ivan-kiselev opened a new pull request, #27777:
URL: https://github.com/apache/datafusion/pull/27777

   ## Which issue does this PR close?
   
   Closes #27776.
   
   ## Rationale for this change
   
   Scans can emit predicate-only columns that a computed projection above 
round-robin repartitioning immediately discards. This adds unnecessary scan 
output and downstream batch width without changing query results.
   
   The regression was introduced by 
[6f3f7b7420c5](https://github.com/apache/datafusion/commit/6f3f7b7420c58bedf795260ddb3677be1b90b1af),
 #25455, and still reproduces on main at 
[053386b43480](https://github.com/apache/datafusion/commit/053386b43480bfbf1a09e9ac3d03b5ca9fafe501).
 After filter pushdown removes the filter, `EnsureRequirements` separates the 
remaining projections with a repartition. The upper computed projection cannot 
pass through it, leaving unused inputs in the scan output. The issue contains a 
standalone Parquet reproducer and the bisect details.
   
   ## What changes are included in this PR?
   
   For computed projections over round-robin repartitioning, insert a 
column-only projection of the referenced inputs below the repartition and remap 
the upper projection's column indices. Keep computations above the repartition 
to preserve their parallel execution. Existing projection pushdown can absorb 
the lower projection into the scan.
   
   The rewrite requires strictly fewer input columns. Hash and range 
repartitioning are unchanged. Schema metadata is preserved and child 
replacement recomputes repartition properties. The logical precedence change in 
#25455 remains intact.
   
   ## What is the testing strategy for this PR?
   
   The seeded property test follows the existing `leaf_pushdown_fuzz` 
convention. It varies arithmetic, casts, repeated references, struct-field 
reads, predicate thresholds and partition counts over nullable data. Each case 
checks scan-column pruning and compares results with an in-memory reference 
with leaf pushdown disabled. It fails at seed 0 on unmodified main and passes 
all 64 cases with this patch. The existing leaf-pushdown tests also pass, 
including the extended 5,000 memory cases and 1,000 Parquet cases.
   
   `cargo fmt --all --check` and `cargo clippy --all-targets --all-features -- 
-D warnings` pass. The extended workspace command passes 13,650 Rust tests, 
with eight upstream-ignored tests, and all 310 selected SQLLogicTest files. A 
separate focused run passes nine matched files covering projection pushdown, 
file-row-index, Parquet filter pushdown, skip pushdown and REE `LIKE`.
   
   A backport of this patch to 56.0.0 was also checked in our downstream Vortex 
integration: 61 scans became narrower, with unchanged predicates, scan counts 
and query results.
   
   ## Are there any user-facing changes?
   
   Plans can have narrower scan output and repartition input. No API, 
result-schema or intended result changes.
   
   When a scan absorbs the pruning projection, no additional runtime operator 
remains. Other inputs, including windows, can retain an extra column-only 
projection. That costs batch construction and array-reference handling; 
planning also collects columns and remaps expressions. Small batches or cheap 
narrow inputs may not recover that cost. Predicate columns still need to be 
read for filtering, so this does not imply lower storage I/O.
   
   Benchmarked against its upstream main parent using six synthetic SQL window 
workloads, release builds, four cores and ten alternating paired blocks per 
workload. Plan and result checks passed in all 120 runs. These measure the net 
effect of the added projection and narrower downstream batches, not scan 
savings.
   
   - The 1K-row workload was slower: paired execution change +7.45%, bootstrap 
95% interval [+4.28%, +9.73%]. Median runtime was 360.55 to 371.79 microseconds.
   - The 1M-row narrow workload improved by 4.32%, interval [-8.18%, -0.42%]. 
Small input batches were inconclusive at +7.51%, interval [-0.32%, +15.64%]. 
The wide-column, string-payload and unchanged-plan control cases also had 
intervals spanning zero.
   - Several workloads had planning increases of about 12% to 15%, with median 
differences around 47 to 224 microseconds.
   
   The window emits one large batch, so these measurements do not establish 
overhead across many small output batches.
   
   Prepared with AI assistance (Amp); the commit records `Generated-by: Amp`.
   


-- 
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]

Reply via email to