Dandandan opened a new pull request, #22606: URL: https://github.com/apache/datafusion/pull/22606
## Which issue does this PR close? - Does not close an issue. ## Rationale for this change `TopK` can currently run after a `ProjectionExec` even when the sort key is just a projected input column. If the projection computes values not needed for ordering, such as `SELECT 1 ... ORDER BY c LIMIT 10`, those expressions are materialized for all input rows instead of only the rows retained by `TopK`. ## What changes are included in this PR? - Adds a physical projection pushdown rewrite that moves `TopK` below computed projections when all sort keys map through the projection to plain input columns. - Leaves alias-only projections and computed sort-key projections unchanged to avoid broader plan churn or duplicated sort-key computation. - Updates ClickBench `EXPLAIN` expectations for affected plans. ## Are these changes tested? - `cargo fmt --all` - `cargo test -p datafusion-physical-optimizer projection_pushdown -- --nocapture` - `cargo test --profile=ci --test sqllogictests -- topk.slt` - `cargo test --profile=ci --test sqllogictests -- clickbench.slt` - `cargo clippy --all-targets --all-features -- -D warnings` - `cargo run --profile release-nonlto -p datafusion-benchmarks --bin dfbench -- clickbench -q 34 -i 1 -n 8 --debug` ## Are there any user-facing changes? No API changes. Physical plans for some `TopK` queries with computed projections can change; query results are unchanged. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
