Skip to content

perf(objectio): compute vector Top-K directly over chunks - #28434

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aunjgr:perf/chunk-native-topk
Sep 8, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aunjgr:perf/chunk-native-topk

Conversation

@aunjgr

@aunjgr aunjgr commented Sep 8, 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 #24097, following #28413. This contributes to query-execution performance improvements without closing the umbrella issue.

What this PR does / why we need it:

Compute vector Top-K directly over eligible chunked object columns instead of reconstructing, concatenating and reserializing the entire column. Preserve existing decoded whole-column cache hits and the legacy, synthetic-column and unsorted-selection fallbacks.

Use one incremental candidate accumulator across chunks while retaining the reader-wide distance heap, original selection ordinals, duplicates, non-finite behavior and distance bounds before heap admission. Read only selected payload ranges, validate directory and payload contracts, and keep each decoded view inside its complete IOVector lease before releasing it and advancing.

Reuse scoped decompression sharing at chunk granularity without adding buffer recycling, allocator pools or write-format changes. Add tiny persisted fixtures for ranking, corruption, cancellation, sharing and Close, together with cache-pressure and compatibility benchmarks.

Design and scope

Design and validation record.

  • LoadColumnDataByTopN keeps its signature and delegates to ObjectIO's scoped ReadColumnTopN entry point.
  • Streaming is limited to existing Lz4Chunked extents and nil/nondecreasing selections. Unsorted inputs keep their existing tie order through the old path.
  • Retain at most one decoded chunk plus its compressed buffer, the bounded directory and O(K) ranking state. Existing cache/sharing budgets remain independent.
  • No decoded-buffer recycling, writer rollout, data rewrite, new format/protocol, fused INCLUDE expansion or additional parallelism.
  • More cold range-read calls are a tradeoff; this is not a claim about remote-storage latency or legacy-file performance recovery.

Validation

  • ObjectIO, ObjectIO/ioutil and persisted block-reader owning suites in normal mode; production GOAMD64=v3 GOEXPERIMENT=simd mode also tested.
  • Owning-package race checks, plus 100 repetitions of the exact concurrent sharing/Close test after its measured race duration.
  • Selection/tie/displacement, reader-wide seeded heap, all six vector representations, NULL/non-finite/range behavior, malformed directories and payloads, errors after earlier chunks, cancellation, Close, wide offsets and skipped unselected payloads.
  • Differential check against main's exact ranking function: 64 deterministic cases matched rows and distance bits.
  • Existing vector_ivf_topk_consumers BVT: 58/58 statements passed twice in normal comparison mode, with database teardown verified after each run.
  • New chunk-reader statement coverage: 91.7% (100/109).
  • Static analysis passed with 0 issues: package graph, MO lint, license checks and golangci-lint.

Performance evidence

Five matched samples, Go 1.26.4, Linux amd64, GOAMD64=v3 GOEXPERIMENT=simd, main 4b43f8c99b. The control uses the unchanged whole-column read/converter and main's exact ranking function; the candidate uses chunk-native execution.

Scoped ObjectIO workload Main elapsed/read Candidate elapsed/read
Whole decoded-cache hit 333.9 us 308.9 us
Legacy LZ4 under cache pressure 649.0 us 615.1 us
Four chunks, all rows, disk cache warm 5.923 ms 1.234 ms
Four chunks, selection in one chunk 5.584 ms 0.392 ms
Four chunks, local store without disk cache 6.524 ms 2.397 ms

For the all-row pressure case, process CPU/read was 17.965 -> 1.242 ms and Go allocation volume 61.4 MB -> 14.8 KB. The largest returned decoded allocation was 16 MiB -> 4 MiB; tests verify that the iterator holds at most one at a time. These are not total-process RSS measurements.

The fixture uses 4,096 synthetic 768-dimensional vectors with four existing-format chunks, including LZ4 and raw payloads. Pressure cases pin an 8 MiB memory cache; the hot-cache control uses 64 MiB. All-row FileService.Read calls increase from one to six, while sparse selection reads only one payload. Call counters are logical calls, not network requests. These are not SQL QPS or Wiki-10M results. Both compatibility controls meet the 5% median regression gate.

Stream eligible chunked vector columns under scoped cache leases instead of reconstructing and reserializing the complete column. Retain the decoded whole-column cache fast path and the legacy, synthetic-column and unsorted-selection fallbacks.

Use one incremental candidate accumulator across chunks while preserving the reader-wide distance heap, input ordinals, duplicate and non-finite behavior, and distance bounds before heap admission. Read only selected payload ranges, validate their directory and payload contracts, and release each chunk before advancing.

Keep buffer recycling, allocator changes and write-format rollout out of scope. Add small persisted fixtures for ranking, corruption, cancellation, sharing and Close, plus cache-pressure and compatibility benchmarks.
@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 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.

Deep review of exact head c433bf5 against base/merge-base b7eca64: no confirmed blocking findings.

Reviewed every changed hunk in the six-file range and traced the ObjectIO entry point into persisted block-reader consumers, validated cache binding, IOVector cleanup and scoped decode sharing.

Design: PASS. The separately committed design b6ec785 records approval before implementation. The implementation follows its one-chunk consumption and incremental ranking model. The explicit tradeoff of additional cold range reads is accepted; the supplied local-storage measurements do not establish remote-storage latency or SQL throughput. There are no format, writer gate, protocol, tenant or rollout changes.

Correctness: a single accumulator retains the reader-wide distance heap across chunks, bounds admission before heap insertion, keeps block-global rows and original selection ordinals, and finishes once. Sorted selections preserve duplicates and invalid-coordinate skipping; unsorted selections retain the whole-column path and tie order. NULL, non-finite and seeded-heap behavior remain consistent with the original loop. Existing decoded whole-column hits and legacy/synthetic fallbacks remain intact. Consumer row mappings and error propagation were traced.

Audit Closure Result
Q1 ownership Borrowed vector freed before its complete IOVector releases data and sharing lease; read errors clean partial results; only owned rows/distances escape PASS
Q2 termination Cancellation checked at chunk/compute boundaries; sharing wait has context/timer/close exits; no new locks, workers or retries PASS
Q3 bounds Directory bounded by BlockMaxRows, payload sizes validated, one consumed chunk at a time, O(K) candidate state; existing cache/sharing budgets remain independent PASS

Validation: reviewed the persisted tests for selections/ties, ranges/seeded heap, all six vector representations, corruption after earlier chunks, cancellation, sharing/Close, wide offsets and skipped payloads, plus the permanent benchmark controls. Verified CI run 34248146146 is SUCCESS on this exact SHA, including successful Ubuntu UT, shared build, Linux SCA and multi-CN BVT checks. Reused CI and the versioned author validation record (normal/SIMD owning packages, race and focused 100-repeat sharing/Close, twice-run IVF BVT and matched benchmarks); those author-local measurements were not independently rerun here. No code changes.

@mergify mergify Bot added the queued label Sep 8, 2026
@mergify

mergify Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-08 17:25 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-08 17:27 UTC · at 439a1c2bd474acba66ca0948179c3a9b992e933d

This pull request spent 2 minutes 3 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28434 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 9f87b62 into matrixorigin:main Sep 8, 2026
19 of 20 checks passed
@mergify mergify Bot removed the queued label Sep 8, 2026
@mergify mergify Bot added the dequeued label Sep 8, 2026
XuPeng-SH pushed a commit that referenced this pull request Sep 9, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to #24097; this does not close the umbrella performance issue.
Follows #28434 and #28442.

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

Compute fused INCLUDE vector Top-K directly over persisted chunks
instead of reconstructing and serializing a whole vector column. Keep
filter, vector, and projection columns in one storage request on cache
misses, then decode only vector chunks containing residual-filter
survivors.

Reuse decoded whole-column cache hits or a fully cached set of chunks
before reading compressed input. Introduce scoped block-read ownership
and single-entry conversion from supplied bytes so chunks use existing
cache admission and bounded decode sharing without additional storage
reads. Keep compressed sources out of decoded-column cache keys and
release raw buffers and temporary chunk ownership deterministically.

Share chunk validation and ranking with the single-column reader,
preserving physical row coordinates, selection order, ties, thresholds,
and reader-wide heap state. Retain legacy and unsupported-operation
behavior, and reconstruct unsorted selections only from already-held
sources. Projection decoding, storage encoding, parallelism, and buffer
recycling are unchanged.

## Design and validation

The design was approved before implementation and recorded in commit
43fd4ee. The design document is included in this implementation PR;
no separate documentation PR is required.

- Owning packages and block-reader consumer pass: `pkg/fileservice`,
`pkg/objectio`, `pkg/objectio/ioutil`, and `pkg/vm/engine/tae/blockio`.
- Owning FileService/ObjectIO packages pass under the race detector.
Individually selected lifecycle, sharing, chunk-reader, and
fused-consumer tests pass 100 race repetitions.
- Tests cover sparse/dense/empty/unsorted selections, cache warming and
partial hits, ordinary-reader interoperability, immutable encoded data,
FileService decorators, malformed input, cancellation, Close, and
selector/materialization cleanup.
- The real fused consumer exercises both legacy data and chunked output
from the production writer. Miniature persisted fixtures cover chunk
boundaries without large datasets.
- Existing IVF INCLUDE `pre_post_modes`, `mode_paths`, and `end_to_end`
SQL cases pass twice in normal comparison mode, with teardown verified
after each run.
- Full repository SCA passes.

### Performance evidence

Five alternating main/candidate samples of `BenchmarkFusedTopN` against
main `f0c31cd4b8`, using the unchanged public fused loader,
production-written 4096×768 vectors, Go 1.26.4 production SIMD mode,
eight CPUs, and identical cache pressure and requests. Medians:

| Workload | Main elapsed | PR elapsed | Main CPU | PR CPU |
|---|---:|---:|---:|---:|
| Dense, chunked miss | 5.702 ms | 0.700 ms | 11.189 ms | 0.738 ms |
| Sparse, chunked miss | 5.334 ms | 0.249 ms | 10.738 ms | 0.280 ms |
| Eight overlapping readers | 6.773 ms | 1.923 ms | 16.451 ms | 5.539 ms
|
| Legacy column | 0.690 ms | 0.684 ms | 0.730 ms | 0.718 ms |
| Existing whole-column cache hit | 0.241 ms | 0.245 ms | 0.247 ms |
0.250 ms |
| Cache warmed by each implementation | 0.241 ms | 0.249 ms | 0.243 ms |
0.253 ms |

Cold storage reads and requested bytes are unchanged: one read/122,221
bytes for dense or sparse, eight reads/977,768 bytes for the overlapping
cohort. Both warm paths perform zero storage reads. The largest decoded
allocation falls from 16 MiB to 8 MiB. Dense Go allocation falls from
approximately 65.2 MiB to 332 KiB per operation; total decoded backing
allocation remains 16 MiB for dense reads and falls to 8 MiB for sparse
reads.

Warm-cache bookkeeping adds up to 3.4% elapsed time / 4.0% CPU in these
samples, below the 5% control gate. These are fused-loader benchmarks,
not SQL or Wiki-10M latency claims.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#28434)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#24097, following matrixorigin#28413. This contributes to query-execution
performance improvements without closing the umbrella issue.

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

Compute vector Top-K directly over eligible chunked object columns
instead of reconstructing, concatenating and reserializing the entire
column. Preserve existing decoded whole-column cache hits and the
legacy, synthetic-column and unsorted-selection fallbacks.

Use one incremental candidate accumulator across chunks while retaining
the reader-wide distance heap, original selection ordinals, duplicates,
non-finite behavior and distance bounds before heap admission. Read only
selected payload ranges, validate directory and payload contracts, and
keep each decoded view inside its complete IOVector lease before
releasing it and advancing.

Reuse scoped decompression sharing at chunk granularity without adding
buffer recycling, allocator pools or write-format changes. Add tiny
persisted fixtures for ranking, corruption, cancellation, sharing and
Close, together with cache-pressure and compatibility benchmarks.

## Design and scope

[Design and validation
record](https://github.com/aunjgr/matrixone/blob/perf/chunk-native-topk/docs/design/chunk_native_topk.md).

- `LoadColumnDataByTopN` keeps its signature and delegates to ObjectIO's
scoped `ReadColumnTopN` entry point.
- Streaming is limited to existing `Lz4Chunked` extents and
nil/nondecreasing selections. Unsorted inputs keep their existing tie
order through the old path.
- Retain at most one decoded chunk plus its compressed buffer, the
bounded directory and O(K) ranking state. Existing cache/sharing budgets
remain independent.
- No decoded-buffer recycling, writer rollout, data rewrite, new
format/protocol, fused INCLUDE expansion or additional parallelism.
- More cold range-read calls are a tradeoff; this is not a claim about
remote-storage latency or legacy-file performance recovery.

## Validation

- ObjectIO, ObjectIO/ioutil and persisted block-reader owning suites in
normal mode; production `GOAMD64=v3 GOEXPERIMENT=simd` mode also tested.
- Owning-package race checks, plus 100 repetitions of the exact
concurrent sharing/Close test after its measured race duration.
- Selection/tie/displacement, reader-wide seeded heap, all six vector
representations, NULL/non-finite/range behavior, malformed directories
and payloads, errors after earlier chunks, cancellation, Close, wide
offsets and skipped unselected payloads.
- Differential check against main's exact ranking function: 64
deterministic cases matched rows and distance bits.
- Existing `vector_ivf_topk_consumers` BVT: **58/58 statements passed
twice** in normal comparison mode, with database teardown verified after
each run.
- New chunk-reader statement coverage: **91.7% (100/109)**.
- Static analysis passed with **0 issues**: package graph, MO lint,
license checks and golangci-lint.

## Performance evidence

Five matched samples, Go 1.26.4, Linux amd64, `GOAMD64=v3
GOEXPERIMENT=simd`, main `4b43f8c99b`. The control uses the unchanged
whole-column read/converter and main's exact ranking function; the
candidate uses chunk-native execution.

| Scoped ObjectIO workload | Main elapsed/read | Candidate elapsed/read
|
|---|---:|---:|
| Whole decoded-cache hit | 333.9 us | 308.9 us |
| Legacy LZ4 under cache pressure | 649.0 us | 615.1 us |
| Four chunks, all rows, disk cache warm | 5.923 ms | 1.234 ms |
| Four chunks, selection in one chunk | 5.584 ms | 0.392 ms |
| Four chunks, local store without disk cache | 6.524 ms | 2.397 ms |

For the all-row pressure case, process CPU/read was **17.965 -> 1.242
ms** and Go allocation volume **61.4 MB -> 14.8 KB**. The largest
returned decoded allocation was **16 MiB -> 4 MiB**; tests verify that
the iterator holds at most one at a time. These are not total-process
RSS measurements.

The fixture uses 4,096 synthetic 768-dimensional vectors with four
existing-format chunks, including LZ4 and raw payloads. Pressure cases
pin an 8 MiB memory cache; the hot-cache control uses 64 MiB. All-row
FileService.Read calls increase from one to six, while sparse selection
reads only one payload. Call counters are logical calls, not network
requests. **These are not SQL QPS or Wiki-10M results.** Both
compatibility controls meet the 5% median regression gate.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#24097; this does not close the umbrella performance issue.
Follows matrixorigin#28434 and matrixorigin#28442.

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

Compute fused INCLUDE vector Top-K directly over persisted chunks
instead of reconstructing and serializing a whole vector column. Keep
filter, vector, and projection columns in one storage request on cache
misses, then decode only vector chunks containing residual-filter
survivors.

Reuse decoded whole-column cache hits or a fully cached set of chunks
before reading compressed input. Introduce scoped block-read ownership
and single-entry conversion from supplied bytes so chunks use existing
cache admission and bounded decode sharing without additional storage
reads. Keep compressed sources out of decoded-column cache keys and
release raw buffers and temporary chunk ownership deterministically.

Share chunk validation and ranking with the single-column reader,
preserving physical row coordinates, selection order, ties, thresholds,
and reader-wide heap state. Retain legacy and unsupported-operation
behavior, and reconstruct unsorted selections only from already-held
sources. Projection decoding, storage encoding, parallelism, and buffer
recycling are unchanged.

## Design and validation

The design was approved before implementation and recorded in commit
43fd4ee. The design document is included in this implementation PR;
no separate documentation PR is required.

- Owning packages and block-reader consumer pass: `pkg/fileservice`,
`pkg/objectio`, `pkg/objectio/ioutil`, and `pkg/vm/engine/tae/blockio`.
- Owning FileService/ObjectIO packages pass under the race detector.
Individually selected lifecycle, sharing, chunk-reader, and
fused-consumer tests pass 100 race repetitions.
- Tests cover sparse/dense/empty/unsorted selections, cache warming and
partial hits, ordinary-reader interoperability, immutable encoded data,
FileService decorators, malformed input, cancellation, Close, and
selector/materialization cleanup.
- The real fused consumer exercises both legacy data and chunked output
from the production writer. Miniature persisted fixtures cover chunk
boundaries without large datasets.
- Existing IVF INCLUDE `pre_post_modes`, `mode_paths`, and `end_to_end`
SQL cases pass twice in normal comparison mode, with teardown verified
after each run.
- Full repository SCA passes.

### Performance evidence

Five alternating main/candidate samples of `BenchmarkFusedTopN` against
main `f0c31cd4b8`, using the unchanged public fused loader,
production-written 4096×768 vectors, Go 1.26.4 production SIMD mode,
eight CPUs, and identical cache pressure and requests. Medians:

| Workload | Main elapsed | PR elapsed | Main CPU | PR CPU |
|---|---:|---:|---:|---:|
| Dense, chunked miss | 5.702 ms | 0.700 ms | 11.189 ms | 0.738 ms |
| Sparse, chunked miss | 5.334 ms | 0.249 ms | 10.738 ms | 0.280 ms |
| Eight overlapping readers | 6.773 ms | 1.923 ms | 16.451 ms | 5.539 ms
|
| Legacy column | 0.690 ms | 0.684 ms | 0.730 ms | 0.718 ms |
| Existing whole-column cache hit | 0.241 ms | 0.245 ms | 0.247 ms |
0.250 ms |
| Cache warmed by each implementation | 0.241 ms | 0.249 ms | 0.243 ms |
0.253 ms |

Cold storage reads and requested bytes are unchanged: one read/122,221
bytes for dense or sparse, eight reads/977,768 bytes for the overlapping
cohort. Both warm paths perform zero storage reads. The largest decoded
allocation falls from 16 MiB to 8 MiB. Dense Go allocation falls from
approximately 65.2 MiB to 332 KiB per operation; total decoded backing
allocation remains 16 MiB for dense reads and falls to 8 MiB for sparse
reads.

Warm-cache bookkeeping adds up to 3.4% elapsed time / 4.0% CPU in these
samples, below the 5% control gate. These are fused-loader benchmarks,
not SQL or Wiki-10M latency claims.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#28434)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#24097, following matrixorigin#28413. This contributes to query-execution
performance improvements without closing the umbrella issue.

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

Compute vector Top-K directly over eligible chunked object columns
instead of reconstructing, concatenating and reserializing the entire
column. Preserve existing decoded whole-column cache hits and the
legacy, synthetic-column and unsorted-selection fallbacks.

Use one incremental candidate accumulator across chunks while retaining
the reader-wide distance heap, original selection ordinals, duplicates,
non-finite behavior and distance bounds before heap admission. Read only
selected payload ranges, validate directory and payload contracts, and
keep each decoded view inside its complete IOVector lease before
releasing it and advancing.

Reuse scoped decompression sharing at chunk granularity without adding
buffer recycling, allocator pools or write-format changes. Add tiny
persisted fixtures for ranking, corruption, cancellation, sharing and
Close, together with cache-pressure and compatibility benchmarks.

## Design and scope

[Design and validation
record](https://github.com/aunjgr/matrixone/blob/perf/chunk-native-topk/docs/design/chunk_native_topk.md).

- `LoadColumnDataByTopN` keeps its signature and delegates to ObjectIO's
scoped `ReadColumnTopN` entry point.
- Streaming is limited to existing `Lz4Chunked` extents and
nil/nondecreasing selections. Unsorted inputs keep their existing tie
order through the old path.
- Retain at most one decoded chunk plus its compressed buffer, the
bounded directory and O(K) ranking state. Existing cache/sharing budgets
remain independent.
- No decoded-buffer recycling, writer rollout, data rewrite, new
format/protocol, fused INCLUDE expansion or additional parallelism.
- More cold range-read calls are a tradeoff; this is not a claim about
remote-storage latency or legacy-file performance recovery.

## Validation

- ObjectIO, ObjectIO/ioutil and persisted block-reader owning suites in
normal mode; production `GOAMD64=v3 GOEXPERIMENT=simd` mode also tested.
- Owning-package race checks, plus 100 repetitions of the exact
concurrent sharing/Close test after its measured race duration.
- Selection/tie/displacement, reader-wide seeded heap, all six vector
representations, NULL/non-finite/range behavior, malformed directories
and payloads, errors after earlier chunks, cancellation, Close, wide
offsets and skipped unselected payloads.
- Differential check against main's exact ranking function: 64
deterministic cases matched rows and distance bits.
- Existing `vector_ivf_topk_consumers` BVT: **58/58 statements passed
twice** in normal comparison mode, with database teardown verified after
each run.
- New chunk-reader statement coverage: **91.7% (100/109)**.
- Static analysis passed with **0 issues**: package graph, MO lint,
license checks and golangci-lint.

## Performance evidence

Five matched samples, Go 1.26.4, Linux amd64, `GOAMD64=v3
GOEXPERIMENT=simd`, main `4b43f8c99b`. The control uses the unchanged
whole-column read/converter and main's exact ranking function; the
candidate uses chunk-native execution.

| Scoped ObjectIO workload | Main elapsed/read | Candidate elapsed/read
|
|---|---:|---:|
| Whole decoded-cache hit | 333.9 us | 308.9 us |
| Legacy LZ4 under cache pressure | 649.0 us | 615.1 us |
| Four chunks, all rows, disk cache warm | 5.923 ms | 1.234 ms |
| Four chunks, selection in one chunk | 5.584 ms | 0.392 ms |
| Four chunks, local store without disk cache | 6.524 ms | 2.397 ms |

For the all-row pressure case, process CPU/read was **17.965 -> 1.242
ms** and Go allocation volume **61.4 MB -> 14.8 KB**. The largest
returned decoded allocation was **16 MiB -> 4 MiB**; tests verify that
the iterator holds at most one at a time. These are not total-process
RSS measurements.

The fixture uses 4,096 synthetic 768-dimensional vectors with four
existing-format chunks, including LZ4 and raw payloads. Pressure cases
pin an 8 MiB memory cache; the hot-cache control uses 64 MiB. All-row
FileService.Read calls increase from one to six, while sparse selection
reads only one payload. Call counters are logical calls, not network
requests. **These are not SQL QPS or Wiki-10M results.** Both
compatibility controls meet the 5% median regression gate.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#24097; this does not close the umbrella performance issue.
Follows matrixorigin#28434 and matrixorigin#28442.

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

Compute fused INCLUDE vector Top-K directly over persisted chunks
instead of reconstructing and serializing a whole vector column. Keep
filter, vector, and projection columns in one storage request on cache
misses, then decode only vector chunks containing residual-filter
survivors.

Reuse decoded whole-column cache hits or a fully cached set of chunks
before reading compressed input. Introduce scoped block-read ownership
and single-entry conversion from supplied bytes so chunks use existing
cache admission and bounded decode sharing without additional storage
reads. Keep compressed sources out of decoded-column cache keys and
release raw buffers and temporary chunk ownership deterministically.

Share chunk validation and ranking with the single-column reader,
preserving physical row coordinates, selection order, ties, thresholds,
and reader-wide heap state. Retain legacy and unsupported-operation
behavior, and reconstruct unsorted selections only from already-held
sources. Projection decoding, storage encoding, parallelism, and buffer
recycling are unchanged.

## Design and validation

The design was approved before implementation and recorded in commit
43fd4ee. The design document is included in this implementation PR;
no separate documentation PR is required.

- Owning packages and block-reader consumer pass: `pkg/fileservice`,
`pkg/objectio`, `pkg/objectio/ioutil`, and `pkg/vm/engine/tae/blockio`.
- Owning FileService/ObjectIO packages pass under the race detector.
Individually selected lifecycle, sharing, chunk-reader, and
fused-consumer tests pass 100 race repetitions.
- Tests cover sparse/dense/empty/unsorted selections, cache warming and
partial hits, ordinary-reader interoperability, immutable encoded data,
FileService decorators, malformed input, cancellation, Close, and
selector/materialization cleanup.
- The real fused consumer exercises both legacy data and chunked output
from the production writer. Miniature persisted fixtures cover chunk
boundaries without large datasets.
- Existing IVF INCLUDE `pre_post_modes`, `mode_paths`, and `end_to_end`
SQL cases pass twice in normal comparison mode, with teardown verified
after each run.
- Full repository SCA passes.

### Performance evidence

Five alternating main/candidate samples of `BenchmarkFusedTopN` against
main `f0c31cd4b8`, using the unchanged public fused loader,
production-written 4096×768 vectors, Go 1.26.4 production SIMD mode,
eight CPUs, and identical cache pressure and requests. Medians:

| Workload | Main elapsed | PR elapsed | Main CPU | PR CPU |
|---|---:|---:|---:|---:|
| Dense, chunked miss | 5.702 ms | 0.700 ms | 11.189 ms | 0.738 ms |
| Sparse, chunked miss | 5.334 ms | 0.249 ms | 10.738 ms | 0.280 ms |
| Eight overlapping readers | 6.773 ms | 1.923 ms | 16.451 ms | 5.539 ms
|
| Legacy column | 0.690 ms | 0.684 ms | 0.730 ms | 0.718 ms |
| Existing whole-column cache hit | 0.241 ms | 0.245 ms | 0.247 ms |
0.250 ms |
| Cache warmed by each implementation | 0.241 ms | 0.249 ms | 0.243 ms |
0.253 ms |

Cold storage reads and requested bytes are unchanged: one read/122,221
bytes for dense or sparse, eight reads/977,768 bytes for the overlapping
cohort. Both warm paths perform zero storage reads. The largest decoded
allocation falls from 16 MiB to 8 MiB. Dense Go allocation falls from
approximately 65.2 MiB to 332 KiB per operation; total decoded backing
allocation remains 16 MiB for dense reads and falls to 8 MiB for sparse
reads.

Warm-cache bookkeeping adds up to 3.4% elapsed time / 4.0% CPU in these
samples, below the 5% control gate. These are fused-loader benchmarks,
not SQL or Wiki-10M latency claims.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#28434)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#24097, following matrixorigin#28413. This contributes to query-execution
performance improvements without closing the umbrella issue.

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

Compute vector Top-K directly over eligible chunked object columns
instead of reconstructing, concatenating and reserializing the entire
column. Preserve existing decoded whole-column cache hits and the
legacy, synthetic-column and unsorted-selection fallbacks.

Use one incremental candidate accumulator across chunks while retaining
the reader-wide distance heap, original selection ordinals, duplicates,
non-finite behavior and distance bounds before heap admission. Read only
selected payload ranges, validate directory and payload contracts, and
keep each decoded view inside its complete IOVector lease before
releasing it and advancing.

Reuse scoped decompression sharing at chunk granularity without adding
buffer recycling, allocator pools or write-format changes. Add tiny
persisted fixtures for ranking, corruption, cancellation, sharing and
Close, together with cache-pressure and compatibility benchmarks.

## Design and scope

[Design and validation
record](https://github.com/aunjgr/matrixone/blob/perf/chunk-native-topk/docs/design/chunk_native_topk.md).

- `LoadColumnDataByTopN` keeps its signature and delegates to ObjectIO's
scoped `ReadColumnTopN` entry point.
- Streaming is limited to existing `Lz4Chunked` extents and
nil/nondecreasing selections. Unsorted inputs keep their existing tie
order through the old path.
- Retain at most one decoded chunk plus its compressed buffer, the
bounded directory and O(K) ranking state. Existing cache/sharing budgets
remain independent.
- No decoded-buffer recycling, writer rollout, data rewrite, new
format/protocol, fused INCLUDE expansion or additional parallelism.
- More cold range-read calls are a tradeoff; this is not a claim about
remote-storage latency or legacy-file performance recovery.

## Validation

- ObjectIO, ObjectIO/ioutil and persisted block-reader owning suites in
normal mode; production `GOAMD64=v3 GOEXPERIMENT=simd` mode also tested.
- Owning-package race checks, plus 100 repetitions of the exact
concurrent sharing/Close test after its measured race duration.
- Selection/tie/displacement, reader-wide seeded heap, all six vector
representations, NULL/non-finite/range behavior, malformed directories
and payloads, errors after earlier chunks, cancellation, Close, wide
offsets and skipped unselected payloads.
- Differential check against main's exact ranking function: 64
deterministic cases matched rows and distance bits.
- Existing `vector_ivf_topk_consumers` BVT: **58/58 statements passed
twice** in normal comparison mode, with database teardown verified after
each run.
- New chunk-reader statement coverage: **91.7% (100/109)**.
- Static analysis passed with **0 issues**: package graph, MO lint,
license checks and golangci-lint.

## Performance evidence

Five matched samples, Go 1.26.4, Linux amd64, `GOAMD64=v3
GOEXPERIMENT=simd`, main `4b43f8c99b`. The control uses the unchanged
whole-column read/converter and main's exact ranking function; the
candidate uses chunk-native execution.

| Scoped ObjectIO workload | Main elapsed/read | Candidate elapsed/read
|
|---|---:|---:|
| Whole decoded-cache hit | 333.9 us | 308.9 us |
| Legacy LZ4 under cache pressure | 649.0 us | 615.1 us |
| Four chunks, all rows, disk cache warm | 5.923 ms | 1.234 ms |
| Four chunks, selection in one chunk | 5.584 ms | 0.392 ms |
| Four chunks, local store without disk cache | 6.524 ms | 2.397 ms |

For the all-row pressure case, process CPU/read was **17.965 -> 1.242
ms** and Go allocation volume **61.4 MB -> 14.8 KB**. The largest
returned decoded allocation was **16 MiB -> 4 MiB**; tests verify that
the iterator holds at most one at a time. These are not total-process
RSS measurements.

The fixture uses 4,096 synthetic 768-dimensional vectors with four
existing-format chunks, including LZ4 and raw payloads. Pressure cases
pin an 8 MiB memory cache; the hot-cache control uses 64 MiB. All-row
FileService.Read calls increase from one to six, while sparse selection
reads only one payload. Call counters are logical calls, not network
requests. **These are not SQL QPS or Wiki-10M results.** Both
compatibility controls meet the 5% median regression gate.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#24097; this does not close the umbrella performance issue.
Follows matrixorigin#28434 and matrixorigin#28442.

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

Compute fused INCLUDE vector Top-K directly over persisted chunks
instead of reconstructing and serializing a whole vector column. Keep
filter, vector, and projection columns in one storage request on cache
misses, then decode only vector chunks containing residual-filter
survivors.

Reuse decoded whole-column cache hits or a fully cached set of chunks
before reading compressed input. Introduce scoped block-read ownership
and single-entry conversion from supplied bytes so chunks use existing
cache admission and bounded decode sharing without additional storage
reads. Keep compressed sources out of decoded-column cache keys and
release raw buffers and temporary chunk ownership deterministically.

Share chunk validation and ranking with the single-column reader,
preserving physical row coordinates, selection order, ties, thresholds,
and reader-wide heap state. Retain legacy and unsupported-operation
behavior, and reconstruct unsorted selections only from already-held
sources. Projection decoding, storage encoding, parallelism, and buffer
recycling are unchanged.

## Design and validation

The design was approved before implementation and recorded in commit
43fd4ee. The design document is included in this implementation PR;
no separate documentation PR is required.

- Owning packages and block-reader consumer pass: `pkg/fileservice`,
`pkg/objectio`, `pkg/objectio/ioutil`, and `pkg/vm/engine/tae/blockio`.
- Owning FileService/ObjectIO packages pass under the race detector.
Individually selected lifecycle, sharing, chunk-reader, and
fused-consumer tests pass 100 race repetitions.
- Tests cover sparse/dense/empty/unsorted selections, cache warming and
partial hits, ordinary-reader interoperability, immutable encoded data,
FileService decorators, malformed input, cancellation, Close, and
selector/materialization cleanup.
- The real fused consumer exercises both legacy data and chunked output
from the production writer. Miniature persisted fixtures cover chunk
boundaries without large datasets.
- Existing IVF INCLUDE `pre_post_modes`, `mode_paths`, and `end_to_end`
SQL cases pass twice in normal comparison mode, with teardown verified
after each run.
- Full repository SCA passes.

### Performance evidence

Five alternating main/candidate samples of `BenchmarkFusedTopN` against
main `f0c31cd4b8`, using the unchanged public fused loader,
production-written 4096×768 vectors, Go 1.26.4 production SIMD mode,
eight CPUs, and identical cache pressure and requests. Medians:

| Workload | Main elapsed | PR elapsed | Main CPU | PR CPU |
|---|---:|---:|---:|---:|
| Dense, chunked miss | 5.702 ms | 0.700 ms | 11.189 ms | 0.738 ms |
| Sparse, chunked miss | 5.334 ms | 0.249 ms | 10.738 ms | 0.280 ms |
| Eight overlapping readers | 6.773 ms | 1.923 ms | 16.451 ms | 5.539 ms
|
| Legacy column | 0.690 ms | 0.684 ms | 0.730 ms | 0.718 ms |
| Existing whole-column cache hit | 0.241 ms | 0.245 ms | 0.247 ms |
0.250 ms |
| Cache warmed by each implementation | 0.241 ms | 0.249 ms | 0.243 ms |
0.253 ms |

Cold storage reads and requested bytes are unchanged: one read/122,221
bytes for dense or sparse, eight reads/977,768 bytes for the overlapping
cohort. Both warm paths perform zero storage reads. The largest decoded
allocation falls from 16 MiB to 8 MiB. Dense Go allocation falls from
approximately 65.2 MiB to 332 KiB per operation; total decoded backing
allocation remains 16 MiB for dense reads and falls to 8 MiB for sparse
reads.

Warm-cache bookkeeping adds up to 3.4% elapsed time / 4.0% CPU in these
samples, below the 5% control gate. These are fused-loader benchmarks,
not SQL or Wiki-10M latency claims.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/documentation Improvements or additions to documentation kind/enhancement kind/refactor Code refactor size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants