Skip to content

perf: accelerate unordered primary-key IN filtering - #32082

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:perf/unordered-pk-backfill-32015
Nov 3, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:perf/unordered-pk-backfill-32015

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 3, 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:

Related to #32015. This improves execution; the automatic index-versus-scan selection issue remains open.

What this PR does / why we need it:

Unordered primary-key backfill may search a candidate list for every base-table row. For normalized integer-backed IN lists with 64–16,384 keys, use a bounded, lazily built and reusable membership set only when a physical vector has at least max(BlockMaxRows/2, ceil(candidateCount/2)) values. Before using that set, check the physical row order: a vector verified entirely ordered reuses the existing sorted search, while the first inversion uses the hash path. If every eligible vector is ordered, the map is never built. The sorted and unordered callbacks share the same immutable candidate search. Unnormalized integer lists and lists of at most four keys use exact linear search; other normalized integer lists outside the hash guard use binary search. Floats use linear or binary search according to candidate normalization and size. No SQL-specific rule, planner admission change, or cross-block order cache is introduced.

The shared vector factory also chooses equality versus custom-comparator search once instead of testing comparator mode on each comparison.

Validation:

  • Full pkg/vm/engine/readutil normal and race suites, a 100-repeat concurrent-publication race test, 15 integer/bit/time/enum dispatches, ordered/first/middle/last inversion, empty/no-hit and 64/65 boundaries, unnormalized input, and float controls passed. Focused blockio consumer tests passed normally and under race. Incremental vet and configured lint passed; the unchanged pkg/container/vector package passed normal/race and SCA earlier in this PR.
  • Exact f7f80a9 versus final-source ABBA: one local embedded CN, 1M rows, warm cache. AUTO/FORCE/IGNORE queries against fake-PK, real-PK and clustered tables returned complete (id, payload) rowsets matching an independent oracle; prepared execution, workspace inserts and rollback passed. For the point predicate, fake-PK AUTO medians across the two baseline runs were 2.950/2.935 ms versus 1.571/1.679 ms in the two final runs; real-PK AUTO was 1.668/1.754 versus 1.607/1.705 ms, and clustered AUTO 0.796/0.780 versus 0.779/0.790 ms. These are local measurements, not a speed guarantee.
  • A wide-IN real-PK FORCE query measured 17.72/17.80 ms versus 18.29/18.51 ms in that same four-run SQL comparison. A repeat ABBA pinned to CPUs 4–7 measured 19.662/19.863 versus 20.064/19.632 ms, so the earlier 3–4% median difference did not repeat consistently. Individual iterations overlapped widely. An independent sorted-search component ABBA with 100,000 keys and 8,192 rows measured 32.377 versus 32.359 µs per overlapping block, with identical allocations; it does not establish the cause of the SQL variation.
  • Real/fake-PK filter-construction ABBA at 4, 64, 1,000 and 16,384 keys kept the same allocation counts and bytes as f7f80a9; eligible cases used 472 B and 13 allocations per constructed filter. On ordered, random and last-inversion physical vectors, first and repeated probe comparisons against the preceding implementation had the same allocation counts. A separate after-GC test with 32 live filter closures on entirely ordered vectors reduced retained Go heap from about 1.18 MB to measurement noise at 1,000 keys and from 18.92 MB to about 6.6 KB at 16,384 keys. This is not peak process RSS; an inverted eligible vector still constructs the bounded map.

A last-pair inversion necessarily adds an order scan before falling back to the hash. One short synthetic sample was 20.5% slower across 16 blocks; a longer local repeat did not reproduce it consistently. Earlier full-PR component tests also observed an approximately 19% one-shot cost at the candidate cap against a prior binary-only implementation, with repeated probes benefiting. Results can vary with key distribution, block reuse, concurrency and hardware. Cold remote storage and multi-CN performance have not been verified. Remote CI on the updated head is pending.

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

Copy link
Copy Markdown
Contributor Author

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

Commit: cb3d95e782cb25a159e3293d0f804af3b7fc2c04

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

Assessment: approve

No actionable findings. Bounded membership reuse preserves selection semantics and ownership, with measured gains that justify its allocation cost.

Model: gpt-6.1-sol / max

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

Validation:

  • Both owning packages passed normal and race tests with no skips, using matching native prerequisites built in a writable frozen-head copy.

  • TestUnsortedPKInSearchConcurrentReuse passed 100 race repetitions.

  • Construction-inclusive benchmark: 1,000 keys across 124 blocks improved from 55.0 ms to 6.82 ms median against the exact-base factory control. Allocation at the cap was approximately 0.56 MiB.

  • Scope, both discussion keys, source identity and command/log/exit receipts reconciled in validation-summary.json. Final audit passed: checks/1793695068566952095-3.json. Source remained unchanged.

Limitations:

  • Frozen CI reports 6 successes, 13 skipped, 5 in progress and 2 neutral checks; pending checks are not passes.

  • Measurements are local component benchmarks. SQL, cold-storage, multi-CN performance and retained-heap peaks were not independently measured. The linked planner-selection issue remains open.

@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: f7f80a9a86696550ee6621ffd36ecf544b3dfa2c

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

Assessment: approve

No actionable findings. The guards and float fallback preserve correctness; measured reuse gains justify the bounded allocation and fallback costs.

Model: gpt-6.1-sol / max

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

Validation:

  • Current readutil normal and race suites passed without skips; the mixed-size concurrent-reuse test passed 100 race repetitions.

  • Unchanged vector normal/race evidence was reused after verifying relevant source, dependency and build inputs.

  • Construction-inclusive partial-block benchmark improved from 8.02 ms to 1.68 ms median against the original production-code control.

  • All four discussion keys and command/source/log/exit receipts reconciled in validation-summary.json. Final audit passed: checks/1793698601107448260-3.json. Source remained unchanged.

Limitations:

  • Local samples showed about 13% overhead below the row threshold and 60–75 ns extra for tiny/constant inputs; this is not an all-input speedup.

  • Frozen CI has 5 checks in progress: 6 success, 13 skipped and 2 neutral.

  • SQL, cold-storage, multi-CN performance and retained-heap peaks were not independently measured. The linked planner-selection issue remains open.

@aunjgr aunjgr 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 all four changed files and traced filter validation/ownership through ConstructBlockPKFilter and the IN type dispatch. No actionable finding. The immutable per-closure set is capped at 16,384 candidates, initialized once only for sufficiently large physical vectors, and leaves sorted-block, unnormalized, short-list and float paths unchanged. Equality/custom-comparator argument order, constant-vector physical length, partially filled blocks, concurrent first publication, and key/row thresholds have distinct regression coverage. Reused the recorded normal/race package and SQL differential/benchmark evidence plus successful current-head CI; no new local test run. The disclosed per-reader/disjunct heap multiplier and bounded one-shot construction regression are accepted scope/performance tradeoffs, not a claim to fix planner index admission.

@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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.

@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: f7f80a9a86696550ee6621ffd36ecf544b3dfa2c

New discussion was assessed; the previous review remains unchanged.

@XuPeng-SH XuPeng-SH changed the title perf: reuse bounded membership for unordered PK backfill perf: accelerate unordered primary-key IN filtering Nov 3, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Nov 3, 2026
@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 49a89f469a1fa9cf5ae1330d1218059a5a79d201

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: 49a89f469a1fa9cf5ae1330d1218059a5a79d201

Assessment: approve

No actionable findings. Reusing the existing sorted search after a per-vector order check avoids unnecessary maps while preserving bounded lazy hashing, selection semantics and ownership. The broader planner issue #32015 remains open.

Model: gpt-6.1-sol / max

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

Validation:

  • Reviewed the complete four-file delta, affected consumers and linked issue. All nine discussion items are accounted for; final source audit passed and both checkouts remain clean.

  • Vector and readutil packages passed normal and race tests on Go 1.27.1 with no skips: checks/1793728365091308556-3.json and checks/1793728603510262384-3.json.

  • Concurrent-reuse test passed 100 race repetitions: checks/1793728649349807934-3.json. Both focused blockio consumer tests passed: checks/1793728742409274211-3.json.

  • Native prerequisites were built from the frozen head and provenance verified. Commands, exits and retained logs are reconciled in validation-summary.json.

Limitations:

  • Supplied SQL and performance measurements were assessed but not independently rerun; relevant frozen CI contexts remained pending.

  • Cold remote I/O, multi-CN performance and peak memory remain unverified. Bounded per-filter memory and one-shot overhead are accepted tradeoffs.

This branch was successfully deployed

No deployments
ci — 12c6711a 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/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants