Repository navigation
Conversation
moraistejerina
force-pushed
the
fix-propagate-empty-relation-union-projection
branch
3 times, most recently
from
October 21, 2026 09:54
d681fc5 to
9a53541
Compare
moraistejerina
marked this pull request as ready for review
October 21, 2026 09:58
moraistejerina
force-pushed
the
fix-propagate-empty-relation-union-projection
branch
from
October 21, 2026 10:06
9a53541 to
d11f89a
Compare
Contributor
Author
When propagate_empty_relation removes all but one input of a Union, it put a Projection over the remaining input with Projection::new_from_schema. That made column references from the union's field names, which come from the first input. If a later input remained and had other names, the projection referred to columns that did not exist, and optimize_projections failed with "No field named ...". Map the remaining input's columns to the union's fields by position and build the projection with Projection::try_new. Closes apache#26516. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moraistejerina
force-pushed
the
fix-propagate-empty-relation-union-projection
branch
from
October 21, 2026 10:59
d11f89a to
5b65023
Compare
gabotechs
approved these changes
Oct 22, 2026
gabotechs
left a comment
Contributor
There was a problem hiding this comment.
👍 no comments, all good here!
I've verified that this is an actual problem present today that other SQL engines do not have:
Contributor
|
Thanks @moraistejerina! |
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Oct 22, 2026
alamb
enabled auto-merge
October 22, 2026 14:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
optimize_projectionsfails with "No field named ..." afterpropagate_empty_relationremoves the first branch of a UNION #26516.Rationale for this change
A
UNION ALLfails to plan withSchema error: No field named ...when the optimizer removes its first input and a later input remains. For example:propagate_empty_relationputs a projection over the remaining input withProjection::new_from_schema. That function makes column references from the union's field names, which come from the first input. When the remaining input has other names, the projection refers to columns that do not exist, andoptimize_projectionsfails.What changes are included in this PR?
Projection::try_new(which also checks the result).Projection: a, b, ctoProjection: test.a AS a, test.b AS b, test.c AS c. In those tests the remaining input is the first input, so the old by-name references worked. The output schema is the same.EXPLAINoutput of thestruct.slttest added in fix: resolve pass-through columns against the input when merging an extraction projection #25412. That PR madepush_down_leaf_projectionshandle the bare-name projection thatpropagate_empty_relationleft after it removed an empty union input. With this change, the projection aliases the qualified input columns (leaf_merge_source.s AS s). The test still plans and returns the same rows. fix: resolve pass-through columns against the input when merging an extraction projection #25412 also handles this same-name alias form, and its unit tests still build the bare-name shape directly.What is the testing strategy for this PR?
propagate_union_remaining_input_with_other_names: the first input is empty and the second input has other column names. Without the fix, the rule producesProjection: a, b, cover an input that only hasx, y, z.union.sltcases with the two queries from the issue.Are there any user-facing changes?
No. The queries that failed now return results. There are no public API changes.