Skip to content

Fix point-update secondary index maintenance scans - #32243

Merged
XuPeng-SH merged 3 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/32221-42-index-maintenance
Nov 5, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/32221-42-index-maintenance

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement

Which issue(s) this PR fixes:

Fixes #32221

What this PR does / why we need it:

A point update of an indexed column can scan the full secondary-index table when default or stale statistics cause the runtime-filter cost heuristic to reject the maintenance join. With two maintained indexes, each scan can read all 50,000 rows even though the base primary-key lookup returns one row.

When an otherwise rejected broadcast INNER join has an ordered full-PK probe and its build is provably at most one row, admit the existing exact runtime filter without changing statistics or join placement. The proof supports a conservative chain of unique-key joins so multiple regular indexes can be maintained selectively. It verifies source index ownership and the full untruncated integer primary key, worker-invariant join expressions, and matching filter dependencies; unsupported shapes retain existing costing. The execution path, memory accounting, and PASS/error behavior remain owned by the existing runtime-filter implementation.

Historical feature validation on Go 1.26.4 with GOEXPERIMENT=simd and GOAMD64=v3, before the CI repair follow-up:

The live service experiments used the preceding candidate build. The final commit relaxes only a cross-table schema-version comparison; both scan references in those experiments use version zero, so their execution behavior is unchanged. The original feature validation below predates the CI repair follow-up.

  • Full pkg/sql/plan tests and race tests; focused HashBuild optional-budget, cleanup, and reset race tests; focused compile broadcast/runtime-filter topology race tests.
  • SQL BVT on a two-index table: 29/29, including prepared reuse, NULL, rollback, primary-key change, and forced-index readback. A prepared UPDATE was also reused successfully after dropping and recreating an index.
  • Two-CN forced AP: both index scans read one row; checked commit/rollback, 20 concurrent updates to the same row from both CNs, direct hidden-index entry counts during repeated changes, cancellation, invalid prepared parameter, NULL, and missing key.
  • Local 50,000-row two-index reproduction, 5 warmups and 20 measured transactions: point-update median 15.47 ms → 1.22 ms, with each index scan 50,000 → 1 input row; 1,000-row range median 19.66 ms → 19.70 ms. Separate sequential service runs include client and transaction overhead. In the forced two-CN AP setup, point median was 91.14 ms → 91.56 ms despite the scan reduction, so no AP latency improvement is claimed.
  • Incremental gofmt, go vet, and repository-pinned golangci-lint pass for the changed packages. The repository's custom molint also reports three existing findings in untouched expr_opt.go and returning.go.

The proof deliberately falls back for unrecognized index metadata, unsupported predicates/types, partitioned sources, and other unproven join shapes. CI for the updated branch is pending.

CI reliability follow-up

The failed Ubuntu race job exposed a shutdown wait: the transaction trace watcher could enter a synchronous statistics lookup that did not wake when its caller was canceled. It also exposed timing-sensitive CDC and file-service tests. The arm64 static-analysis runner was OOM-killed at its 8 GiB limit while using the legacy full-check path.

  • Backport cancellation-aware statistics waiting and forced-queue admission, and propagate the trace worker's stop context through its queries, writes, queue handoff, and retry wait. Trace data during shutdown remains best effort.
  • Replace timing-sensitive test assertions with controlled progress and cleanup. The file-service range test verifies the actual configured wait bound with virtual time.
  • Backport runtime-scoped, idempotent auto-increment service setup from fix: eliminate CI test lifecycle leaks and metric flakiness #27480 and reuse each mock planner context's process. This prevents repeated test fixture creation from orphaning background workers; clean up fixture pools and restore overridden test services.
  • Enable the existing split static-analysis workflow on 4.2 and limit its Go and lint concurrency while retaining the full legacy target and license checks. This is an OOM mitigation; the arm64 runner still needs to validate it.

CI repair validation

  • pkg/cdc, pkg/fileservice, pkg/txn/trace, and pkg/vm/engine/disttae: full package race tests; 13 named concurrency tests each repeated 100 times under race.
  • pkg/embed.TestBasicCluster: race test using -short -tags matrixone_test.
  • pkg/sql/plan: the full package now passes in a single -short -race -tags matrixone_test process (5.00 s). A previous full run before the fixture fix was OOM-killed at a 10 GiB cgroup limit; after the fix, a complete run peaked at 1,148,952,576 bytes (about 1.07 GiB). These are not two completed-run benchmarks.
  • pkg/testutil, pkg/sql/plan/tools, pkg/sql/colexec/hashbuild, and pkg/sql/compile: full package race tests. Selected service-ownership, planner-context, and runtime-filter tests each passed 100 repetitions under race.
  • Incremental gofmt, go vet, pinned molint, and configured golangci-lint across 11 changed or directly affected packages; full license header and dependency checks. The local x86_64 check ran in an 8 GiB cgroup, peaking at 6,646,784,000 bytes (about 6.19 GiB) with no OOM events. After the final fixture cleanup, planner vet, molint, and golangci were rerun. molint reported ten existing unsafe-recover diagnostics in seven files unchanged from the merge base; it reported none in changed files.
  • On the preceding CI-repair snapshot, full x86_64 make static-check-analysis GOLANGCI_LINT_CONCURRENCY=1 with GOMEMLIMIT=3GiB exited 0; repository-configured golangci-lint reported 0 issues. The full molint run also emitted existing diagnostics in unchanged baseline files. The final planner-fixture follow-up was covered by the incremental checks above.
  • CN shutdown consumers: three focused race tests, including trace-producer shutdown, passed.

The updated head's arm64 SCA and complete CI remain to be verified.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner November 5, 2026 09:02
@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 5, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 1491babb9a0dbc3eab90dc87bed82fd1ee9f7648

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: 1491babb9a0dbc3eab90dc87bed82fd1ee9f7648

Assessment: approve

The bounded singleton proof supports selective maintenance of multiple indexes while reusing existing filter delivery, budgeting and cleanup. The reported scan reduction justifies the added proof logic; no actionable defects remain.

Model: gpt-6.1-sol / max

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

Validation:

  • Reviewed all six changed files, linked issue, discussion and affected planner/compiler/HashBuild consumers.

  • Local source and independent relational/SQL-oracle audit passed: source-audit.log and checks/1793871937421022604-2.json.

  • Reused author-reported planner/race, HashBuild/topology and live SQL/performance evidence after checking revision and semantic scope.

Limitations:

  • No local Go tests or SQL/BVT rerun; native prerequisites and raw author execution logs were not supplied.

  • Substantive current-head CI remains pending. Reported AP measurements show scan reduction without a latency improvement.

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Nov 5, 2026
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Nov 5, 2026
@XuPeng-SH

XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 8dd7c8d9ea9e9a55bb19c4d15546c5e33d84e4a9

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

Assessment: approve

The bounded singleton proof enables selective multi-index maintenance through existing runtime-filter delivery and budgeting, without changing statistics or placement. The shutdown, fixture-ownership and static-analysis repairs reuse existing owners and address observed blocking and memory costs. No actionable findings remain.

Model: gpt-6.1-sol / max

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

Validation:

  • Reviewed all 32 changed files, linked issue #32221, all four discussion entries and affected planner/compiler/HashBuild, shutdown and fixture consumers.

  • Qualified prior review 5782897144 by source identity: five feature files are unchanged; the sixth differs only in process-fixture cleanup. Subsequent repairs were reviewed independently.

  • Local preflight and source audit passed: pinned clean head, 27 Go files formatted, 29 SQL/result commands aligned, nine expected results checked with an independent SQLite relational oracle, preserved Makefile checks and complete discussion coverage. Logs and matching check-run receipts are retained.

  • Reused author-reported planner normal/race, HashBuild/topology, 29/29 SQL regression and two-CN prepared/index/concurrency/cancellation checks for unchanged feature code. Reported 50k-row point median improved from 15.47ms to 1.22ms with each index scan reduced to one row.

  • Reused author-reported owning-package race, named 100x stress, final planner race and incremental static checks for the repairs. Reported x86 static analysis stayed within an 8GiB limit; the preceding full-analysis run and final incremental checks were distinguished.

Limitations:

  • No fresh local Go, MatrixOne SQL, race or performance execution; author raw logs and native build inputs were not supplied. The local SQLite audit checks expected relational results only.

  • Frozen-head shared build, Ubuntu unit tests/coverage and Linux arm64 static analysis remain pending. Final arm64 memory behavior and external workflow license-step execution are unverified.

  • Reported AP runs demonstrate scan reduction without a latency improvement; the prior planner OOM is an incomplete run, not a completed before/after benchmark.

@iamlinjunhong iamlinjunhong 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 head 8dd7c8d9ea9e9a55bb19c4d15546c5e33d84e4a9 against 4.2-dev base ebf03dc42bf25ba00018da019783e1037299d1ae. No actionable findings; approve.

Reviewed all 32 changed files against the scope of issue 32221, including singleton proof and fallback, nested index ownership, runtime-filter delivery and memory-budget fallback, statistics cancellation, trace shutdown, test fixture ownership, and static-analysis changes. The shared CI workflow retains separate license checks when selecting the new analysis target.

According to the supplied exact-head review data, the 34 checks are 19 success, 13 skipped, and 2 neutral: they are not all successful, although none are failed or pending. The required CI gate, Ubuntu unit tests and coverage, arm64 static analysis, shared build, and both active BVT jobs succeeded. CI run.

Validation performed here: source and caller-path review, git diff --check, and the provided read-only PR artifact check; both checks passed. Local Go/race/SQL/performance execution was skipped because no remaining concrete uncertainty required a targeted reproduction and exact-head CI evidence was available. Author-reported local performance and stress results were not independently reproduced.

This is the first review by this reviewer. The supplied history contains no prior findings or inline threads requiring an author-response assessment.

@XuPeng-SH

XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 8dd7c8d9ea9e9a55bb19c4d15546c5e33d84e4a9

New discussion was assessed; the previous review remains unchanged.

@XuPeng-SH
XuPeng-SH merged commit f3c72c6 into matrixorigin:4.2-dev Nov 5, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/32221-42-index-maintenance branch November 5, 2026 23:03
XuPeng-SH added a commit that referenced this pull request Nov 10, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [x] Code Refactoring

## Which issue(s) this PR fixes:

Related to #30125. Backport of #32191.

## What this PR does / why we need it:

Bound HashBuild runtime-filter key collection to aligned chunks of at
most 8,192 rows, with earlier splits for component-vector byte limits.
This avoids growing one key vector across the entire build. The ordinary
path collects newly inserted hash groups; HashOnPK retains the existing
primary-key uniqueness assumption. Account for chunk metadata, roll back
failed multi-column appends, and reject invalid checkpoints without
publishing partial keys.

Keep the ordinary IN encoding and single-chunk fast path. Numeric runs
are copied and sorted in the final admitted buffer; other sorted runs
are merged without a whole-build vector. Inline runs whose key ranges
are already ordered can use the same admitted buffer and bulk-copy path.
Integrate the 4.2-dev composite-primary-key filter from #32400: convert
components in probe-key order for each chunk, use the converted vectors
for bounds and encoding, and turn an out-of-range optional filter into
whole-filter PASS. A cancellation already observed at that fallback
remains an error.

Publish membership keys as one immutable, reference-counted payload and
adapt the existing 4.2-dev IVF/fulltext consumers to visit all chunks.
IVF may use a complete exact SQL predicate or a tagged reader filter,
according to the existing key-type contract. Required non-integer IVF
membership retains the 8 MiB global literal-list limit and fails rather
than becoming partial or approximate. The release keeps its existing TVF
architecture and native filter ABI.

The rebase also adapts the #32243 optional-collection failure tests to
the chunked owner, preserving PASS, complete JoinMap, wide-key lookup,
and accounting checks. It retains the author's concurrent merge fixes
and fixture cleanup.

## Validation of the rebased production tree

- Normal and race suites for the 12 changed/affected CPU packages;
HashBuild, runtimefilter and the planner were rerun after the last
production change. The exact two-CN role-grant fixture was also run
under `-race -short`.
- Four focused lifecycle tests each passed 100 `-race` repetitions:
ordered-run cancellation and cleanup, composite narrowing, next-chunk
admission failure, and cross-chunk rollback. HashBuild also passed
`-short -covermode=set` (74.7% of that package's statements; this is not
changed-code coverage).
- An embedded SQL differential test verified an actual
`serial(cast(...), ...)` composite-PK runtime-filter plan with 9,000
build keys; enabled, disabled, out-of-range and NULL controls returned
the same 9,000 matches. The input exceeded one chunk, but the SQL
experiment did not instrument per-operator chunk count; white-box tests
explicitly construct and validate multiple chunks.
- The repository's IVF membership BVT ran twice in normal comparison
mode on one isolated CN after SQL and ISCP readiness: 44/44 statements
each time, zero ignored, with both test databases verified absent after
each run.
- Incremental `gofmt`, `molint`, and golangci-lint 2.6.2 passed over the
changed package closure. The additional planner scan reports three
`checkrecover` items at identical lines on the unmodified 4.2-dev
baseline. Tests used Go 1.26.6 and CPU native libraries; a rebuild from
the same tracked native sources produced an identical libmo
executable-code section.

## Performance and limits

In a local pinned-CPU microbenchmark comparing the rebased code
immediately before and after the ordered-inline optimization,
three-sample medians for ordered composite keys changed from 1.156/1.190
ms to 0.880/0.907 ms at 8,193 rows and from 10.341/10.101 ms to
7.537/7.755 ms at 65,536 rows (direct/cast respectively). Single-chunk
controls also varied 4–8%, so these are local measurements, not a
general speedup claim. Randomly interleaved 65,536-row cases changed by
+2.4%/+1.4% in another three-sample comparison. Chunking still increases
Go allocations: the 65,536-row cast fixture used about 111 allocations
on the 4.2-dev baseline and 359 here. Go allocation figures exclude
MPool/native memory.

CUDA, mixed-version rollout, multi-gigabyte workloads, peak MPool/native
memory and end-to-end OLAP performance were not independently validated
in this run. The author previously reported full-repository SCA and
additional 100-run ownership stress on the earlier PR revision; those
reports are historical evidence, not new-head CI results.

Design: [bounded HashBuild key collection and 4.2-dev
integration](https://github.com/aunjgr/matrixone/blob/91c9bbf26c012fab1cc8a4a4e7bb2f73373d7977/docs/design/hashbuild-key-batches.md).

---------

Co-authored-by: XuPeng-SH <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — 8dd7c8d9 Deployed Nov 5, 2026 by XuPeng-SH
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.

3 participants