Skip to content

perf: bound regular-index backfill work - #32039

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:perf/32015-index-backfill
Nov 3, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:perf/32015-index-backfill

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 2, 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 #32015

What this PR does / why we need it:

A noncovering secondary-index query on a table without an explicit primary key can spend almost all CPU comparing every base key against every candidate key. On a flushed 1M-row table with 1,000 matches, the automatic index plan took about 201 ms while the same SQL with IGNORE INDEX took about 2 ms. Broad real-PK lookups also paid substantial per-reader candidate preparation cost that automatic admission did not account for.

  • Search normalized exact IN operands by binary search on unordered block rows, replacing O(rows × keys) work with O(rows × log keys). Preserve type comparators, row multiplicity, unsorted fake-PK behavior, and the legacy internal array fallback.
  • Stream canonical workspace key encoding through the existing packer without allocating owned bytes for each probed row. Retained-key callers still receive owned payloads, with constant expansion and packer-reuse behavior preserved. Keep sorted candidates for replay/range pruning, and build an exact membership map only when an IN leaf is actually probed. A pointer-owned sync.Once safely publishes the complete map across concurrent readers; SetFullData replaces its generation. Reader reset releases the filter, and batch-scoped defers return pooled packers/bitmaps on panic.
  • Price candidate preparation and unordered PK probing in automatic backfill admission. Keep candidate ranking, prepared-bound uncertainty, and sorted-key locality distinct: a possible scattered layout must not reject a useful clustered lookup. The encoding CPU weight is a calibrated estimate.

Previously validated local warm-cache SQL results (unchanged block-search and planner paths):

Representative results (2 CNs, 1M rows, matching SQL/results, nine interleaved samples per decision workload):

Workload Baseline AUTO This PR AUTO This PR IGNORE INDEX
No explicit PK, 1,000 matches 201.4 ms 1.14 ms 1.41 ms
Real PK, 100,000 matches, DOP 4 47.2 ms 2.26 ms 2.17 ms

The DOP-1 broad lookup also selects scan (4.58 ms vs 4.74 ms with IGNORE INDEX). A clustered wide-column control retains the beneficial index plan (0.92 ms vs 2.12 ms scan). Forced no-PK backfill drops from about 193 ms to 5.92 ms, independently confirming the execution improvement. Encoder calibration at 100k integer keys reduces allocated bytes/key from about 162 to 56 after descriptor preallocation. These are local warm-cache measurements; locality, statistics and hardware still affect plan quality.

Final workspace component measurement, including candidate encoding and filter construction (1,000 integer candidates, 8,192 rows/batch, three 300 ms repetitions): baseline to final medians are 68.5 to 34.3 μs for construction, 448.6 to 275.1 μs for one batch, and 6.17 to 3.52 ms for 16 repeated batches. Sixteen-batch allocated bytes fall from 12.63 MB to 0.116 MB. These are component measurements, not transactional SQL latency claims. Additional narrow/128-byte key checks cover K=8/1,000/100,000 and N=1/8,192. Lazy maps retain the original hash implementation's candidate-memory cost after initialization: 100,000 wide keys across eight filters retain about 278 MB of Go heap in both versions (GC heap delta, not RSS). Candidate/reader fan-out still matters. The O(K) first-use map build runs under the existing workspace transaction lock and is not interruptible; no universal cancellation-latency or optimal-plan claim is made.

Validation (Go 1.27.1, -short, matrixone_test): full normal tests for readutil, plan, blockio, disttae, compile, cdc, iscp and logtailreplay; public TestIntegerIndexAccess covers both PK layouts, persisted/workspace data, prepared reuse, duplicate rows and rollback. Affected nine-package vet, pinned molint and configured incremental golangci pass. All eight owning packages and the public SQL regression also pass under -race. The workspace amendment additionally passes six affected owning packages normally and under race, public transaction SQL normally/under race, final encoder boundary regression normal/race, and affected nine-package incremental SCA with a final readutil delta check. Concurrent IN first use/replacement, fixed/variable constant ownership and shortened-constant failure contracts are covered. Remote CI is separate from these local checks.

Design. Design and independent final overall review use gpt-6.1-terra/max. The workspace amendment was designed before implementation and reconciles the entire PR with the preserved block/planner evidence.

CI regression coverage: unhinted broad-range EXPLAIN cases assert the cost-based scan choice, while selective unhinted OR ranges and a small clustered fake-PK range assert automatic non-covering index selection and full query results. Separate FORCE INDEX controls retain broad-range index-plan coverage. The clustered positive exercises small-table access-shape policy; it does not establish large-table cost admission or a performance win. The sequence retry late-join test uses virtual time while retaining exact deadline, probe, lock and terminal assertions. Both affected BVT scripts passed twice on the CI merge build (201/201 combined per run: 75/75 and 126/126); the compile package passed normally and under race, including 100 race repetitions of the late-join case.

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

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: 3b514b40aea03c6ccaf5f7f52facf4807edaf2ad

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 7e99ea5afa1739611588372c3582e5ddd33f651f

Review completed. Read the assessment.

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Nov 2, 2026

@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: 7e99ea5afa1739611588372c3582e5ddd33f651f

Assessment: approve

Exact IN matching, packed-key ownership, reader cleanup and planner admission controls are preserved. The documented performance tradeoffs are acceptable; no actionable unresolved findings remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Executor preflight and native build passed; 193 native input files matched the frozen head.

  • Normal short-mode readutil and planner suites passed. Focused CDC/ISCP ownership tests and public TestIntegerIndexAccess passed.

  • Three interleaved workspace benchmark rounds confirmed lower construction time and allocations, with slower probing in the 1,000-key workspace cases.

  • Verified source unchanged, patch consistency, all three discussion keys, command receipts and retained logs. Evidence is recorded in review-plan.md, discussion-assessment.json and validation-summary.json under the assigned diagnostic directory.

Limitations:

  • Two unrelated planner subtests were skipped.

  • Author-reported race and two-CN performance checks were not independently rerun; relevant CI was pending in the supplied evidence.

  • Workspace component probes with 1,000 keys were 31–44% slower when scanning batches, while construction was about twice as fast. This is an accepted memory-saving tradeoff, not an end-to-end SQL latency measurement.

@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 2dc705f6f342405fbb4ff4bc554cd35af003f972

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: 2dc705f6f342405fbb4ff4bc554cd35af003f972

Assessment: approve

Complete review found no actionable defects. The added BVT coverage checks broad AUTO scans, selective AUTO backfills and small-table behavior while retaining FORCE controls. Production code and previously validated Go tests are unchanged.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Reviewed all 17 changed files, the design, linked issue and seven discussion entries.

  • Receipt-backed source audit verified the four-file additive BVT delta, preserved earlier statements, formatting and unchanged source.

  • Independently verified all 134 new expected rows and metadata, plus AUTO/FORCE plan expectations. Evidence: source-bvt-audit.json and validation-summary.json.

  • Reused source-matched coverage from the two supplied prior reviews. The author reports two updated BVT passes, 201/201 each.

  • Saved review-plan.md and discussion-assessment.json; final receipt and discussion-coverage audit passed.

Limitations:

  • No Go or SQL tests were rerun locally. Prior execution coverage and updated BVT results were reused from supplied reports; raw execution logs are absent.

  • Relevant CI remained pending in frozen evidence.

  • The previously accepted workspace tradeoff remains: slower 1,000-key probing in exchange for faster construction and lower allocation.

@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: d94103eca7ebcd41956ccf0679234b599d036d53

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

Assessment: approve

No actionable unresolved findings. Exact membership, retained-key ownership, concurrent lookup initialization, workspace cleanup and planner controls are preserved.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Reviewed all 18 changed files, affected consumers, design, linked issue and all ten discussion entries.

  • Isolation preflight and native build passed; 193 native input files matched the frozen head.

  • Full readutil suite passed normally and under race detection: 131 top-level tests, no skips. Concurrent first-use test passed 100 additional race repetitions.

  • CDC/ISCP retained-key ownership tests and public TestIntegerIndexAccess passed normally and under race detection.

  • Verified 134 added BVT expected rows, formatting, patch consistency and unchanged source.

  • Receipts and retained logs reconciled in validation-audit.json; review-plan.md and discussion-assessment.json completed.

Limitations:

  • Relevant CI remained pending in the frozen evidence.

  • Distributed BVT and two-CN performance checks were not independently rerun. Matching prior-review and author reports were reused; their raw execution logs were unavailable.

@XuPeng-SH
XuPeng-SH merged commit dd2499c into matrixorigin:main Nov 3, 2026
cpegeric added a commit to cpegeric/matrixone that referenced this pull request Nov 3, 2026
…#32039

visitEncodedPrimaryKeyVector took over the switch from
EncodePrimaryKeyVector, so its baseline key no longer matched. Low-precision
floats and VECTOR columns are rejected as primary key columns at DDL; tag the
switch and drop the stale baseline entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

No deployments
ci — 77c068f3 Deployed Nov 3, 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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: index join-back never yields to full scan, 200x slower at 10% selectivity

3 participants