Skip to content

fix(plan): hash safe arithmetic and OR EXISTS predicates - #32087

Merged
mergify[bot] merged 4 commits into
matrixorigin:mainfrom
ck89119:issue-31869-main
Nov 3, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:mainfrom
ck89119:issue-31869-main

Conversation

@ck89119

@ck89119 ck89119 commented Nov 3, 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:

Fixes #31869

What this PR does / why we need it:

Avoid quadratic nested-loop joins for safe expression-correlated EXISTS/NOT EXISTS predicates such as i.id = o.id - 1.

  • Reuse the exact integer-range proof to expose arithmetic equality keys to existing hash SEMI/ANTI/MARK joins. Recheck current predicates and column origins before MARK conversion; retain IN/ANY/ALL three-valued semantics.
  • Split eligible top-level OR predicates into at most eight independently rebound existence branches. Combine totalized markers before applying NOT, preserving NULL handling and outer-row multiplicity.
  • Keep unsafe/unproved expressions, non-equality OR arms, extra correlated residuals, and complex inner relations on their existing paths. This does not implement index merge for [Performance]: OR across two indexed columns scans the full table #31863.

Validation with Go 1.27.1:

  • Full planner/compiler package tests, including public SQL planning, fallback/ownership/cancellation checks, and assertions that compilation produces HashJoin operators.
  • go vet, incremental lint, and the standard service build passed. Changed-statement coverage: 117/119 (98.3%).
  • Generated and independently checked the SQL regression results; two normal mo-tester comparison runs on the same instance passed 43/43 each, with no ignored cases and verified database cleanup. These comparisons exclude wire metadata; typed-plan tests check non-null existence markers.
  • Exact result parity at 20k/200k rows. Local warm two-arm OR EXISTS timings: 3.45–3.58 ms / 15.67–15.98 ms; no cross-machine speedup claim.

Validation was performed on dd2499cdcd plus this patch and reused after syncing the unrelated MinIO range-read and HA deployment changes in 38f4ba6804; the affected SQL paths, fixtures, toolchain, and DISK-V2 test backend are unchanged.

@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Nov 3, 2026
@ck89119
ck89119 marked this pull request as ready for review November 3, 2026 14:11
@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 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 3c96ad5bb567b39fe55d891db17ec194228e5b57

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: 3c96ad5bb567b39fe55d891db17ec194228e5b57

Assessment: approve

The fix coherently reuses existing range proofs, totality checks and hash executors. The bounded OR expansion preserves NULL semantics, outer-row multiplicity, conservative error fallbacks and index hints. No actionable defects remain.

Model: gpt-6.1-sol / max

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

Validation:

  • Full planner and compiler package tests passed with Go 1.27.1, -count=1 and the assigned test-exec: 4,658 and 1,687 top-level tests. All 13 changed test roots passed; two unrelated subtests were skipped. Log: plan-compile-test.log; receipt: checks/1793720468225950798-3.json.

  • Independent SQLite oracle matched all 26 row-result queries in the 43-statement SQL fixture. Log: sql-result-oracle.log; receipt: checks/1793720312434184680-3.json.

  • Isolation preflight, native build and native provenance verification passed. Source identity, clean checkout, discussion coverage and execution receipts reconciled successfully in validation-evidence.json; audit receipt: checks/1793720608082492196-3.json.

  • Reviewed all nine changed files, complete discussion, linked issues and affected planner/compiler consumers. Frozen exact-head CI reports successful UT, SCA, shared build and multi-CN BVT checks.

Limitations:

  • No fresh MatrixOne SQL runtime or performance run was performed locally; author-reported execution and timing results were not independently reproduced.

  • The SQLite oracle excludes wire metadata and MatrixOne-specific overflow evaluation order. Raw CI logs and earlier author validation artifacts were unavailable.

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

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as dbf3efd at 18:31 UTC

2 h 46 min in the queue, 1 h 4 min of it CI.

So far

  • ✅ Entered the queue Tue 3 Nov, 15:45 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 18:31 · dbf3efd · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@aunjgr aunjgr 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 nine changed files, the predicate/origin totality checks, independent-arm rebinding and hint ownership, MARK conversion, compile consumer tests, and SQL result pairs. No actionable finding. Arithmetic admission reuses exact overload/intermediate-range proofs rather than assuming determinism implies totality. OR expansion is capped at eight arms, admits only safe same-block scan chains, and totalizes each existence marker before combining/negating, preserving duplicate outer rows and EXISTS versus IN/ANY/ALL NULL semantics. Unsafe expressions, volatile/fallible projections, complex inner inputs, extra correlations, cancellation and hint paths retain explicit controls. Reused the recorded planner/compiler and public SQL differential/comparison evidence and successful current-head CI; no new local test run.

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: correlated EXISTS with expression correlate runs as nested-loop MARK join

4 participants