-
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
Relational: Translate SelectMany #17077
Merged
Merged
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
@maumar Please make it a priority to review this when you get in. (You were nominated in triage! 🚎) |
maumar
reviewed
Aug 12, 2019
maumar
reviewed
Aug 12, 2019
test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs
Show resolved
Hide resolved
maumar
reviewed
Aug 12, 2019
src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
maumar
approved these changes
Aug 12, 2019
SelectMany in linq look something like following (second clause is considered the collection selector) ```C# from c in cs from o in c.Orders select.... ``` Following are the translations of SelectMany Unrelated collection selector ```C# from c in cs from o in os ``` Generates CROSS JOIN Correlated collection selector with correlation being a predicate ```C# from c in cs from o in os.Where(o => o.CustomerID == c.CustomerID) ``` Such predicate can be lifted and used in generating a join. So this query generates JOIN. If collection selector ends with DefaultIfEmpty then it is LEFT JOIN. Correlated collection selector with correlation not a predicate ```C# from c in cs from o in os.Select(o => c.City) ``` Since we cannot generate a join predicate here, this translates to CROSS APPLY. If collection selector ends with DefaultIfEmpty then it is OUTER APPLY. - Add support for Cross Apply - Add Support for Outer Apply - Convert Cross Apply to Inner Join when possible - Convert Outer Apply to Left Join when possible - Add translation for DefaultIfEmpty - Add translation for both overloads of SelectMany - Handle DefaultIfEmpty & SelectMany without collectionSelector in Navigation Expansion - Ensure columns are in projection when generating join predicate from a correlated subquery Currently there are no tests for Cross/Outer Apply. Our earlier Cross Apply got converted to join. N+1 evaluation tests are disabled right now, which would generate Cross Apply. We never supported Outer Apply in past. Resolves #15711 Resolves #12567 Resolves #12572 Resolves #12872 Resolves #16330 Resolves #15081 Resolves #16989 Re-enable tests for #12449
Renamed CrossApplyExpression -> InnerJoinLateralExpression & OuterApplyExpression -> LeftJoinLateralExpression to match with formal SQL terminology. Also updated relational implementation and moved SqlServer specific sql syntax in provider code. |
To match with SQL standard
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.
SelectMany in linq look something like following (second clause is considered the collection selector)
Following are the translations of SelectMany
Unrelated collection selector
Generates CROSS JOIN
Correlated collection selector with correlation being a predicate
Such predicate can be lifted and used in generating a join. So this query generates JOIN.
If collection selector ends with DefaultIfEmpty then it is LEFT JOIN.
Correlated collection selector with correlation not a predicate
Since we cannot generate a join predicate here, this translates to CROSS APPLY.
If collection selector ends with DefaultIfEmpty then it is OUTER APPLY.
Currently there are no tests for Cross/Outer Apply.
Our earlier Cross Apply got converted to join. N+1 evaluation tests are disabled right now, which would generate Cross Apply.
We never supported Outer Apply in past.
Resolves #15711
Resolves #12567
Resolves #12572
Resolves #12872
Resolves #16330
Resolves #15081
Resolves #16989
Re-enable tests for #12449