Repository navigation
fix(sql): bound shared MARK membership on 4.1.6-hotfix - #32315
Conversation
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
left a comment
There was a problem hiding this comment.
基于 096a24944259c2d150e9e2399b86785a46a2550c 复审,结论为 Request changes。CI 失败没有作为结论依据。
当前生产实现仍有两项已复现且未关闭的问题:
- 小 probe / 早命中无条件构建整个 RHS 索引:同机 SQL 对照中,2M 重复 RHS、1 个 probe 的 NOT IN 中位数从 2.083 ms 增至 74.808 ms;256 个早命中 probe 的 IN 从 7.655 ms 增至 74.195 ms。
- 索引分配未计入算子内存统计:真实算子中 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 工作区。
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.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
|
This pull request is merged. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
What type of PR is this?
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
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.min(64 MiB, pool cap / 8)through cap-enforced MPool. Native calloc supplies zero initialization; no redundant consumer clear.Validation
Go 1.26.4, Darwin arm64, matching CGo artifacts, target
cbb7da471a495f21361fcfdc8fa715f6bdd346a0merged before final validation.-race -short -tags matrixone_test. Exact shared-consumer, cancellation, native-failure, admission, real transition/generation and batch-continuation selections pass race ×100.matrixone_test(2,167 packages). Previously documented Darwin molint unsafe diagnostics in unchanged allocator files are not claimed as zero findings.EXPLAIN ANALYZEof 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.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×Bprefix 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, run42344369146attempt 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.