You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HashJoinExec with a fetch reads its whole probe side when its build-side hash map is empty #27726
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. 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).
To Reproduce
In datafusion-cli:
SETdatafusion.execution.target_partitions =1;
CREATETABLEprobeASSELECT value AS k FROM generate_series(1, 100000);
CREATETABLEnull_keysASSELECT CAST(NULLASBIGINT) AS k;
CREATETABLEother_keysASSELECT CAST(-1ASBIGINT) AS k;
EXPLAIN ANALYZE SELECT*FROM probe WHERE NOT EXISTS (SELECT1FROM null_keys WHEREnull_keys.k=probe.k) LIMIT10;
EXPLAIN ANALYZE SELECT*FROM probe WHERE NOT EXISTS (SELECT1FROM other_keys WHEREother_keys.k=probe.k) LIMIT10;
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.
Activity