Skip to content

Better management of negated expressions #31027

@roji

Description

@roji

For EXISTS, IN and SQLite glob and regexp, we support a nicer negated SQL: instead of NOT (x IN y), we generate x NOT IN y.

However, this is implemented by having an IsNegated flag on the expression node itself; this forces us to check and deal with the possible negation in various visitors across the query pipeline (e.g. null semantics), to optimize NOT(EXISTS) to the negated EXISTS form, etc. This introduces needless complexity - we can simply have these nodes wrapped in a NOT SqlUnaryExpression nodes as with all other expressions, recognize them in QuerySqlGenerator instead and generate the nicer SQL.

As a bonus, this PR generates nicer negated SQL for LIKE as well (i.e. x NOT LIKE y instead of NOT (x LIKE y).

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions