Repository navigation
perf(plan): eliminate implied semi joins using key containment - #28462
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed all five changed files at exact head 516afdd and traced the rule through projection removal, semi-join pushdown, comparison/structural-identity helpers, subsequent statistics refresh, physical child swapping, column remapping and runtime-filter generation. No confirmed merge-blocking finding.
The bounded optimizer rule has a sound conservative proof for its accepted domain: one injective mapping accounts for every removed base-table occurrence and snapshot; every removed predicate must be total/side-effect-free and present under that mapping; and every membership-key component must follow from the same retained relation witness. Duplicate build witnesses therefore do not multiply probe rows, NULL equality does not establish a witness, and an empty retained build cannot admit rows. The direct-column/same-representation equality closure avoids treating a coercing equality as value identity. Full ObjectRef identity and snapshot comparison avoid table-name-only or cross-snapshot matching. Outer joins, limits/offsets, barriers, projections on intermediate operators, unsupported expressions and over-limit scan relations conservatively decline the rewrite.
The placement before swapJoinChildren is important: IsRightJoin is still a physical orientation hint, so the logical probe remains Children[0]. Statistics, physical orientation, column reference counts/remapping and runtime filters are recomputed after the rewrite. The rule introduces no executor/protocol/catalog change, goroutine, shared mutable cache or cleanup obligation; temporary proof state is query-local. The six-scan cap bounds injective enumeration to at most 720 complete assignments per candidate, with predicate-dependent comparison cost rather than a statistics-dependent legality decision. This is a focused optimizer improvement, not a new execution subsystem/major-refactor design gate.
Tests include a real planner positive and non-implied control, composite-key consistency, disconnected keys, snapshot/limit/fallible-predicate rejection, physical orientation, plus SQL NULL/duplicate/empty-build cases and an independent result oracle. Exact-head CI run 34306229880 reports successful Linux UT, SCA, shared build, coverage and complementary proxy/pessimistic BVT jobs. I did not independently rerun the native package or TPC-DS benchmark. The reported Q95 948s-to-522s result is one controlled local comparison, not a general performance guarantee; recognition remains intentionally limited to adjacent logical SEMI joins.
Merge Queue Status
This pull request spent 19 minutes 31 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #28462 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
…xorigin#28462) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to matrixorigin#26768. This PR contributes a stats-independent redundant SEMI join elimination rule to the optimizer roadmap; it does not complete or close the tracking issue. ## What this PR does / why we need it: Eliminate an outer SEMI join when the inner SEMI already proves membership in its build-side key set. For example, `x IN A AND x IN (A JOIN B)` need not evaluate A again. In TPC-DS Q95 this removes a redundant warehouse self-join: web_sales scans decrease from five to three, and SEMI joins from two to one. The proof maps every base-table occurrence, snapshot and total predicate of the removed side into a conjunctive scan/filter/INNER JOIN relation. Membership keys must match directly or through same-type equality. Unsupported shapes remain unchanged; scan mapping is bounded to six occurrences. Legality uses no cardinality estimates, table-name checks or query-specific constants. Recognition currently requires adjacent logical SEMI joins. In a single local TPC-DS 1T comparison against main `585a38efd1` (16 vCPUs, 31 GiB RAM, 128 MiB spill thresholds, 20 GiB process-cgroup limit, merge disabled), Q95 decreased from **948s to 522s**, with identical results. Sampled peak RSS decreased from **12.11 GiB to 9.00 GiB**; both runs had zero cgroup swap and OOM events. TPC-H 1G and 100G ordinary EXPLAIN plans were byte-identical before/after for all 22 queries at each scale. Planner package tests pass. SQL regression checks cover NULLs, duplicate witnesses, an empty build and a missing-predicate counterexample, and passed twice in normal comparison mode (16/16 statements each run). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…xorigin#28462) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to matrixorigin#26768. This PR contributes a stats-independent redundant SEMI join elimination rule to the optimizer roadmap; it does not complete or close the tracking issue. ## What this PR does / why we need it: Eliminate an outer SEMI join when the inner SEMI already proves membership in its build-side key set. For example, `x IN A AND x IN (A JOIN B)` need not evaluate A again. In TPC-DS Q95 this removes a redundant warehouse self-join: web_sales scans decrease from five to three, and SEMI joins from two to one. The proof maps every base-table occurrence, snapshot and total predicate of the removed side into a conjunctive scan/filter/INNER JOIN relation. Membership keys must match directly or through same-type equality. Unsupported shapes remain unchanged; scan mapping is bounded to six occurrences. Legality uses no cardinality estimates, table-name checks or query-specific constants. Recognition currently requires adjacent logical SEMI joins. In a single local TPC-DS 1T comparison against main `585a38efd1` (16 vCPUs, 31 GiB RAM, 128 MiB spill thresholds, 20 GiB process-cgroup limit, merge disabled), Q95 decreased from **948s to 522s**, with identical results. Sampled peak RSS decreased from **12.11 GiB to 9.00 GiB**; both runs had zero cgroup swap and OOM events. TPC-H 1G and 100G ordinary EXPLAIN plans were byte-identical before/after for all 22 queries at each scale. Planner package tests pass. SQL regression checks cover NULLs, duplicate witnesses, an empty build and a missing-predicate counterexample, and passed twice in normal comparison mode (16/16 statements each run). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…xorigin#28462) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to matrixorigin#26768. This PR contributes a stats-independent redundant SEMI join elimination rule to the optimizer roadmap; it does not complete or close the tracking issue. ## What this PR does / why we need it: Eliminate an outer SEMI join when the inner SEMI already proves membership in its build-side key set. For example, `x IN A AND x IN (A JOIN B)` need not evaluate A again. In TPC-DS Q95 this removes a redundant warehouse self-join: web_sales scans decrease from five to three, and SEMI joins from two to one. The proof maps every base-table occurrence, snapshot and total predicate of the removed side into a conjunctive scan/filter/INNER JOIN relation. Membership keys must match directly or through same-type equality. Unsupported shapes remain unchanged; scan mapping is bounded to six occurrences. Legality uses no cardinality estimates, table-name checks or query-specific constants. Recognition currently requires adjacent logical SEMI joins. In a single local TPC-DS 1T comparison against main `585a38efd1` (16 vCPUs, 31 GiB RAM, 128 MiB spill thresholds, 20 GiB process-cgroup limit, merge disabled), Q95 decreased from **948s to 522s**, with identical results. Sampled peak RSS decreased from **12.11 GiB to 9.00 GiB**; both runs had zero cgroup swap and OOM events. TPC-H 1G and 100G ordinary EXPLAIN plans were byte-identical before/after for all 22 queries at each scale. Planner package tests pass. SQL regression checks cover NULLs, duplicate witnesses, an empty build and a missing-predicate counterexample, and passed twice in normal comparison mode (16/16 statements each run). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Related to #26768. This PR contributes a stats-independent redundant SEMI join elimination rule to the optimizer roadmap; it does not complete or close the tracking issue.
What this PR does / why we need it:
Eliminate an outer SEMI join when the inner SEMI already proves membership in its build-side key set. For example,
x IN A AND x IN (A JOIN B)need not evaluate A again. In TPC-DS Q95 this removes a redundant warehouse self-join: web_sales scans decrease from five to three, and SEMI joins from two to one.The proof maps every base-table occurrence, snapshot and total predicate of the removed side into a conjunctive scan/filter/INNER JOIN relation. Membership keys must match directly or through same-type equality. Unsupported shapes remain unchanged; scan mapping is bounded to six occurrences. Legality uses no cardinality estimates, table-name checks or query-specific constants. Recognition currently requires adjacent logical SEMI joins.
In a single local TPC-DS 1T comparison against main
585a38efd1(16 vCPUs, 31 GiB RAM, 128 MiB spill thresholds, 20 GiB process-cgroup limit, merge disabled), Q95 decreased from 948s to 522s, with identical results. Sampled peak RSS decreased from 12.11 GiB to 9.00 GiB; both runs had zero cgroup swap and OOM events. TPC-H 1G and 100G ordinary EXPLAIN plans were byte-identical before/after for all 22 queries at each scale.Planner package tests pass. SQL regression checks cover NULLs, duplicate witnesses, an empty build and a missing-predicate counterexample, and passed twice in normal comparison mode (16/16 statements each run).