mbutrovich opened a new issue, #27726: URL: https://github.com/apache/datafusion/issues/27726
### Describe the bug A hash join's build-side hash map is empty when the build side has no rows, or when nulls equal nothing (`NullEqualsNothing`) and every build row has a NULL key. In that case, for each probe batch, `HashJoinStream` takes its [empty build side path](https://github.com/apache/datafusion/blob/9d894e1ae001391cfde2f6d3078ac1989396ff90/datafusion/physical-plan/src/joins/hash_join/stream.rs#L890-L904). That path ignores the status `push_batch` returns and goes back to `FetchProbeBatch`. `LimitedBatchCoalescer` sets `finished` only in `finish()`, so the stream keeps reading the probe side after it has `fetch` rows. When the map has entries, the stream calls `finish()` on `LimitReached` and stops. The output is right, since the coalescer drops rows past the limit. The join reads and joins the rest of the probe input for nothing. The join types that return rows on that path are `RightAnti` and `RightMark`. With the default `enable_migration_hash_join = true`, inner, left, right, and full joins take the batched path instead ([`RegularJoinKind::from_join_type`](https://github.com/apache/datafusion/blob/9d894e1ae001391cfde2f6d3078ac1989396ff90/datafusion/physical-plan/src/joins/hash_join/batched_join_processor.rs#L497-L505)). ### To Reproduce In `datafusion-cli`: ```sql SET datafusion.execution.target_partitions = 1; CREATE TABLE probe AS SELECT value AS k FROM generate_series(1, 100000); CREATE TABLE null_keys AS SELECT CAST(NULL AS BIGINT) AS k; CREATE TABLE other_keys AS SELECT CAST(-1 AS BIGINT) AS k; EXPLAIN ANALYZE SELECT * FROM probe WHERE NOT EXISTS (SELECT 1 FROM null_keys WHERE null_keys.k = probe.k) LIMIT 10; EXPLAIN ANALYZE SELECT * FROM probe WHERE NOT EXISTS (SELECT 1 FROM other_keys WHERE other_keys.k = probe.k) LIMIT 10; ``` Both plans are `HashJoinExec: mode=CollectLeft, join_type=RightAnti, on=[(k@0, k@0)], fetch=10`, and both return 10 rows. With `null_keys` as the build side, the join's probe metrics are `input_batches=13, input_rows=100.0 K`: it read the whole probe side. With `other_keys`, whose map has an entry, they are `input_batches=1, input_rows=8.19 K`. ### Expected behavior Once it has `fetch` rows, the join stops reading its probe side, as it does when the map has entries. ### Additional context #20492 stopped the join from reading the probe side when an empty build side means empty output. Here the output isn't empty. -- 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]
