-
Couldn't load subscription status.
- Fork 3.3k
Implement CASE flattening optimizations
#34175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I'll mark it as ready after adding some tests for the new transformations (they already affect some existing tests, but having some dedicated ones is probably better). |
62b6472 to
d838062
Compare
It filters out all elements after a certain predicate it satisfied.
This makes the expression a little simpler and (especially) normalizes the ELSE sub-expression.
| { | ||
| var test = caseWhenClause.Test; | ||
|
|
||
| if (operand == null && test is CaseExpression { Operand: null, WhenClauses: [var clause] } testExpr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (operand == null && test is CaseExpression { Operand: null, WhenClauses: [var clause] } testExpr) | |
| if (operand == null && test is CaseExpression { Operand: null, WhenClauses: [var nestedSingleClause] } testExpr) |
| => expr is SqlConstantExpression { Value: false or null }; | ||
|
|
||
| bool IsTrue(SqlExpression expr) | ||
| => expr is SqlConstantExpression { Value: true }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, with pattern matching, the syntax is simple enough that maybe we should just inline, rather than have a helper method like this…
|
nice improvement, thanks! |
It is possible to perform most of the
CASEoptimizations at construction time.This improves the SQL emitted by SqlServer and makes it easy to implement the optimizations proposed in #18774.
Fixes #18774.
Fixes #18935.