Skip to content

fix(sql): bound shared MARK membership on 4.1.6-hotfix - #32315

Merged
XuPeng-SH merged 13 commits into
matrixorigin:4.1.6-hotfixfrom
ck89119:issue-32263-4.1.6-hotfix
Nov 11, 2026
Merged

XuPeng-SH merged 13 commits into
matrixorigin:4.1.6-hotfixfrom
ck89119:issue-32263-4.1.6-hotfix

Conversation

@ck89119

@ck89119 ck89119 commented Nov 6, 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 #32263

Related planner/nullability fixes (#32085 and follow-ups) are in the target; this PR does not replace them.

What this PR does / why we need it:

Design v7 is independently technically accepted and now implemented. XuPeng-SH's exact-revision decision explicitly accepts v7 at e4a87c73b9f745334cef8a23c2feadd072e5312b. That was design acceptance, not implementation or overall PR approval. The remaining eager-index regression and omitted native MemorySize are addressed here; implementation re-review is still required.

Implementation

  • Begin with the existing MARK evaluator. Per exact JoinMap/key descriptor, share completed safe work and admit construction only after 32 × actual published RHS rows, with a real unprocessed probe remaining. Admission reads the published HashBuild count and bounded slot geometry, not RHS keys/batches; construction subsequently validates actual batch counts. Missing, invalid or oversized counts retain the evaluator.
  • Only same-type direct-column equality on integer/Boolean keys qualifies. Actual NULL probes, constant RHS and constant predicate results do not earn fictitious work; real FLAT NULL results are checked through the input key. Count only RHS batches actually evaluated before an early match. Strings, casts, expressions, residual/composite predicates and unsupported metadata retain evaluator behavior.
  • Preserve evaluator-prefix/index-tail output within one Call, remaining output capacity, cross-batch work, SQL three-valued logic, empty/all-NULL RHS, duplicates and Reset/Prepare generations.
  • One immutable native slot array per shared JoinMap, borrowing RHS keys; no per-worker full indexes, key-encoding buffers, new goroutines or wire/shuffle/spill changes. Bound slots to min(64 MiB, pool cap / 8) through cap-enforced MPool. Native calloc supplies zero initialization; no redundant consumer clear.
  • Return newly published native bytes only to the successful builder. Its own goroutine immediately calls its analyzer's Alloc before probing/output can fail. Waiters/reuse/fallback/errors return zero; Reset/Free release ownership without erasing historical allocation, and the next Prepare resets statistics normally.
  • Keep native OOM/cap fallback, original allocator-error propagation and admission rollback. Unrelated errors and mandatory output allocation errors propagate. Waiter cancellation is independent; a cancelled builder does not poison live siblings.

Validation

Go 1.26.4, Darwin arm64, matching CGo artifacts, target cbb7da471a495f21361fcfdc8fa715f6bdd346a0 merged before final validation.

  • All eight owning/reverse-consumer normal packages pass: malloc, MPool, hashmap, batch, aggexec, message, LoopJoin and HashBuild.
  • Message/LoopJoin/HashBuild/batch/aggexec pass -race -short -tags matrixone_test. Exact shared-consumer, cancellation, native-failure, admission, real transition/generation and batch-continuation selections pass race ×100.
  • Real HashBuild→LoopJoin tests prove exactly 32 evaluator probes followed by indexed match/miss/NULL tails, preserved IDs/markers/counts, cross-input-batch credit, DefaultBatchSize+1 continuation both within-Call and after a full output batch, and no build without a future probe.
  • Two concurrent real consumers prove one physical index and exactly one charged analyzer, including delayed final Free. Additional tests cover FLAT NULL, constant RHS, non-NULL constant probes, native OOM/unrelated failure at the admitted allocation boundary, later output errors and post-publication cancellation, plus Reset/Prepare generations.
  • Changed-block statement coverage: 262/269 = 97.40%. Standard vet, golangci-lint 2.6.2 (four changed owning packages), gofmt, err-check and diff checks pass. Full test dependency discovery succeeds with/without matrixone_test (2,167 packages). Previously documented Darwin molint unsafe diagnostics in unchanged allocator files are not claimed as zero findings.
  • Real mo-tester normal comparison on the latest merged target passes twice, 48/48 each, no failures/skips. Prepared NULL/non-NULL/empty RHS generations retain the independent 67-row truth/count oracle; teardown verifies both test databases absent. No 2M-row data is added to maintained UT/BVT.
  • Public EXPLAIN ANALYZE of that same 67-row prepared query body reports 40 bytes per MARK node versus 8 bytes on target, exactly the additional 32-byte native index each. The 2M miss control reports 39.63 MiB versus 7.63 MiB, adding the actual 32-MiB index. Low-work duplicate controls remain at 7.63 MiB. Typed concurrent tests establish once-only attribution across consumers, not merely a positive statistic.

Local performance and explicit tradeoffs

All three binaries use the same latest target planner/function metadata: stock target; pre-adaptive (only six MARK production files restored from accepted e4a87c73b9, including its zeroing repair); and v7. Same native artifacts, single CN, GOMEMLIMIT=4GiB, persistent connection, one warmup + seven measurements, reversed variant order in a second pass. Startup GOMAXPROCS=4 is raised to 10 by this branch's system.init in all three binaries. Every run checks exact result/NULL counts. Numbers are local medians in milliseconds, not an SLA.

Control Target loop Pre-adaptive v7
2M duplicate RHS, 1 early hit 1.893 37.953 1.596
2M duplicate RHS, 256 early hits 6.226 37.967 6.288
2M duplicate RHS, 1 miss 10.327 37.871 10.359
2M duplicate RHS, 256 misses 2179.505 37.762 315.007
2M unique RHS, 1 low-key match 1.968 127.512 1.783
2M unique RHS, 256 low-key matches 32.636 128.725 32.910
2M unique RHS, 1 miss 10.189 129.212 10.296
2M unique RHS, 256 misses 2176.473 128.703 397.138
33 NULL probes, 2M RHS 146.807 37.808 148.934
33 probes, 2M FLAT all-NULL RHS 297.607 15.702 296.664
3k same-type direct-column NOT IN 30.209 1.093 1.420
6k same-type direct-column NOT IN 114.890 0.584 1.024

Dispersion examples for v7: duplicate 1-hit 1.419–1.830 ms, duplicate 256-hit 5.990–6.468, duplicate 256-miss 308.295–319.122, unique 256-miss 391.412–408.808, and direct-column 3k/6k 1.260–1.868 / 1.001–1.363. Unique low-key 256-match measurements are noisy (15.135–244.989 ms); SQL does not promise RHS scan order, so they are not deterministic early-position proof. The duplicate-key controls and operator tests supply that proof.

The 32×B prefix deliberately gives up some pre-adaptive throughput to avoid eagerly hashing a large RHS for cheap probes. Large misses are still faster than target but slower than unconditional indexing; NULL-probe/constant controls deliberately stay conservative. A FLAT all-NULL RHS is not a constant vector: non-NULL probes can earn work and the final probe can build, so no no-allocation claim is made for that case. Original nullable UNION variants remain evaluator-bound on both pre-adaptive/v7 on this target (about 59/232 ms; BIGINT variants 31/116 ms); they are negative compatibility controls, not acceleration evidence. This change does not broaden the approved predicate/metadata domain to address them. Large fixtures, service binaries and raw measurement artifacts remain temporary/uncommitted.

CI status / limitations

This is not a claim that all CI is green. At old head 096a24944259c2d150e9e2399b86785a46a2550c, run 42344369146 attempt 1 lost its self-hosted runner; attempt 2 reported three real RPC/transaction deadline failures tracked in #32474. Their relationship to this PR is unproven, and they are not dismissed as infrastructure/pre-existing. Earlier embedded startup failures remain separately tracked in #32323. Local validation above is not a fix or substitute for those CI results. New-head CI has not been polled.

Add a single cap-enforced membership index per JoinMap for safe scalar equality predicates. Borrow RHS keys without build/probe encoding buffers, preserve evaluator fallback, and isolate consumer cancellation.

Fixes matrixorigin#32263
Return calloc errors instead of panicking after native admission so optional MARK indexes can publish evaluator fallback. Cover pool/global rollback, shared waiter termination, and unrelated-error propagation with deterministic allocator failures.
Remove the batch-aware helper from common/hashmap to break the batch self-test -> aggexec -> hashmap -> batch import cycle. Preserve the complete index implementation and test matrix in vm/message and validate the full test dependency graph.

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

基于 096a24944259c2d150e9e2399b86785a46a2550c 复审,结论为 Request changes。CI 失败没有作为结论依据。

当前生产实现仍有两项已复现且未关闭的问题:

  1. 小 probe / 早命中无条件构建整个 RHS 索引:同机 SQL 对照中,2M 重复 RHS、1 个 probe 的 NOT IN 中位数从 2.083 ms 增至 74.808 ms;256 个早命中 probe 的 IN 从 7.655 ms 增至 74.195 ms。
  2. 索引分配未计入算子内存统计:真实算子中 index 为 262,144 bytes,而 LoopJoin 的 MemorySize 为 0;MPool cap 仍然生效。

本轮还发现分配后重复清零带来的实际开销,见新的行内意见。

v6 设计结论:暂不批准 这个确切设计版本。 将成本信用和共享索引放在已有 JoinMap、先走 evaluator、限定固定宽度域、由唯一 builder 计费一次,这些方向合理;接受仅加速整数/Boolean、按 RHS 行数预留以及 32×B 需要实测验证的取舍。但当前设计还明确要求对已经归零的分配再次清零,和现有分配器职责重复,并有可测开销。请根据行内意见修订设计及实现,再对修订后的确切版本作技术评审;32×B 的性能矩阵仍须在实现后验证。此处不是对 v4 实现或合并的批准。

历史意见状态:等待者取消测试现已在 ready/context select 处同步,且验证 builder 放行前等待者独立返回,该线程可以维持 resolved。跨阈值 SQL 的 67 行 fixture 与真实 FLAT/NULL evaluator 控制已经补入,v6 也规定了真实 HashBuild → LoopJoin 的切换及统计断言;但这些是尚未实施方案的验收要求,不能把 v4 的通过结果当成自适应路径已验证,该线程应保持 open。实现 v6 时也请删除只服务已退出优化范围的变长索引代码及测试,保留实际 SQL/evaluator 兼容控制。

验证:当前 head 的 malloc、mpool、message、loopjoin 四个相关包普通测试通过;共享构建、取消、分配失败及真实 evaluator 等定向 race 测试通过。新增的清零对照使用同一 head 的临时测试 overlay,没有改动 PR 工作区。

Comment thread pkg/vm/message/membership_index.go Resolved
Remove the redundant whole-index clear after native MakeSlice. Document the existing MPool zero-initialization contract and verify typed native allocations and poisoned index rebuilds without assuming address reuse. Leave the adaptive admission and analyzer design approval-gated.
Record the v6 design rejection and restore allocator ownership of zero initialization. Keep the remaining adaptive design and acceptance evidence explicitly pending independent review.
@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: e4a87c73b9f745334cef8a23c2feadd072e5312b

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: e4a87c73b9f745334cef8a23c2feadd072e5312b

Assessment: request_changes

Design v7 is technically accepted with its stated tradeoffs and reuse of existing owners. The waiter and duplicate-zeroing concerns are resolved. Two previously reported implementation defects remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

  • P2 pkg/sql/colexec/loopjoin/join.go:201: An eligible MARK join has few or early-matching probes against a large RHS.
    Impact: The first probe still triggers a full RHS scan and row-sized index reservation—for example, 32 MiB for two million duplicate keys. Implement work-based admission so low-work inputs retain the evaluator.
    Evidence: GetMembershipIndex runs before the probe loop and immediately builds the index. The supplied v4 comparison reported 2.083→74.808 ms for one early-matching probe. These admission paths remain unchanged; removing clear does not implement v7's adaptive selection.

  • P2 pkg/vm/message/membership_index.go:103: LoopJoin creates the shared native index after HashBuild publishes its JoinMap.
    Impact: Up to 64 MiB of index storage is omitted from operator MemorySize and EXPLAIN ANALYZE. Attribute published bytes exactly once through the successful builder's analyzer.
    Evidence: HashBuild reports allocations before publication, while LoopJoin never reports the later index allocation. JoinMap.Size does not refresh analyzer statistics. The prior reproduction showed a 262,144-byte index with MemorySize=0; these accounting paths remain unchanged. MPool caps still apply.

Validation:

  • Reviewed all 17 changed files, 12 discussion entries and three linked issues.

  • Receipt-backed static audits passed: 14 Go files, 48 SQL/result statements, independent three-valued oracles and relevant source-identity checks.

  • Reused frozen-head CI: 12 successful, 13 skipped and 2 neutral checks, plus scoped author and prior review evidence.

Limitations:

  • No fresh local Go/race/SQL execution or benchmark; raw author runtime logs were unavailable.

  • V7's adaptive admission and accounting remain unimplemented. Benchmark numbers above are the supplied earlier v4 measurements.

@matrix-meow matrix-meow added size/XXL Denotes a PR that changes 2000+ lines and removed size/XL Denotes a PR that changes [1000, 1999] lines labels Nov 10, 2026
@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 188fc72c4402c17da6afef243603076aa6441a6f

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: 188fc72c4402c17da6afef243603076aa6441a6f

Assessment: approve

The implementation follows accepted v7: bounded shared indexing reuses JoinMap ownership and the evaluator, admits construction after earned work, and accounts native bytes once. Prior blockers are resolved; no actionable findings remain.

Model: gpt-6.1-sol / max

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

Validation:

  • Eight owning/reverse-consumer packages passed: 807 test/subtest passes (owners-normal.stdout.jsonl; checks/1794333125961162831-3.json).

  • Focused race checks passed 100 repetitions: 36 parent tests and 9,400 test/subtest passes (focused-race.stdout.jsonl; checks/1794333167422490876-3.json).

  • All 48 SQL statements passed twice with independent result oracles and teardown. Both EXPLAIN ANALYZE plans report 40 bytes per MARK node (public-probe.stdout.jsonl; checks/1794333268530869080-3.json).

  • Formatting, truth oracles and go vet passed. Frozen-head UT, SCA, coverage and both BVT lanes succeeded. validation-audit.json reconciles receipts, logs, native provenance, unchanged source and all 15 discussion keys.

Limitations:

  • Large-workload timings are author-reported and were not independently remeasured.

  • Local SQL validation used one embedded CN and the MySQL protocol. Normal mo-tester and multi-CN results were reused from supplied author/CI evidence.

This branch was previously deployed

1 inactive deployment
ci — 188fc72c Deployed Nov 10, 2026 by ck89119
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 kind/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants