Repository navigation
Add RemoveRedundantSemiJoinPass to eliminate redundant SEMI/ANTI joins - #103254
Draft
wudidapaopao wants to merge 15 commits into
Draft
wudidapaopao wants to merge 15 commits into
wudidapaopao wants to merge 15 commits into
Conversation
New analyzer pass that drops a `LEFT SEMI` / `LEFT ANTI JOIN` when its right-hand side is provably a subset (SEMI) or superset (ANTI) of another sibling SEMI/ANTI on the same key. Controlled by `optimize_remove_redundant_semi_join` (enabled by default).
Contributor
|
Workflow [PR], commit [18d8115] Summary: ❌
|
T38: SEMI with two-key ON drops the looser one. T39: SEMI with two-key ON, conjuncts reordered and operands flipped, still optimises (verifies canonicalisation in `extractJoinKeys`). T40: SEMI multi-key vs single-key on the same table fall in different buckets and are kept.
T41: SEMI multi-key ON where one equals has an expression on the LHS, identical between two SEMI joins, drop the looser one. T42: SEMI multi-key ON where one equals has neither side resolving to a right-table physical column, no elimination.
…pression modifiers (SAMPLE, FINAL, ...)
wudidapaopao
force-pushed
the
eliminate_redundant_join
branch
from
April 21, 2026 12:04
f4596b3 to
f682d31
Compare
wudidapaopao
force-pushed
the
eliminate_redundant_join
branch
from
April 21, 2026 13:44
c73b6ae to
ebc0913
Compare
| DECLARE(Bool, optimize_if_transform_strings_to_enum, false, R"( | ||
| Replaces string-type arguments in If and Transform to enum. Disabled by default cause it could make inconsistent change in distributed query that would lead to its fail. | ||
| )", 0) \ | ||
| DECLARE(Bool, optimize_remove_redundant_semi_join, true, R"( |
Contributor
There was a problem hiding this comment.
This PR introduces a new user-facing setting, but the PR metadata still has Documentation is written unchecked and there is no matching docs update for optimize_remove_redundant_semi_join.
Please add docs for the setting (behavior, default, and safety limitations) and then mark the documentation checkbox accordingly.
wudidapaopao
force-pushed
the
eliminate_redundant_join
branch
from
April 22, 2026 11:31
a07797a to
db4bbee
Compare
wudidapaopao
force-pushed
the
eliminate_redundant_join
branch
from
April 22, 2026 11:33
db4bbee to
cef8c4d
Compare
1 task done
Contributor
LLVM Coverage Report
Changed lines: 95.41% (270/283) · Uncovered code |
1 task
wudidapaopao
marked this pull request as draft
July 3, 2026 05:37
…_join Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. - retargeted PR record [email protected] to 26.10 (settings-history check rule) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #77400.
Adds a new analyzer pass
RemoveRedundantSemiJoinPassthat drops aLEFT SEMI/LEFT ANTI JOINwhen its right-hand side is provably redundant against a sibling SEMI/ANTI on the same key.Approach
For each top-level query the pass walks the join tree and collects every
LEFT SEMI/LEFT ANTIwhose right side is the simple shapeSELECT [...] FROM table [WHERE ...]joined on a single equi-key. Each candidate is summarised by(base table, right-side join column, set of WHERE conjuncts on the right side, count of RIGHT/FULL outer joins between the candidate and the join-tree root).Candidates that share base table and right key are then bucketed and compared pairwise:
RIGHT/FULLbarrier in the unsafe direction.Gated by the new setting
optimize_remove_redundant_semi_join(enabled by default).Cases that are optimized
INNER,LEFT, andRIGHT/FULLin the safe direction) between the two candidates do not block elimination.Cases that are NOT optimized
SELECT [...] FROM table [WHERE ...](GROUP BY,DISTINCT,LIMIT, aggregates, joins,PREWHERE, computed projections — all skipped).age > 10⊇age > 20is not detected.SELECT,WHERE,GROUP BY/HAVING,ORDER BY, or a siblingJOIN ... ON.RIGHT/FULLouter join between the two candidates in the unsafe direction (its NULL-padding interacts differently with SEMI and ANTI).ANDofequals, or someequalshas neither side resolving to a physical column on the right base table.Test coverage matrix lives in
tests/queries/0_stateless/04099_remove_redundant_semi_join.sql(44 cases: 17 positive, 27 negative).Changelog category (leave one):
Changelog entry:
Added analyzer pass
RemoveRedundantSemiJoinPassthat removes aLEFT SEMI/LEFT ANTI JOINwhen its right-hand side is provably redundant against a sibling SEMI/ANTI on the same key. Controlled by the new settingoptimize_remove_redundant_semi_join(enabled by default).Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/103254]