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
Sort-merge join ignores a join filter that references no columns (wrong FULL JOIN results) #26002
SortMergeJoinExec skips a join filter whose expression references no columns, so a FULL JOIN keeps pairs that the filter rejects. Hash join returns the correct result.
A common way to end up with such a filter is a prepared statement with a parameter-only condition in the ON clause: once the parameter is bound, the condition (e.g. 3 > 5) no longer references any column.
The same happens with a boolean parameter, and with a volatile function that takes no columns:
PREPARE qb(BOOLEAN) ASSELECTcount(*) FROM a FULL JOIN b ONa.k=b.kAND $1;
EXECUTE qb(false);
-- 4, expected 6SELECT*FROM a FULL JOIN b ONa.k=b.kAND random() >2ORDER BYa.k, b.k;
-- the same 4 rows as above-- EXPLAIN: SortMergeJoinExec: join_type=Full, on=[(k@0, k@0)], filter=random() > 2
(With target_partitions = 1 the planner picks HashJoinExec and the results are correct.)
Expected behavior
3 > 5 (and random() > 2) is false for every pair, so nothing matches and every row is NULL-padded, as with SET datafusion.optimizer.prefer_hash_join = true:
Reproduced on current main (Oct 3 2026). LEFT, RIGHT and INNER joins with the same conditions return correct results.
In sort_merge_join/materializing_stream.rs the filter is only evaluated under if !filter_columns.is_empty(), so a filter whose expression reads no columns is skipped and every candidate pair is kept. A possible fix is to evaluate the filter even when it has no columns, building the filter batch with RecordBatchOptions::with_row_count(...) so its row count matches the candidate pairs.
Related: #26001 (same code path, filter batch construction for outer joins).
Activity
fix: evaluate sort-merge join filters that reference no columns (apac…