Uh oh!
There was an error while loading. Please reload this page.
fix: FilterExec should drop projection when apply projection pushdown - #21460
Conversation
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
Uh oh!
There was an error while loading. Please reload this page.
alamb
commented
Apr 8, 2026
Thanks @haohuaijin |
Uh oh!
There was an error while loading. Please reload this page.
haohuaijin
commented
Apr 9, 2026
Thanks for your quick reviews @alamb |
alamb
commented
Apr 9, 2026
Gotta love the bug fixes. THanks @haohuaijin Cna you please make a backport for this issue to |
alamb
commented
Apr 9, 2026
I agree -- it is fine that the test is not included |
…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 `Closesapache#123` indicates that this PR will close issue apache#123. --> - Closesapache#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. -->
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?