You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CASE WHEN t1 THEN x WHEN t2 THEN x ... WHEN tn THEN x ELSE x END β x
This should be safe even for impure x π
CASE WHEN boolExpr THEN TRUE ELSE FALSE END β boolExpr
CASE WHEN NOT (boolExpr) THEN x ELSE y END β CASE WHEN boolExpr THEN y ELSE x END
NOT (CASE WHEN nullOrBoolExpr THEN x ELSE y END) β CASE WHEN nullOrBoolExpr THEN NOT(x) ELSE NOT(y) END β οΈ it can improve or worsen the complexity of the query
NOT (CASE WHEN nullOrBoolExpr THEN TRUE ELSE FALSE END) β CASE WHEN nullOrBoolExpr THEN FALSE ELSE TRUE END
This is the query in the top comment and is relevant because it is emitted within EFCore; this specialization of the previous case always improves the query.
NOT (COALESCE(nullOrBoolExpr, FALSE)) -> COALESCE(NOT(nullOrBoolExpr), TRUE)
is the COALESCE version of the previous rule. It does not improve the complexity of the query, but additional simplifications might be possible on NOT(nullOrBoolExpr)
See #18774 for optimizations related to nested CASE expressions.
The fourth optimization could be generalized to apply to most operations; as before, it is probably effective on constants: CASE WHEN nullOrBoolExpr THEN 5 ELSE 9 END = 9
β CASE WHEN nullOrBoolExpr THEN 5 = 9 ELSE 9 = 9 END
β CASE WHEN nullOrBoolExpr THEN FALSE ELSE TRUE END
CASE WHEN t1 THEN x WHEN t2 THEN x ... WHEN tn THEN x ELSE x END
βx
This should be safe even for impure
x
πCASE WHEN boolExpr THEN TRUE ELSE FALSE END
βboolExpr
CASE WHEN NOT (boolExpr) THEN x ELSE y END
βCASE WHEN boolExpr THEN y ELSE x END
NOT (CASE WHEN nullOrBoolExpr THEN x ELSE y END)
βCASE WHEN nullOrBoolExpr THEN NOT(x) ELSE NOT(y) END
NOT (CASE WHEN nullOrBoolExpr THEN TRUE ELSE FALSE END)
βCASE WHEN nullOrBoolExpr THEN FALSE ELSE TRUE END
This is the query in the top comment and is relevant because it is emitted within EFCore; this specialization of the previous case always improves the query.
NOT (COALESCE(nullOrBoolExpr, FALSE))
->COALESCE(NOT(nullOrBoolExpr), TRUE)
is the
COALESCE
version of the previous rule. It does not improve the complexity of the query, but additional simplifications might be possible onNOT(nullOrBoolExpr)
Originally posted by @ranma42 in #33857 (comment)
The text was updated successfully, but these errors were encountered: