fix: FilterExec should drop projection when apply projection pushdown#21460
Merged
alamb merged 5 commits intoapache:mainfrom Apr 8, 2026
Merged
fix: FilterExec should drop projection when apply projection pushdown#21460alamb merged 5 commits intoapache:mainfrom
alamb merged 5 commits intoapache:mainfrom
Conversation
alamb
approved these changes
Apr 8, 2026
Contributor
alamb
left a comment
There was a problem hiding this comment.
Thanks @haohuaijin
the fix makes sense to me, but I think it would be better to try and add some higher level tests if possible
Contributor
|
Thanks @haohuaijin |
Contributor
Author
|
Thanks for your quick reviews @alamb |
Contributor
|
Gotta love the bug fixes. THanks @haohuaijin Cna you please make a backport for this issue to |
Contributor
Author
Contributor
I agree -- it is fine that the test is not included |
Rich-T-kid
pushed a commit
to Rich-T-kid/datafusion
that referenced
this pull request
Apr 21, 2026
…apache#21460) ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#21459 ## Rationale for this change When a `ProjectionExec` sits on top of a `FilterExec` that already carries an explicit projection, the `ProjectionPushdown` optimizer attempts to swap them via `try_swapping_with_projection`. The swap replaces the `FilterExec's` input with the narrower `ProjectionExec`, but `FilterExecBuilder::from(self)` carried over the old projection indices (e.g. [0, 1, 2]). After the swap the new input only has the columns selected by the `ProjectionExec` (e.g. 2 columns), so .build() tries to validate the stale projection against the narrower schema and panics with "project index 2 out of bounds, max field 2". ## What changes are included in this PR? In `FilterExec::try_swapping_with_projection`, after replacing the input with the narrower ProjectionExec, clear the FilterExec's own projection via .`apply_projection(None)`. The ProjectionExec that is now the input already handles column selection, so the FilterExec no longer needs its own projection. ## Are these changes tested? yes, add test case ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
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?
Rationale for this change
When a
ProjectionExecsits on top of aFilterExecthat already carries an explicit projection, theProjectionPushdownoptimizer attempts to swap them viatry_swapping_with_projection. The swap replaces theFilterExec'sinput with the narrowerProjectionExec, butFilterExecBuilder::from(self)carried over the old projection indices (e.g. [0, 1, 2]). After the swap the new input only has the columns selected by theProjectionExec(e.g. 2 columns), so .build() tries to validate the stale projection against the narrower schema and panics with "project index 2 out of bounds, max field 2".What changes are included in this PR?
In
FilterExec::try_swapping_with_projection, after replacing the input with the narrower ProjectionExec, clear the FilterExec's own projection via .apply_projection(None). The ProjectionExec that is now the input already handles column selection, so the FilterExec no longer needs its own projection.Are these changes tested?
yes, add test case
Are there any user-facing changes?