Skip to content
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

Make sort order consistent in split queries #34097

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

ascott18
Copy link
Contributor

@ascott18 ascott18 commented Jun 26, 2024

Make sort order consistent in split queries between the parent query and its occurrences in subqueries for collection includes.

  • Deterministic sorting was already being added to the parent query (sorting by the identifiers used to join the subquery to the subsequent collection queries). However, due to what appears to be a simple oversight, these were not getting applied to the subquery in the split collection query. As a result, the parent query and the subquery were actively being given different sort orderings.
  • Tests that previously expected a thrown exception (Include_collection_skip_take_no_order_by, Include_collection_skip_no_order_by) due to this missing sort order in skip/take queries have been made non-throwing since the same ordering from the parent query is now applied to the subquery that lacked sorting.

All the changes in the tests that add or change an ORDER BY are such that the change makes the subquery exactly match the parent query.

Since the same deterministic sorting was already being appended to the parent query, I didn't go down the paths discussed in #26808 of checking whether existing sorts on the query are already perfectly deterministic.

Fixes #26808

(Apologies for not asking for permission to work on this first - this started out as an exploration of whether I could even figure out how to approach fixing an issue like this).

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @ascott18, and sorry it took so long to get reviewed.

This looks correct to me, and a good fix; I'm not sure why the identifier orderings were added late (after the pushdown) - hopefully that was just an oversight and not for a good reason (this area of the code was written by a team member who has left since, and it's one place where we don't have perfect expertise at the moment).

@ascott18 can you please rebase on latest main and see the comment about removing the dead warning? Otherwise I'm good with merging this for 9.0 - @maumar @cincuranet would you mind giving this a look in case I've missed something?

@@ -24,14 +24,64 @@ public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());

public override async Task Include_collection_skip_take_no_order_by(bool async)
=> Assert.Equal(
SqlServerStrings.SplitQueryOffsetWithoutOrderBy,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistaken, this warning can no longer be generated, since we ensure that the identifier is always injected as the ordering, both into the main query and into the split one (outer and subquery). So I think the warning and the visitor that generates it can now be removed.

If that's true, @ascott18 can you do that in this PR? If you prefer not to, let me know and I'll do it.

Copy link
Contributor Author

@ascott18 ascott18 Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

I did also noticed that in the docs, this warning won't be applicable anymore. Not sure how warnings like that are usually handled when they only apply to some versions.

@roji roji self-assigned this Jul 27, 2024
@ascott18 ascott18 force-pushed the ascott/split-query-consistent-order-9 branch from c3d754d to 34a956b Compare July 30, 2024 02:29
@ascott18
Copy link
Contributor Author

@roji Friendly ping - is this still on track for EF 9?

@roji
Copy link
Member

roji commented Sep 25, 2024

@ascott18 unfortunately not - EF 9 is already locked down and nothing but critical bug fixes is being merged in... My apologies that this took so long to process, the recent couple of months have simply been very busy. I'll make sure this gets merged in for 10.

@roji roji force-pushed the ascott/split-query-consistent-order-9 branch from 890a30c to 0c318ac Compare October 10, 2024 08:21
@roji roji enabled auto-merge (squash) October 10, 2024 08:26
@roji roji merged commit a0d6550 into dotnet:main Oct 10, 2024
7 checks passed
@roji
Copy link
Member

roji commented Oct 10, 2024

@ascott18 finally merged this for 10 - thanks again for contributing this! I've also submitted dotnet/EntityFramework.Docs#4831 to amend the doc comment you referred to, thanks for that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants