Repository navigation
Stop reading the left side of a left semi join with an empty right side - #119218
Conversation
`alwaysReturnsEmptySet` reports that a join can only produce an empty result, and `JoiningTransform` then finishes without reading its left input. It was true for `INNER` and `RIGHT` joins only, but a `LEFT SEMI` join keeps a left row solely because it has a match, so an empty right side empties it just the same. `GraceHashJoin` gates the same check on the join kind before it looks at its buckets, so it needs the same condition. The join runtime filter already stops the left side of such a join, which is why this is not visible with the default settings; with `enable_join_runtime_filters = 0` a left semi join over 50 million rows against an empty right side reads all of them, and none after this change. Co-Authored-By: Claude Opus 5 <[email protected]>
…ut of this PR Both are independent of `INTERSECT`/`EXCEPT` and are reviewed on their own: - the final `DISTINCT` on all threads, with the constant-sort gather it needs, in ClickHouse#119228 - the left semi join that stops reading its left side for an empty right side, in ClickHouse#119218 `scatterByPartition`'s limit helpers and the `SortingStep` gather stay here as well, because the partitioned `INTERSECT`/`EXCEPT` step needs them too; they are the same change in both pull requests. Related: ClickHouse#119228 Related: ClickHouse#119218
|
Workflow [PR], commit [7dc02e8] Summary: ❌
AI ReviewSummaryThis PR extends the empty-right early exit to Findings
Final VerdictChanges requested. The join-side implementation is fine, but the functional regression test is still weaker than the contract this PR promises. LLVM Coverage ReportMeasured on commit 7dc02e8.
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
…e too `MergeJoin` accepts `LEFT SEMI` and runs through the same `JoiningTransform` early exit as the hash joins, but its `alwaysReturnsEmptySet` still reported an empty result for `INNER` and `RIGHT` only, so `join_algorithm = 'partial_merge'` kept reading the whole left side. `min_max_right_blocks` stays empty when the right side is, because `mergeRightBlocks` returns before filling it, so the same condition applies. The test covers `partial_merge` alongside the hash-based algorithms. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Build profile diff (arm_release)Comparing commit See the job log for details. |
|
@vdimir can you give those failed tests a retry, they shouldn't be related to this PR |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
@groeneai reference the PR where |
|
Fixed by #119298, the revert of #118606 "Proper partition pruning with dates", merged 2026-09-10 17:26 UTC as The run here predates that revert, so the fix is not in the tree it tested. Two of the five failures are in A plain job retry will not clear it. Another PR whose tested tree also predates the revert had |
|
@raimannma Could you please add a performance test? |
The left key is hashed with `sipHash64` to give the left side a cost worth
skipping: a plain `numbers_mt` source is read in a few milliseconds.
Local comparison against master (13 runs per side, one hyperthread per
physical core), median client time in seconds:
join_algorithm master branch
hash 0.336 0.0035
parallel_hash 0.356 0.0058
grace_hash 0.425 0.0040
partial_merge 0.473 0.0033
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_018vHnrNqPvYi4i6xkDih7XK
2dc8de9
A
LEFT SEMIjoin keeps a left row solely because it has a match on the right, so an empty right side makes the whole result empty - exactly as it does for anINNERorRIGHTjoin.alwaysReturnsEmptySetreported that only for the latter two, soJoiningTransformkept reading the left side of a left semi join that could not produce a single row.GraceHashJoingates the same check on the join kind before it looks at its buckets, andMergeJoin(join_algorithm = 'partial_merge') also acceptsLEFT SEMIand runs through the sameJoiningTransformearly exit, so both get the same condition.The join runtime filter already stops the left side of such a join, which is why this is not visible with the default settings. With
enable_join_runtime_filters = 0, a left semi join over 50 million rows against a right side that turns out empty reads all 50 million of them, and none after this change. The test asserts that throughsystem.query_log.read_rows, for thehash,parallel_hash,grace_hashandpartial_mergealgorithms.Split out of #118230, where
INTERSECT DISTINCTwith an empty right arm needs it to stop as early as the set-operation step does. It stands on its own: it speeds up any left semi join whose build side turns out to be empty.Related: #118230
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
LEFT SEMIjoin whose right side is empty no longer reads its left side.Workflow [PR]
Sync PR [sync-upstream/pr/119218]
Version info
26.9.1.1588(included in26.9and later)