Skip to content

Preserve discriminating ORDER BY for many-to-many collections - #38811

Draft
AndriySvyryd with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-many-to-many-order-by-regression
Draft

Preserve discriminating ORDER BY for many-to-many collections#38811
AndriySvyryd with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-many-to-many-order-by-regression

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Many-to-many collection includes could omit their only varying identifier from ORDER BY, making materialization order depend on the provider’s physical access path.

  • Ordering logic

    • Retain the pending identifier when surviving identifiers only repeat the collection join key.
    • Preserve the existing omission when another identifier already discriminates collection elements.
  • Regression coverage

    • Seed SQLite join rows out of key order to expose physical-order dependencies.
    • Update SQL Server baselines to include the restored discriminator.
-- Before
ORDER BY [e].[Id], [s].[OneId]

-- After
ORDER BY [e].[Id], [s].[OneId], [s].[TwoId]

Copilot AI and others added 2 commits August 14, 2026 20:52
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix many-to-many collection ORDER BY regression in EFCore 11.0 Preserve discriminating ORDER BY for many-to-many collections Aug 14, 2026
Copilot AI requested a review from AndriySvyryd August 14, 2026 21:00
@AndriySvyryd
AndriySvyryd requested a balanced review from Copilot August 15, 2026 01:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes nondeterministic many-to-many collection materialization by retaining the final discriminating identifier in generated ORDER BY clauses.

Changes:

  • Detects when surviving orderings contain only collection join keys.
  • Seeds SQLite join rows out of key order for regression coverage.
  • Updates SQL Server baselines across standard, temporal, TPT, and TPC queries.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs Preserves the required collection discriminator ordering.
test/EFCore.Sqlite.FunctionalTests/ManyToManyLoadSqliteTestBase.cs Introduces non-key-ordered join rows.
test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyQuerySqlServerTest.cs Updates SQL ordering baselines.
test/EFCore.SqlServer.FunctionalTests/Query/TemporalManyToManyQuerySqlServerTest.cs Updates temporal SQL baselines.
test/EFCore.SqlServer.FunctionalTests/Query/Inheritance/TPTManyToManyQuerySqlServerTest.cs Updates TPT SQL baselines.
test/EFCore.SqlServer.FunctionalTests/Query/Inheritance/TPCManyToManyQuerySqlServerTest.cs Updates TPC SQL baselines.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Many-to-many collection ORDER BY loses its only discriminating column (regression in 11.0)

3 participants