Skip to content

fix(plan): avoid premature cross joins and correct semi-join coverage - #32833

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:fix/avoid-premature-cartesian-joins
Nov 17, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:fix/avoid-premature-cartesian-joins

Conversation

@aptend

@aptend aptend commented Nov 17, 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 #32806.

What this PR does / why we need it:

Fix two general planner mechanisms without query-specific rules, executor changes, or spill/budget changes:

  • Join ordering: a multi-input predicate establishes connectivity, but cannot constrain a join before all its inputs exist. Prefer the cheapest next input that closes an available predicate; preserve the existing fallback for unavoidable Cartesian joins. Include list dependencies and stop treating unknown relation tags as input zero. This removes the premature Cartesian join in TPC-DS Q4.
  • SEMI cardinality: filtering rows on a nonunique matching input is not the probability that a preserved key has a match. Reuse the existing ANTI overlap fallback, retain the unique-key dimension model and primary-key bound, and apply the same semantic-side calculation after physical swapping. The 50% fallback represents uncertainty, not measured key coverage. This lets Q35 use existing parallel range-shuffle rather than a severely underestimated broadcast/serial stage.

Measured performance

Same-host TPC-DS 1T, one CN / 64 CPUs, unchanged original SQL and settings:

Query Before After Improvement
Q4 >300.051 s, timed out 85.360 s, PASS >3.51x faster
Q35, mean of two pairs 62.175 s 33.630 s 45.9% less time

Q35 pairs were 63.260→33.160 s and, with service order reversed, 61.090→34.100 s. Both returned byte-identical outputs. Q4 matches the historical successful output byte-for-byte; the timed-out control has no complete result to compare. Q31/Q24/Q62/Q99 and Q10/Q23/Q69/Q78/Q83 also completed with equivalent results; these controls are not counted as additional established speedups.

Measurements used main 8e8708a8d3 plus the respective unchanged patches before rebasing onto e765c5fd44. Q35's parent already includes the Q4 fix. Settings: max_dop=0, agg_spill_mem=4GiB, join_spill_mem=0 (automatic), sort_spill_mem=512MiB, GOGC=200, cgroup MemoryMax=192GiB/no swap, auto merge off. These are lab measurements, not a rerun of #32806's distinct 40GiB/automatic-spill configuration.

Validation

  • After rebasing: the complete pkg/sql/plan test package passes (60.56 s), including focused predicate-availability, dependency, SEMI coverage, PK-bound and physical-swap checks.

  • All 103 TPC-DS statements and 22 TPC-H 1T captured-fixture plans build on both current main and this branch. Q4/Q31 conditionless INNER joins each go from 1 to 0; no new conditionless joins appear. All 22 TPC-H reachable operator, expression, join-orientation, shuffle and runtime-filter shapes remain unchanged after normalizing numeric estimates; Q4/Q21 derived block-count estimates differ. This is plan regression evidence, not a new native TPC-H timing claim.

  • Local incremental SCA passes on all 111 affected packages selected by the repository's verified Go production/test reverse-dependency graph. Pinned tools: molint v0.0.0-20261115233300-147a3f213653, golangci-lint 2.14.0; tests are included. Commands, with selected containing that same package list:

    go vet -mod=readonly -p=2 "${selected[@]}"
    molint check -mod=readonly "${selected[@]}"
    golangci-lint run --concurrency=4 -c .golangci.yml "${selected[@]}"

    All exit 0 with no findings; gofmt and git diff --check also pass.

Only planner implementation and focused unit tests are included: 6 files, +229/-15 lines. Fixtures, benchmark data, scripts and experimental merge settings remain outside the PR.

@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 →

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 37a72bd205867cac56506c09cba2e44b3ef9db52

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 37a72bd205867cac56506c09cba2e44b3ef9db52

Assessment: approve

The changes preserve predicate availability and join boundaries while reusing existing overlap and primary-key rules for SEMI estimates across physical orientations. The bounded, query-local bookkeeping is justified; no actionable correctness or design issues remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Seven focused planner tests passed, including all changed roots and the existing 22-query TPC-H planning fixture.

  • The same selection against exact merge-base production sources failed for the intended dependency, premature-Cartesian and SEMI-bound defects; unchanged controls passed.

  • The complete planner suite passed (47.438s). EXPLAIN consumer tests and go vet also passed.

  • Isolation preflight, fresh native build, formatting, whitespace and native fingerprint checks passed. Tests used Go 1.27.1 and the assigned test-exec.

  • Command receipts, retained logs, discussion coverage and source identity were reconciled in validation-audit.json. Frozen source remains unchanged.

Limitations:

  • Author-reported TPC-DS 1T timings, captured-fixture comparisons and 111-package static checks have no supplied raw receipts and were not independently rerun.

@mergify mergify Bot added the queued label Nov 17, 2026
@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · Matrixone CI execution / UT Test on Ubuntu/x86 fails with this pull request

3 h 55 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 17 Nov, 07:24 · rule main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in place
  • 🚫 Left the queue 11:19 · a19258f

The failure is in this pull request. It failed tested alone on top of main.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Failing checks:

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — a19258fb Deployed Nov 17, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants