Repository navigation
perf(vector): skip empty marker lookups in UnionOne - #29664
LeftHandCold merged 1 commit into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
LeftHandCold
left a comment
There was a problem hiding this comment.
Reviewed head 0adb714cd766fc14e320ba3a20e9fe313ed04e74 against base 281ca809d688f7ff727e813a48436aff1cfbea36. No blocking findings; recommendation: Approve.
The production change is limited to two marker-lookup guards in UnionOne; the append/copy path is unchanged.
- For owned bitmaps,
Nulls.Containsalready checks the underlying empty flag. For borrowed Arrow validity, installation requires a positive NULL count, windows preserve/recompute it, and the Arrow input boundary validates the actual bitmap. Consequently a legal borrowed source containing NULLs cannot be classified as empty by the new guard. - Const/null/grouping behavior, existing destination prefixes, prepared/string/binary metadata, reset/reuse, and allocation/bitmap admission remain intact. Both marker decisions are still taken before append mutates either vector, including alias cases. The real
mergeutilper-row consumer retains its original source lifetime and error handling. - All three changed files were checked. New tests independently verify selected row bytes across fixed widths, NULL/grouping and constant controls, metadata after reset, borrowed validity without materializing the source, exact lease release counts, and allocation failure preserving the destination prefix before a successful retry. They use small fixtures and no new cluster or timing threshold.
Unhappy-path closure:
| Dimension | Result |
|---|---|
| Q1 ownership | No new owner or transfer; vector/lease cleanup is unchanged, with immediate test cleanup and release/mpool oracles. |
| Q2 termination | No new lock, callback, goroutine, retry, or blocking edge. |
| Q3 boundedness | No new allocation, retained state, or scan in the production guard; test allocation-failure fixture is bounded. |
Validation: git diff --check passed. Exact-head CI completed successfully: Linux/x86 UT (short/race), coverage (including vector and mergeutil), Linux/arm64 SCA, multi-CN pessimistic BVT, proxy BVT, and the required gate. CI logs verify Go 1.27.0 and the exact checkout. I did not rerun heavyweight tests.
The local normal-mode vector/mergeutil, vet/lint, and eight paired benchmarks are author-reported; their raw local artifacts were not independently located. The reported ~15% ordinary-copy gain is a component result, not an end-to-end SQL claim or closure of the broader #29571 regression. No concrete correctness, ownership, or normal-business regression was found in this scoped change.
Submitted as COMMENT because the authenticated account is the PR author and GitHub disallows formal self-approval.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of 0adb714cd766fc14e320ba3a20e9fe313ed04e74 against 281ca809d688f7ff727e813a48436aff1cfbea36: APPROVE; no blocking findings.
Design and correctness
The final scope is appropriately narrow: two read-only empty-marker guards in UnionOne, with no new cache, state machine, copy implementation, serialization format, or ownership protocol. Reusing Nulls.EmptyByFlag is preferable to introducing a second representation of marker state.
I checked the key equivalence rather than relying only on green tests. For owned bitmaps, the existing Nulls.Contains already gates its lookup on np.EmptyByFlag. For borrowed validity, successful InstallBorrowedValidity requires a positive null count; retained windows with no NULLs remain empty, and materialization rebuilds the bitmap before releasing validity. Consequently the new guard does not skip a reachable NULL. Contains is read-only, so skipping it loses no required side effect. Constant-NULL handling remains before the flat-vector NULL lookup. Reset, bitmap read/unmarshal, grouping propagation, metadata preflight, allocation admission and the remaining append path are unchanged.
QA, engineering quality and unhappy paths
Reviewed all three changed files: production +4/-2 lines, tests +197, no documentation increment. The small table-driven cases cover selected fixed-width bytes, empty/nonempty NULL and grouping sets, existing destination prefixes, constant behavior, reuse and later metadata divergence. Borrowed validity has an independent value/NULL oracle, no-materialization assertion and exactly-once lease checks. The bounded-mpool case checks failed growth preserves the prefix and a subsequent retry succeeds. These tests use small deterministic fixtures without sleeps or a timing threshold.
I also traced the existing varlen/constant/window/marshal tests and the real MergeSortBatches per-row consumer; the PR does not replace or bypass those paths.
| Unhappy-path dimension | Result |
|---|---|
| Ownership/cleanup | Existing destination allocation owner and source leases retained; new tests install cleanup immediately and verify final allocation balance / release counts. |
| Wait termination | No new wait, goroutine or synchronization edge. |
| Growth/boundedness | No new retained state or allocation path; existing growth/admission remains authoritative. |
Evidence and limits
- Verified CI run 37595214593 is for this exact head. Its UT checkpoint selects
pkg/container/vector,pkg/container/nullsandpkg/objectio/mergeutilwith-race -short -tags matrixone_test, without a test-name filter, and records the light-test stage finishing with status 0. The relevant new tests have no short-mode skip. SCA and the proxy/pessimistic BVT jobs also passed. - Local
git diff --checkpassed. My attempted focused local race run did not start: the isolated worktree lacks a matchinglibmo.dylib, and the repository wrapper correctly rejected primary-worktree artifact reuse. I reused the verified exact-head CI evidence; this is not a claim of a separate local pass. - The PR reports eight alternating matched performance pairs: ordinary BIGINT copy 143.416us -> 121.668us, unchanged zero allocations, with NULL/grouping/prepared/varlen controls improving and repaired marshal neutral. Those are author-supplied measurements, not an independently reproduced benchmark in this review. The change adds only O(1) flag guards; no new growth or synchronization cost is introduced.
The final history recheck found the author's newly submitted COMMENT review, which reports no blockers and explicitly distinguishes author-reported benchmarks from CI evidence; I read it and found no outstanding requested change. There are no inline review threads. Approval is for this bounded lookup optimization, not a declaration that the broader SQL/end-to-end regression in #29571 is resolved; that issue should remain open pending its own evidence.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
#29669) Main BigData still spends extra time generating hidden primary keys and appending ordinary CSV values. Reduce those costs at their existing owners. The investigation uses the complete 22-case/340-statement [Main run](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/37489307309) and [4.2 attempt 2](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/37334858166). - **Hidden primary-key allocation:** #29527 bounds speculative reservations to protect visible AUTO_INCREMENT from huge planner estimates. Bulk fake-PK generation consequently makes frequent allocator requests; private COPY executes allocator metadata SQL repeatedly in its growing transaction workspace. Prefetch now follows successfully assigned actual rows, saturating at 1M, while the initial reservation remains 10k. Qualification requires authoritative hidden fake-PK ownership, default service policy, unit step and default session series. Explicit service/table policies and visible user columns retain their policy. Cold/reset owners obtain the qualification in the existing catalog snapshot. - **Ordinary append:** skip empty metadata preparation/publication only when the existing scalar, sidecar and preflight state proves the operations have no effect. Keep physical data/bitmap admission, borrowed ownership, JSON checks, metadata transitions and failure rollback. - **Spill regression coverage:** retain the codec implementation already merged in #29646 unchanged. Consolidate one `BenchmarkSelectedRowsVarlenaDecode` with inline/nullable/64B long values, 23/24B boundaries, VECF32/VECF64, account peak and reusable destinations. Preserve all upstream codec tests and the four distinct PR boundary/capacity/invalid-length/borrowed-owner cases. The real MergeGroup consumer still checks spill/reload, exact DISTINCT values and resource release; its fixed test ledger makes forced spill independent of host pressure. The allocator change directly applies to no-PK writes and DROP-PK COPY that generate fake keys. ADD-PK COPY is a safety control here; its complete performance difference has additional contributors. Existing #26706 locking, #29664 and all main changes are preserved. No regression-runner or BigData coverage changes are included. ### Review integration and fresh component comparison [Review 5444104534](#29669 (review)) is addressed by merging current main and removing this PR's duplicate production decoder rewrite. Both conflicting codec files are reconciled; there is one decoder and one benchmark. The former 72%–74% decoder improvement belongs to the now-merged #29646 and is **not** incremental evidence for this PR. Fresh baseline: `3d796acf87081d48cb01449dce2a34d366534b24`, including #29646 and #29663. Delivery also integrates `ea011906d61dfe2b023993dbbbe2e778459776f8` (#29662); that subsequent frontend catalog lookup change is outside the measured vector/allocator dependency paths. Both benchmark binaries use the exact same fixtures; allocator qualification goes through production `GetAutoColumnFromDef` with a hidden column in both versions. The baseline overlay restores all six remaining production files to the named main revision and excludes only the new private-field UT when compiling the baseline. Vector measurements use Go1.27.0, Linux/amd64, GOAMD64=v3, GOEXPERIMENT=simd, the same provenance-checked native build, CPU6, GOMAXPROCS=1 and four alternating pairs at 300ms per workload. | Workload | Fresh result versus main | | --- | --- | | 1M actual generated IDs in batches of 8192, private-mode and committed caches | 101 → 8 range requests; 1,010,000 → 1,052,192 reserved values, initial reservation 10k | | 8192 ordinary BIGINT appends | 34.16% lower component latency; zero allocations retained | | 8192 ordinary inline / area VARCHAR appends | 15.12% / 17.75% lower component latency; zero allocations retained | | 8192 NULL BIGINT / VARCHAR appends | 12.56% / 9.92% lower component latency; allocation counts unchanged | | Prepared / literal / binary-prefix append controls | 0.84% lower / 4.56% higher / 1.01% lower component latency | | Consolidated main codec control | All 18 shape/size cells pass; 3 heap allocations per reusable decode; no additional decoder speedup claimed | The literal-prefix cost is an accepted guard overhead outside the ordinary CSV path. The allocator probe uses an in-memory store: its request/reservation counts are evidence, its timing does not reproduce SQL workspace cost. The historical estimate-prefetch control still reserves 2,000,010,000 values in 3 requests; that policy is not restored. These are component measurements, not a completed billion-row or 8-hour acceptance run. ### Validation after integration - Complete owning/consumer packages pass: vector, incrservice, group and mergeutil (669 top-level tests, all passed). The later frontend-only main commit leaves their tested source/dependency paths unchanged. - Complete vector/incrservice/group packages pass under race on integrated head `6537884aa4c5b936863f289fe20af43ce91d85f4`. - Real authenticated two-CN `TestBigDataBulkWriteAndPrimaryKeyCopyPreserveRows` passes in 9.00s: 32,768 rows, cold catalog lookup, ADD/DROP PK COPY, exact values/NULLs/vector payloads, duplicate COPY rejection with continued writes, and visible fake-PK-name user control. - Existing `TestIssue29602IndexBackfillLocksStayScopedToPrivateTargets` passes in 0.28s, preserving #26706 cross-CN row locks, uniqueness rejection, rollback and release. - Bulk-demand tests cover 2M IDs in private and committed CREATE owners, explicit config/table/session/step opt-outs, failure, terminal uint64, cold rebuild and cross-CN uniqueness. Existing estimate-gap protections remain and pass. - Real accounted MergeGroup VECF32/F64 spill/reload checks exact DISTINCT values, NULL and terminal memory/disk/FD release. All upstream codec UTs plus PR boundary, exact-capacity/one-byte-short, borrowed-owner and failed-decode reuse checks pass. - Fresh paired append measurements, both allocator count probes and all 18 consolidated codec benchmark cells reach PASS. Three independent focused source reviews have no remaining blocker. - `vet=all` for the five affected/consumer packages passes. Repository-config incremental golangci-lint v2.14.0 (Go1.27) reports zero issues; gofmt and final diff checks pass. The original-head CI was green before main integration. Its result is historical evidence; the updated head requires its new CI checks before merge. Commands, with the repository native prerequisites built: ```sh GOAMD64=v3 GOEXPERIMENT=simd .agents/skills/mo-dev/scripts/mo-cgo-test \ -count=1 -timeout=180s ./pkg/container/vector ./pkg/incrservice \ ./pkg/sql/colexec/group ./pkg/objectio/mergeutil GOAMD64=v3 GOEXPERIMENT=simd .agents/skills/mo-dev/scripts/mo-cgo-test \ -race -count=1 -timeout=180s ./pkg/container/vector ./pkg/incrservice ./pkg/sql/colexec/group GOAMD64=v3 GOEXPERIMENT=simd .agents/skills/mo-dev/scripts/mo-cgo-test \ -count=1 -timeout=300s \ -run '^(TestBigDataBulkWriteAndPrimaryKeyCopyPreserveRows|TestIssue29602IndexBackfillLocksStayScopedToPrivateTargets)$' \ ./pkg/tests/issues GOAMD64=v3 GOEXPERIMENT=simd .agents/skills/mo-dev/scripts/mo-cgo-test \ -run '^$' -bench '^BenchmarkAutoIDCacheBulkAllocationRequests$' -benchtime=1x ./pkg/incrservice ``` ### Limits and follow-up acceptance Successful assignment demand is not committed-row count; later SQL/transaction failure need not undo it. The adaptive asynchronous span is bounded; synchronous real-batch/concurrency demand retains its existing policy. Qualification adds one catalog aggregate to cold GetColumns, including visible-user tables, rather than each allocation. Frozen BigData YAML and the inspected operator configuration pipeline contain no explicit cache count; the installed Pod TOML was not retrieved. Verify actual activation and remaining critical-path time in the next complete BigData run before claiming end-to-end recovery. Approved by: @XuPeng-SH
…ement (#29666) ## Summary This is a small follow-up to the shared broadcast producer ownership work. When several independent broadcast probe scopes share one CN, a HashBuild/map and its build source must be owned by their common result region, not by the first consumer. That consumer may end normally without calling its child while a peer still needs the shared build. Reuse the existing producer-region protocol for repeated-CN HashJoin/LoopJoin probe groups. Keep single/packed scopes, unique-CN non-Product scopes, IndexJoin, ProductL2, DedupJoin and RightDedupJoin unchanged. Do not change JOIN semantics, probe placement, result receiver order, scan count, cancellation normalization, or add global serialization. Existing Product ownership remains unchanged; the already computed groups are reused rather than calculated twice. The extension is deliberately limited to HashJoin/LoopJoin. Other HashBuild operators also have related structure, but their repeated-CN lifecycle has not been reproduced and is not changed by this PR. HashJoin's JOIN-type variants use the same ownership protocol; their algorithms are unchanged. The new runtime RED/GREEN is specifically equi INNER HashJoin and non-equi INNER LoopJoin, **not a claim that every operator/type was reproduced in this topology**. Existing owning-package tests validate the unchanged operator/compiler contracts separately. The existing producer-region helper runs Dispatch at the coordinator. An eligible remote build source may therefore acquire one additional coordinator Merge relay. Scan count and probe placement are preserved, but this PR does **not** claim that every source/network placement is identical or that public SQL performance in this remote-source domain has been A/B validated. ## Deterministic contract evidence The regression fixture uses real compiler probe/build assembly, finalized producer ownership, pipeline context initialization and MergeRun. Two independent colocated HashJoin/LoopJoin probes consume the same build. A real outer broadcast INNER join with an empty map normally skips one consumer, while the peer still requires three build rows. The first consumer's cause is asserted to be ErrPipelineStopped, and the query parent remains live. On the untouched base, normal consumer cleanup cancels the still-required shared source. With the fix, the peer returns the exact expected result. Additional cases cover first/last skipped consumers, empty peer, all consumers skipped, empty build, original build error, partial output then panic, query cancel/deadline, ancestor normal stop, and normal/cancelled execution followed by Scope.Reset with a fresh allocation-account/pipeline generation. The reuse test retains internal operator templates; it does not assert that AP prepared SQL is supported. Every scenario joins workers and drains board/spool ownership before asserting allocation-account usage is zero. A structural regression explicitly excludes IndexJoin and checks final worker reference counts, including downstream DOP changes and existing remote groups. Existing Product remote retirement and independent result-root contracts remain enabled. ## Important scope boundary This proves a supported **internal compiler/runtime scope ownership contract**. It does not prove an actual SQL planner currently creates the asymmetric probe placement in this fixture. It does not establish the first cancellation owner or the root cause of Nightly Run 37484909730's information_schema metadata JOIN failure. Natural three-CN and DOP=2 incident probes passed without reaching the repeated-CN independent-probe domain. Do not interpret this PR as fully fixing or closing that incident/Issue #29642. PR #29643 is the already-deployed Product ownership fix; it is not the original incident's Issue number. ## Validation Go 1.27.0; exact-base verified CGo artifacts; CPU 0/1, GOMAXPROCS=2 and 4GiB Go memory budget. No production cluster or foreign service was touched. These were run from the MatrixOne worktree with verified native prerequisites. The commands below are directly executable with the same Go/native setup: ```sh GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \ .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -count=1 -timeout=180s ./pkg/sql/compile GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \ .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race -count=1 -timeout=180s ./pkg/sql/compile GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \ .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race \ -run '^TestBroadcastHashJoinSharedProducerOwnership$' -count=2 -timeout=120s ./pkg/sql/compile GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \ .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race \ -run '^TestBroadcastLoopJoinSharedProducerOwnership$' -count=2 -timeout=120s ./pkg/sql/compile ``` Final narrowed production guard: normal compile package **PASS 7.224s**; full compile package under `-race` **PASS 9.606s**; exact HashJoin/LoopJoin two repetitions **PASS 3.211s / 3.195s**. Before the guard was narrowed to these same Hash/Loop paths, each exact test was also adaptively stressed 29 times under race (1.02s measured test, 30s budget): **PASS 30.887s / 31.333s**. Related runtime package checks were also run: ```sh GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB \ .agents/skills/mo-dev/scripts/mo-cgo-test -p=2 -race -count=1 -timeout=180s \ ./pkg/sql/colexec/hashbuild ./pkg/sql/colexec/hashjoin ./pkg/sql/colexec/loopjoin \ ./pkg/sql/colexec/dispatch ./pkg/vm/message ./pkg/vm/pipeline ./pkg/vm/process ``` All seven packages **PASS** (1.973s, 11.624s, 1.676s, 1.316s, 1.219s, 1.188s and 2.262s respectively). This is supporting dependency evidence, not a public remote-source performance test. Official Main linter **v2.14.0, built with Go1.27.0** was run with matching Go1.27 PATH/GOROOT and repository CGo include/library paths: ```sh GOTOOLCHAIN=go1.27.0 GOMAXPROCS=2 GOMEMLIMIT=4GiB GOWORK=off \ CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" \ CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib" \ golangci-lint run --concurrency=2 --timeout=5m -c .golangci.yml ./pkg/sql/compile git diff --check ``` Final narrowed version: linter **PASS, exit 0, 0 issues**; `git diff --check` **PASS**. No older Go1.21 or golangci v2.6 tooling was used as a final gate. Detailed terminal evidence is retained locally. Root additionally combined this patch with the independent minimal vector and catalogue patches (#29664 and #29662) in a temporary exact-base worktree. Full vector/mergeutil/compile/frontend package tests passed; the authenticated two-CN `TestIssue29414PublicationWaitsForPhysicalDatabaseDrop` public SQL consumer passed rollback, commit, replacement and cancellation (9.660s). This checks composition and ordinary public SQL behavior; it is **not** a natural reproduction or a performance A/B of the special repeated-CN domain. --------- Co-authored-by: XuPeng-SH <[email protected]>
Summary
Related to #29571. Avoid redundant per-row NULL/grouping lookups in UnionOne
when the source marker set is empty. The check uses the existing EmptyByFlag,
which also accounts for borrowed Arrow validity; nonempty sets keep Contains.
All existing allocation, bitmap, owner, constant and metadata behavior remains.
No state cache, copy specialization, wire format or SQL behavior changes.
Validation
borrowed validity/lease and allocation-error tests pass with mpool zero.
ordinary BIGINT copy 143.416us -> 121.668us (-15.16%), unchanged zero alloc.
(golangci-lint v2.14.0/Go1.27, vector plus mergeutil closure, 0 issues).
The larger initial append fast-path prototype was discarded because it hurt
NULL/grouping/varlen controls. This PR contains only the smaller lookup change.
Component gains are not claimed as SQL/end-to-end resolution of the entire
Issue, and this PR should not automatically close #29571.
Local functional commands (matching native prerequisites built first):
GOAMD64=v3 GOEXPERIMENT=simd .agents/skills/mo-dev/scripts/mo-cgo-test \ -v -count=1 -timeout=120s ./pkg/container/vector ./pkg/objectio/mergeutil GOAMD64=v3 GOEXPERIMENT=simd .agents/skills/mo-dev/scripts/mo-cgo-test \ -vet=all -run='^$' ./pkg/container/vectorThe performance gate uses the 8192-row ordinary-copy workload from #29571
plus prepared/NULL/grouping/varlen/marshal controls. Same base/candidate
toolchain and native artifacts, CPU6, GOMAXPROCS=1, eight alternating pairs;
the row/metadata/marker/reset/allocation-balance oracles run in each measured
process. Ordinary paired improvements range 14.39%–16.08%. No fixed wall-time
threshold was added to CI.