Skip to content

perf(sql): hash safe nullable composite EXISTS witnesses - #31848

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/nullable-mark-witness-31829
Oct 30, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/nullable-mark-witness-31829

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 30, 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 #31829.

What this PR does / why we need it:

Projected correlated EXISTS over duplicate-heavy nullable composite keys can repeatedly scan the complete witness input. The planner already knows when a consumer needs only Boolean existence, but compilation loses that distinction and conservatively uses the three-valued loop MARK path.

Preserve that proof on the plan and lower eligible broadcast MARK joins to the existing hash membership operator. TRUE requires a complete non-NULL matching key; every other existence result is FALSE. Preserve the existing IS TRUE consumer and scalar DISTINCT/LIMIT reconstruction, including NULL on no witness. Ordinary IN/NOT IN/ANY/ALL keep their three-valued semantics and existing shuffle restrictions.

The initial domain is direct cross-input equality on matching integer types, with no residual or computed key and a finite estimated outer cardinality greater than one. Missing/small estimates and unsupported shapes retain the old path. Planner totality checks protect errors and volatile join operands. Reuse HashBuild's existing map, memory accounting, producer-error propagation and cleanup; add no deduplication stage, cache or owner. Copy and transport the Boolean operator mode consistently. Additive proto fields default to false for older persisted plans; no new per-feature protocol gates under the repository's shutdown-upgrade contract.

Design: Boolean existence MARK, revision 1.2. Terra/max designed the solution before implementation and performed the final overall review.

Performance and tradeoffs (local Linux, one CN; timings are observed runs with cache/background-I/O variation):

Fixture Base Candidate
4,512,752 witness rows / 288 outer rows, full query 17.48 s 5.24 s
Same query's MARK operator 11.58 s loop 0.90 ms hash probe + 208.64 ms build
Query hash budget peak for that execution 46.31 MB 61.76 MB
262,144 unique-witness fixture, filtered build 174,763 2.24 s loop 0.067 ms hash probe + 10.04 ms build
Query hash budget peak for unique fixture 2.40 MB 19.73 MB

Both large fixtures return all 288 rows matching independent Python oracles. Operator times are not additive query wall times; these are not an SLA or a controlled production benchmark. DISTINCT controls varied substantially (roughly 4.9–28.7 s). A one-probe timing control was also noisy (23.38 s base / 32.02 s candidate); physical regression coverage confirms it retains LoopJoin, so no speedup is claimed there.

Hash membership exchanges extra O(distinct keys) map memory for avoiding repeated witness scans. Peak build memory still includes existing input copies: O(input rows + distinct keys). The high-distinct fixture adds about 17.33 MB of accounted peak memory. Broadcast builds gain no spill fallback; resource admission can reject a hash plan where a batch-only loop fits. Existing budget failure propagation and zero-account cleanup are tested.

Validation (Go 1.27.1, Linux/amd64, matching native artifacts through the repository CGo wrapper):

  • Focused existing/new race UT: planner, compiler, HashJoin and affected public SQL pass. Cover integer/type/estimate gates, ordinary MARK/shuffle behavior, producer proof, plan copying and wire/default-false fields, exhaustive two-/three-key NULL masks, duplicate build batches and outer rows, reset/reuse, build errors/cancellation, and budget rejection cleanup.
  • Real SQL checks pass for EXISTS/NOT EXISTS alongside IN/NOT IN UNKNOWN, mixed/empty witnesses, prepared execution, scalar reconstruction, binding/runtime errors, and actual HashJoin versus one-probe LoopJoin selection. Existing correlated-CTE consumer regression also passes under race.
  • Existing two-CN fixture passes under race with peer execution and shared broadcast consumers; no additional heavy cluster fixture.
  • Full normal owning-package tests pass for planner, compiler, HashJoin and both changed protobuf packages.
  • Incremental seven-package go vet, configured golangci-lint (0 issues) and Makefile-pinned molint pass. The final test cleanup delta also passes focused race and incremental SCA. Gofmt and diff checks pass.

Remote CI is pending. This does not optimize general nullable composite IN/NOT IN, computed keys, non-integer domains or single-probe estimates.

@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 Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 8f244d4cd399ac4513fe618625ebe1c1f7ad9255

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 8f244d4cd399ac4513fe618625ebe1c1f7ad9255

Assessment: approve

No actionable defects found. The Boolean EXISTS path preserves ordinary MARK semantics, copying, transport and resource ownership. The documented additional-memory tradeoff is acceptable.

Model: gpt-6-astra / xhigh

Session: 01a1869d-999c-7481-b340-ae4a63e8cee4 · slot 1 · generation 2

Validation:

  • Full normal tests passed for both protobuf packages, hashjoin, planner and compiler.

  • Public nullable-EXISTS SQL and two-CN integration tests passed.

  • Four focused dependency/reuse tests passed under race detection, including 100 repetitions each.

  • Seven changed packages passed go vet; formatting and diff checks passed.

  • Decoded protobuf descriptors contain only the intended additions. Discussion coverage and source immutability verified.

  • Commands, exits and retained logs reconciled in validation-ledger.json and validation-audit-v2.log.

Limitations:

  • Performance measurements remain author-reported; benchmarks were not independently repeated.

  • Configured golangci-lint was unavailable; static validation used go vet.

@XuPeng-SH
XuPeng-SH merged commit 4183159 into matrixorigin:main Oct 30, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/nullable-mark-witness-31829 branch October 30, 2026 19:10
gouhongshen added a commit to gouhongshen/matrixone that referenced this pull request Oct 30, 2026
…sion

Upstream 4183159 (matrixorigin#31848) added plan.Node.mark_existence_only = 96 and
pipeline.HashJoin.existence_only = 19 while this branch had already assigned
Node field 96 to its additive ScanReadRole scan_read_role.

Resolution (semantic, both sides kept):
- upstream's mark_existence_only keeps field number 96 (shipped on main);
- this branch's additive scan_read_role moves to field number 97 - the
  branch was never merged, so no serialized plan ever carried 96 as
  scan_read_role;
- plan.pb.go and pipeline.pb.go are regenerated from the merged protos with
  the repository protoc/gogofast toolchain plus the
  plan_string_literal_form and plan_collation_admission postprocess steps;
  the same toolchain reproduces upstream main's committed bindings
  byte-for-byte from main's own protos, so the merged bindings are
  upstream's content plus only this branch's additive fields, in upstream's
  exact generation style;
- all other overlapping files auto-merged with both sides' hunks intact:
  deepcopy.go still copies both MarkExistenceOnly and ScanReadRole, and
  upstream's HashJoin wiring in convertToVmOperator lives in distinct
  functions from this branch's LockOp marking.

Full-tree go build ./pkg/... and the focused conflict-resolution test
ladder are green (see the PR description for the dated record).

This branch was successfully deployed

No deployments
ci — e9ea4704 Deployed Oct 30, 2026 by XuPeng-SH
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.

[Performance]: projected nullable EXISTS spends seconds on duplicate-heavy MARK join witnesses

2 participants