Skip to content

Fix UnnestExec misattributing column properties on duplicated column names#23394

Open
simonvandel wants to merge 4 commits into
apache:mainfrom
simonvandel:push-xlzmxnmwvkmz
Open

Fix UnnestExec misattributing column properties on duplicated column names#23394
simonvandel wants to merge 4 commits into
apache:mainfrom
simonvandel:push-xlzmxnmwvkmz

Conversation

@simonvandel

@simonvandel simonvandel commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

I can create an issue if needed.

Rationale for this change

While working on filter pushdown for UnnestExec, I found a problem in the existing code I wanted to re-use/repurpose.
The problem was that input-output column-relationships were tracked by name. So if multiple columns have the same name, the optimizer could misattribute PlanProperties to the wrong column.

What changes are included in this PR?

  • First commit adds an SLT-reproduction - Unnest over duplicate column names can misattribute order-properties. The SLT shows that a SortExec is missing.
  • Second commit is purely a refactor to make it easier to read the third commit.
  • Third commit is the actual fix - track input-output relationship by index instead of by name. The SLT-reproduction shows the SortExec reappearing.
  • Fourth commit fixes an existing roundtrip_unnest test that was constructing output schema incorrectly by hand

Are these changes tested?

Yes, first commit demonstrates the issue, last commit fixes it.

Are there any user-facing changes?

Yes, order on query is now correct.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Jul 8, 2026
@simonvandel simonvandel changed the title Push xlzmxnmwvkmz Fix UnnestExec misattributing column properties on duplicated column names Jul 8, 2026
@simonvandel simonvandel marked this pull request as draft July 8, 2026 20:54
@github-actions github-actions Bot added the proto Related to proto crate label Jul 9, 2026
…ties

Pure code motion: the logic that computes which non-unnested input
columns map to which output columns is extracted into a helper so it
can be reused. No behavior change.
Unnesting a list column yields an output column with the *same name* as
the input list column, so looking up a passthrough column's output index
by first-match name lookup can bind to the wrong column when a
passthrough column shares its name with an unnested column (possible
e.g. after a join of two tables with a common column name).

Reconstruct the output layout positionally instead, and validate that
the output schema lines up with the input schema.
The added validation in passthrough_columns caught the manually constructed output_schema being wrong
@simonvandel simonvandel marked this pull request as ready for review July 9, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate proto Related to proto crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant