ivan-kiselev opened a new issue, #27776: URL: https://github.com/apache/datafusion/issues/27776
### Describe the bug Since DataFusion 56, a scan can emit columns used only by its pushed-down predicate. A computed projection above round-robin repartitioning drops those columns again, so query results are correct, but the scan and intervening operators carry unnecessary data. This reproduces on upstream main at [053386b43480](https://github.com/apache/datafusion/commit/053386b43480bfbf1a09e9ac3d03b5ca9fafe501). We found it while upgrading a downstream Vortex integration; the SQL below reproduces it using Parquet alone. ### To Reproduce Run in `datafusion-cli` in a directory without an existing `repro.parquet`: ```sql SET datafusion.execution.target_partitions = 4; SET datafusion.execution.parquet.pushdown_filters = true; COPY ( SELECT value AS timestamp, value * 3 AS period, value * 7 AS val, named_struct('name', 'namespace', 'unused', value) AS attrs FROM range(0, 20000) ) TO 'repro.parquet' STORED AS PARQUET; CREATE EXTERNAL TABLE t STORED AS PARQUET LOCATION 'repro.parquet'; EXPLAIN FORMAT INDENT SELECT val * period AS result FROM t WHERE timestamp >= 0 AND lower(attrs['name']) = 'namespace'; ``` The scan projection contains `timestamp` and the extracted name alongside `period` and `val`. Neither predicate input is needed above the scan. The multiplication remains above `RepartitionExec: partitioning=RoundRobinBatch(4)`. ### Expected behavior The scan should emit only `period` and `val`, while still evaluating both predicates internally. Multiplication should remain above repartitioning so it retains parallel execution. ### Additional context An executable bisect between 55.2.0 and 56.0.0, with no skipped revisions, identified [6f3f7b7420c5](https://github.com/apache/datafusion/commit/6f3f7b7420c58bedf795260ddb3677be1b90b1af), #25455, as the introducing commit. Its parent does not emit the predicate-only timestamp. That change resolves a conflict between logical optimizer rules; reverting it is not the proposed fix. `EXPLAIN VERBOSE` shows the mechanism: 1. Logical leaf extraction leaves a projection below the filter that includes predicate inputs. 2. Physical filter pushdown absorbs the filter into the scan, leaving adjacent projections. 3. `EnsureRequirements` inserts round-robin repartitioning between those projections before they merge. 4. The upper computed projection cannot pass through the repartition, so the lower projection reaches the scan with unused columns intact. #27152 addresses leaf expressions stranded above a repartition. This case instead requires pruning inputs to computed expressions after filter pushdown. This is a plan-efficiency regression, not a wrong-results report. Predicate columns still need to be read to evaluate the predicate; narrower scan output does not necessarily reduce storage I/O. Prepared with AI assistance (Amp). ### Willingness to contribute I plan to contribute a fix for this bug independently. -- 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]
