-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Optimize SQL based on parameter nullability #18491
Conversation
depends on #18035 |
|
||
protected override Expression VisitExtension(Expression extensionExpression) | ||
{ | ||
if (extensionExpression is SelectExpression selectExpression) |
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.
temporary workaround, correct fix tracked here: #18492
src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
...onalShapedQueryCompilingExpressionVisitor.ParameterNullabilityOptimizingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
...onalShapedQueryCompilingExpressionVisitor.ParameterNullabilityOptimizingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
var newOperand = (SqlExpression)Visit(sqlUnaryExpression.Operand); | ||
if (newOperand is SqlParameterExpression parameterOperand) | ||
{ | ||
var parameterValue = _parametersValues[parameterOperand.Name]; |
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.
Should use TryGetValue?
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.
Is it possible to get this far for a query with a parameter that doesn't have a value?
If yes then use TryGetValue and throw a nice exception and add a test.
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.
will do it in a different PR, we have a few places where we directly access parameterValues elements, without TryGetValue - will update all of them
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.
filed #18502
...onalShapedQueryCompilingExpressionVisitor.ParameterNullabilityOptimizingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
This is part of #17543 - Queries really slow due to null checks Problem was that at the time we performed null semantics and related optimizations we didn't know the value of parameters, so we always had to assume they can be nullable, which resulted in additional IS NULL checks being created. However, later in the pipeline we know the parameter values and we can optimize out those checks for parameters whose values are not null.
This is part of #17543 - Queries really slow due to null checks
Problem was that at the time we performed null semantics and related optimizations we didn't know the value of parameters, so we always had to assume they can be nullable, which resulted in additional IS NULL checks being created.
However, later in the pipeline we know the parameter values and we can optimize out those checks for parameters whose values are not null.