Skip to content

Query: optimize NOT (CASE WHEN x THEN 1 ELSE 0) by pushing NOT into the THEN/ELSE  #33857

@maumar

Description

@maumar

pointed out by @ranma42

WHERE NOT (CASE
    WHEN instr("c"."CompanyName", "c"."ContactName") > 0 THEN 1
    ELSE 0
END)

can be simplified to:

WHERE CASE
    WHEN instr("c"."CompanyName", "c"."ContactName") > 0 THEN 0
    ELSE 1
END

can be safely done for constants for sure, need to think about/test more complex cases, e.g. if THEN itself is an expression, like a comparison.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions