jackkleeman opened a new issue, #20190:
URL: https://github.com/apache/datafusion/issues/20190
### Describe the bug
When an empty `ProjectionExec` (`expr=[]`) sits on top of a `HashJoinExec` —
for example from `SELECT count(1) FROM t1 RIGHT JOIN t2 ON ...` — the
projection pushdown optimizer fails to embed it. `try_embed_projection` calls
`collect_column_indices` on the empty expression list, gets an empty result,
and returns `Ok(None)`, leaving the projection un-embedded.
This means the join still materializes all build-side and probe-side columns
(including null arrays for the build side when it's empty), even though none of
them are needed downstream.
### To Reproduce
Good (HashJoinExec has projection=[a], ProjectionExec removed):
```
datafusion-cli -c "CREATE TABLE t1 (a INT) AS VALUES (1), (2), (3); CREATE
TABLE t2 (a INT) AS VALUES (2), (3), (4); EXPLAIN ANALYZE SELECT count(t1.a)
FROM t1 RIGHT JOIN t2 ON t1.a = t2.a;"
...
| | RepartitionExec:
partitioning=RoundRobinBatch(12), input_partitions=1,
metrics=[fetch_time=700.583µs, repartition_time=1ns, send_time=20.97µs]
|
| | CoalesceBatchesExec: target_batch_size=8192,
metrics=[output_rows=3, elapsed_compute=18.958µs]
|
| | HashJoinExec: mode=CollectLeft,
join_type=Right, on=[(a@0, a@0)], projection=[a@0], metrics=[output_rows=3,
elapsed_compute=643.17µs, build_input_batches=1, build_input_rows=3,
input_batches=1, input_rows=3, output_batches=1, build_mem_used=140,
build_time=144.042µs, join_time=499.126µs] |
| | DataSourceExec: partitions=1,
partition_sizes=[1], metrics=[]
|
| | DataSourceExec: partitions=1,
partition_sizes=[1], metrics=[]
```
Bad (HashJoinExec has no projection, produces nulls for any unmatched rows):
```
datafusion-cli -c "CREATE TABLE t1 (a INT) AS VALUES (1), (2), (3); CREATE
TABLE t2 (a INT) AS VALUES (2), (3), (4); EXPLAIN ANALYZE SELECT count(1) FROM
t1 RIGHT JOIN t2 ON t1.a = t2.a;"
...
| | RepartitionExec:
partitioning=RoundRobinBatch(12), input_partitions=1,
metrics=[fetch_time=93.042µs, repartition_time=1ns, send_time=2.219µs]
|
| | ProjectionExec: expr=[],
metrics=[output_rows=3, elapsed_compute=209ns]
|
| | CoalesceBatchesExec: target_batch_size=8192,
metrics=[output_rows=3, elapsed_compute=2.375µs]
|
| | HashJoinExec: mode=CollectLeft,
join_type=Right, on=[(a@0, a@0)], metrics=[output_rows=3,
elapsed_compute=80.46µs, build_input_batches=1, build_input_rows=3,
input_batches=1, input_rows=3, output_batches=1, build_mem_used=140,
build_time=24.334µs, join_time=56.124µs] |
| | DataSourceExec: partitions=1,
partition_sizes=[1], metrics=[]
|
| | DataSourceExec: partitions=1,
partition_sizes=[1], metrics=[]
```
### Expected behavior
_No response_
### Additional context
_No response_
--
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]