Skip to content

Fix ValuesExpression pruning dropping outer columns referenced from VALUES cells - #38779

Open
yvesleguennec wants to merge 2 commits into
dotnet:mainfrom
yvesleguennec:fix/38700-values-pruning-column-refs
Open

Fix ValuesExpression pruning dropping outer columns referenced from VALUES cells#38779
yvesleguennec wants to merge 2 commits into
dotnet:mainfrom
yvesleguennec:fix/38700-values-pruning-column-refs

Conversation

@yvesleguennec

Copy link
Copy Markdown

Fixes#38700

SqlTreePruner.PruneValues (from #36159) copied VALUES row cells without
Visit(), so ColumnExpressions embedded in inline collections were never
registered. Outer join projections were then over-pruned (e.g. only Id
projected while EXISTS still referenced ServiceId).

Fix

  • Always Visit() nested RowValues / ValuesParameter in PruneValues
    (same pattern as OpenJSON pruning)
  • Fix column-name backfill to use ColumnNames[j] instead of repeating the
    first unreferenced column's name

Tests

  • Relational AdHoc query filters regression for the reported scenario
  • SqlServer SQL baseline asserting ServiceId remains in the join projection

Note: approach described on #38700; no maintainer reply after ~1.5 weeks, opening PR for review.


  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:

Summary of the changes
- Detail 1
- Detail 2
Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

@yvesleguennec

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@AndriySvyryd
AndriySvyryd requested a balanced review from CopilotAugust 12, 2026 00:29
@AndriySvyrydAndriySvyryd self-assigned this Aug 12, 2026
@AndriySvyrydAndriySvyryd added this to the 12.0.0 milestone Aug 12, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes VALUES pruning so nested outer-column references are retained.

Changes:

  • Visits VALUES cells during pruning.
  • Corrects pruned column-name backfilling.
  • Adds relational regression coverage and a SQL Server baseline.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
src/EFCore.Relational/Query/SqlTreePruner.csCorrects VALUES traversal and column pruning.
test/EFCore.Relational.Specification.Tests/Query/AdHocQueryFiltersQueryRelationalTestBase.csAdds the regression scenario.
test/EFCore.SqlServer.FunctionalTests/Query/AdHocQueryFiltersQuerySqlServerTest.csVerifies the generated SQL projection.

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

Comment threadsrc/EFCore.Relational/Query/SqlTreePruner.cs
Comment threadtest/EFCore.Relational.Tests/Query/SqlTreePrunerTest.cs Outdated
…ALUES cells
- Visit nested RowValues/ValuesParameter in PruneValues so embedded
ColumnExpressions are registered before outer join projections are pruned
- Fix column-name backfill to use ColumnNames[j] instead of repeating the
first unreferenced column's name
Fixesdotnet#38700
…tnet#38700)
Cover the jk-aau case (inline-array Max + AsSplitQuery + pagination),
forcing VALUES+MAX on SQL Server compat < 160.
@yvesleguennec
yvesleguennecforce-pushed the fix/38700-values-pruning-column-refs branch from 60b1d5b to eeee33bCompareAugust 21, 2026 05:45
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression 9.0 → 10.0] Query filter with inline array of navigation columns generates SQL referencing pruned columns

3 participants

@yvesleguennec@AndriySvyryd