You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "adriangb (via GitHub)" <gi...@apache.org> on 2026/10/06 14:04:32 UTC

[PR] fix: `PushDownLeafProjections` yields when the extraction cannot move [datafusion]

adriangb opened a new pull request, #26085:
URL: https://github.com/apache/datafusion/pull/26085

   ## Which issue does this PR close?
   
   - Part of https://github.com/apache/datafusion/issues/25459. This is a follow-up to https://github.com/apache/datafusion/pull/25455 (https://github.com/apache/datafusion/issues/14540).
   
   ## Rationale for this change
   
   `PushDownLeafProjections` and `OptimizeProjections` undo each other in every optimizer pass for a common plan shape: a projection of a struct field (or another `MoveTowardsLeafNodes` expression) directly over a node that the extraction cannot go through, such as a `TableScan` or an `Aggregate`.
   
   ```text
   Projection: leaf_udf(test.a)
     TableScan: test
   ```
   
   In each pass, `push_down_leaf_projections` splits this into a recovery projection over an in-place extraction projection:
   
   ```text
   Projection: __datafusion_extracted_1 AS leaf_udf(test.a)
     Projection: leaf_udf(test.a) AS __datafusion_extracted_1, test.a
       TableScan: test
   ```
   
   Then `optimize_projections` merges the two back into the original plan. The loop stops only because the plan at the end of a pass is the same as at the end of the previous pass. The final plan is correct, but each pass does the work of both rules again.
   
   The test that https://github.com/apache/datafusion/pull/25455 added found this shape. That test records which rules change the plan in each pass. On `main` it prints, for the plan above:
   
   ```text
   pass 0: push_down_leaf_projections, optimize_projections
   pass 1: push_down_leaf_projections, optimize_projections
   ```
   
   With this PR:
   
   ```text
   pass 0: optimize_projections
   ```
   
   ### Which rule yields
   
   `PushDownLeafProjections` yields. The split has no use when the extraction projection cannot move: a plain `Projection(get_field(...))` directly over a Parquet scan already reaches `DataSourceExec projection=[..., get_field(s@1, value) ...]`. The existing `EXPLAIN` checks in `projection_pushdown.slt` show this and do not change. If `OptimizeProjections` yielded instead, the plan would keep a projection node that does no work.
   
   ## What changes are included in this PR?
   
   In `split_and_push_projection` (`extract_leaf_expressions.rs`), the rule still builds the in-place extraction projection, because a mixed projection over a `Filter` must become a pure extraction projection before it can go through the filter. The rule now immediately tries to push that extraction projection into its input. If it cannot move, the rule returns the original projection unchanged. The unused `has_new_extractions` flag is removed.
   
   ## What is the testing strategy for this PR?
   
   - `filter_and_extraction_projection_reach_fixed_point` in `push_down_filter.rs` now checks that no rule at all changes the plan in the last optimizer pass (before, it checked only `PushDownFilter` and `PushDownLeafProjections`). It also covers a projection over a scan with no filter. Without the fix it fails with `[["push_down_leaf_projections","optimize_projections"],["push_down_leaf_projections","optimize_projections"]]`.
   - Six stage snapshots in `extract_leaf_expressions.rs` change. In each one, only the "After Pushdown" stage changes, to "(same as after extraction)". The "Optimized" plan is the same in all six.
   - One line in `unnest.slt` changes (logical plan line 03). A nested alias is now kept: `get_field(__unnest_placeholder(...,depth=1) AS UNNEST(recursive_unnest_table.column3), Utf8("c1"))`. The split and merge used to remove that alias as a side effect. The physical plan is the same. This is the same display-only nested alias that https://github.com/apache/datafusion/pull/25455 showed for `length(...)`.
   
   Commands run:
   
   - `cargo test --profile ci -p datafusion-optimizer --lib`: 932 passed.
   - `cargo test --profile ci -p datafusion-sqllogictest --test sqllogictests`: 526 of 526 files pass.
   - `cargo fmt --all` and `cargo clippy --profile ci -p datafusion-optimizer --all-targets -- -D warnings`: clean.
   
   ## Are there any user-facing changes?
   
   No. Final plans and results do not change, except for the alias display in the `unnest` plan above. Planning does less work for queries that read struct fields.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: `PushDownLeafProjections` yields when the extraction cannot move [datafusion]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #26085:
URL: https://github.com/apache/datafusion/pull/26085#issuecomment-6018410188

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/26085?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `77.27273%` with `5 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 82.72%. Comparing base ([`6f3f7b7`](https://app.codecov.io/gh/apache/datafusion/commit/6f3f7b7420c58bedf795260ddb3677be1b90b1af?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`4461e73`](https://app.codecov.io/gh/apache/datafusion/commit/4461e7350bb2f9d164389ddc6307196a9e0c6417?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/26085?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [datafusion/optimizer/src/push\_down\_filter.rs](https://app.codecov.io/gh/apache/datafusion/pull/26085?src=pr&el=tree&filepath=datafusion%2Foptimizer%2Fsrc%2Fpush_down_filter.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL3B1c2hfZG93bl9maWx0ZXIucnM=) | 40.00% | [0 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/26085?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...tafusion/optimizer/src/extract\_leaf\_expressions.rs](https://app.codecov.io/gh/apache/datafusion/pull/26085?src=pr&el=tree&filepath=datafusion%2Foptimizer%2Fsrc%2Fextract_leaf_expressions.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL2V4dHJhY3RfbGVhZl9leHByZXNzaW9ucy5ycw==) | 88.23% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/26085?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##             main   #26085      +/-   ##
   ==========================================
   - Coverage   82.72%   82.72%   -0.01%     
   ==========================================
     Files        1147     1147              
     Lines      448179   448163      -16     
     Branches   448179   448163      -16     
   ==========================================
   - Hits       370751   370727      -24     
   + Misses      54898    54897       -1     
   - Partials    22530    22539       +9     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/26085?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: `PushDownLeafProjections` yields when the extraction cannot move [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on PR #26085:
URL: https://github.com/apache/datafusion/pull/26085#issuecomment-6353988884

   Thanks @kosiew ! Addressed your feedback in d33044860f3675c4b1c4eb1cc6f70b209e171ef8. I can confirm that the new tests fail without the code change.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: `PushDownLeafProjections` yields when the extraction cannot move [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb merged PR #26085:
URL: https://github.com/apache/datafusion/pull/26085


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: `PushDownLeafProjections` yields when the extraction cannot move [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #26085:
URL: https://github.com/apache/datafusion/pull/26085#discussion_r4346990021


##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########


Review Comment:
   Could we update this test comment? It still describes an in-place extraction and recovery projection, but the updated snapshot shows that the aggregate blocks movement and the original projection remains unchanged.



##########
datafusion/optimizer/src/push_down_filter.rs:
##########
@@ -4794,13 +4796,17 @@ mod tests {
             .project(vec![leaf_udf_expr(col("a")), col("b")])?
             .build()?;
 
-        for plan in [simple, two_filters] {
+        // No filter: the extraction projection cannot move below the scan.
+        let no_filter = LogicalPlanBuilder::from(test_table_scan()?)
+            .project(vec![leaf_udf_expr(col("a"))])?
+            .build()?;
+

Review Comment:
   Optional: Could we also include a leaf-expression projection over an Aggregate in this fixed-point loop, using the grouped-struct shape from `test_projection_with_leaf_expr_above_aggregate`? The existing snapshot covers the aggregate barrier, but asserting an empty final pass here would additionally verify convergence under the complete default optimizer sequence.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org