forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to dotnet#6861 - Query with projection and navigation properties …
…adds extra sort columns in ORDER BY for foreign key columns When creating LEFT OUTER JOIN we add ORDER BY clause(s) based on the key of the outer entity. This is because out GroupJoin method is streaming and we need to have results in order to create the correct groups in a performant way. However we can there are some optimizations we can do: 1. we don't need ORDER BY if the join is from dependent to principal because there will always be at most one customer associated with a given order. e.g. orders.Select(o => o.Customer.Name) which translates to: from o in Orders join c in Customers on o.CustomerId equal c.Id into grouping from c in grouping.DefaultIfEmpty() select c.Name In case of composite keys we need to check that entire key is being used as a join condition. Moreover, if there are additional elements in the join condition (on top of the FK->PK) we don't need to add order by either, because the grouping will be even more restrictive. 2. in case when we fully translate LOJ into SQL (which is now very often the case) we also don't need the extra ORDER BYs because we no longer perform streamed grouping on the client.
- Loading branch information
Showing
8 changed files
with
474 additions
and
383 deletions.
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.