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

…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

Fixes dotnet#38700
@yvesleguennec

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

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

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 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.

File Description
src/EFCore.Relational/Query/SqlTreePruner.cs Corrects VALUES traversal and column pruning.
test/EFCore.Relational.Specification.Tests/Query/AdHocQueryFiltersQueryRelationalTestBase.cs Adds the regression scenario.
test/EFCore.SqlServer.FunctionalTests/Query/AdHocQueryFiltersQuerySqlServerTest.cs Verifies the generated SQL projection.

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

{
referencedColumns[j] = true;
newColumnNames.Add(columnName);
newColumnNames.Add(values.ColumnNames[j]);
Protects the case where leading VALUES columns stay referenced while a
later column is pruned — the path that previously repeated the pruned
column's name in newColumnNames.
Sign up for free to 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