Skip to content

perf(plan): eliminate implied semi joins using key containment - #28462

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:perf/eliminate-implied-semi-joins
Sep 9, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:perf/eliminate-implied-semi-joins

Conversation

@aptend

@aptend aptend commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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).

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mergify mergify Bot added the queued label Sep 9, 2026
@mergify

mergify Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-09 05:13 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-09 05:32 UTC · at d54de9621f4f7f5d3ec2b5b27a58cc765357c63a

This pull request spent 19 minutes 31 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You 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.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 5b4fda4 into matrixorigin:main Sep 9, 2026
25 of 26 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 9, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants