-
Notifications
You must be signed in to change notification settings - Fork 545
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
Don't simplify filter with custom functions over projection #800
Merged
ajcvickers
merged 11 commits into
dotnet:master
from
kosinsky:fixes/AvoidSimplificationForUDFs
Jun 26, 2019
Merged
Don't simplify filter with custom functions over projection #800
ajcvickers
merged 11 commits into
dotnet:master
from
kosinsky:fixes/AvoidSimplificationForUDFs
Jun 26, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…suboptimal SQL plans and allow window functions (these function not allowed in WHERE clause)
divega
reviewed
May 20, 2019
src/EntityFramework/Core/Query/PlanCompiler/TransformationRulesContext.cs
Outdated
Show resolved
Hide resolved
src/EntityFramework/Core/Query/PlanCompiler/TransformationRulesContext.cs
Show resolved
Hide resolved
…DbContexConfiguration
ajcvickers
reviewed
Jun 25, 2019
Thanks @kosinsky. Sorry for the long delay. |
+1 thanks for this @kosinsky! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Don't simplify filter with custom functions over projection to avoid suboptimal SQL plans and allow window functions (these function not allowed in WHERE clause)
The change helps following cases:
For IQueryable that looks like:
EF6 simplifies expression and keeps only one SELECT with call to the function in SELECT and WHERE parts:
Not simplified version should look like:
For table with 100K records.
Simplified query execution takes: 1100 ms of SQL CPU time
Not simplified: 600 ms of SQL CPU time
If I replace dbo.UDF_Test by LEN (build in function), execution plans are the same and no performance difference are observed.
Custom UDF are block box and database have to call function twice for each row and couldn't optimize it.
When instead of Custom UDF, window functions are used (ROW_NUMBER, LEAD, LAG, PERCENTILE_CONT etc.), SQL SERVER (and I assume every DB that supports window functions) will return error that window function supported only in SELECT or ORDER BY clauses