Skip to content

refactor(storage): remove containers.Vectors, fastrand and mock (#33539) - #33540

Merged
fengttt merged 6 commits into
matrixorigin:mainfrom
fengttt:vectors-to-batch
Nov 30, 2026
Merged

fengttt merged 6 commits into
matrixorigin:mainfrom
fengttt:vectors-to-batch

Conversation

@fengttt

@fengttt fengttt commented Nov 30, 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:

issue #33539

What this PR does / why we need it:

Two commits; the second is a mechanical move and is easier to review alone.

1. Replace containers.Vectors with batch.Batch

  • Column loaders (LoadColumnsData, ReadDeletes, ...) fill a *batch.Batch and set its row count. Read-filter searches take []*vector.Vector. objectio no longer imports the TAE containers package.
  • Batch.InitVectors(n) allocates up to 8 vectors and their pointers at once. Scratch batches stay on the stack in the tombstone and reader paths.
  • The reader creates its scratch vectors on the first load that needs them and sizes them to the block. Plain scans copy straight to the output and never create them.
  • LoadColumnsDataFromMeta's release no longer moves the IOVector to the heap.
  • The checkpoint readers no longer copy vector headers that share ownership of their buffers.
  • VectorsCopyToBatch becomes CopyBatch. Its test ignored append errors and compared zero rows; it now checks the data.
  • VectorPool.GetVector uses math/rand/v2 instead of a linkname to runtime.cheaprand. Both runtime*.go files are removed; runtime.go (!go1.22) was never built.

2. Move containers/mock.go to tae/testutils

catalog.MockBatch, a wrapper in a non-test file, becomes testutils.MockSchemaBatch, so no production package imports testutils. It takes an interface because importing the catalog from testutils would create import cycles.

Benchmarks

Base and new alternated on pinned cores, 8 to 24 samples each.

Path Allocs/op B/op Time
Reader scan, 1-32 columns -1 -25% to -28% -1% to -6%
Reader point lookup -1 -13% to -24% 0 to -5%
Reader limit fallback -1 up to 8 columns, else same -19% to +0.8% -1% to -5%
Tombstone reads -1 -3% to -9% 0 to -4%
Checkpoint meta, 64 rows 22 to 15 -19% -8%
Late materialization -1 -12% no significant difference

Costs:

  • GetVector + release is about 2% (3 ns) slower serially, with the same allocations.
  • The limit fallback at 32 columns uses 159 B more per reader.
  • BlockDataReadInnerDeletes1 measured +0.6% (p=0.006); Deletes10 shows no difference.
  • An unsorted lookup measured +3.6% in one build; over 6 randomized function layouts it ranges from -16% to +7% (pooled p=0.99), so that is code layout.

Testing

  • Unit tests of the affected packages, including tae/db/test, engine/test, disttae and backup.
  • make static-check-changed: 0 issues.
  • Not run locally: BVT, sysbench, TPC-H.

🤖 Generated with Claude Code

fengttt and others added 2 commits November 30, 2026 10:01
Column loaders fill a *batch.Batch and set its row count; read-filter
searches take []*vector.Vector. containers.Vectors is removed, and objectio
no longer imports the TAE containers package for it.

Batch.InitVectors allocates up to 8 vectors and their pointers at once, and
the Batch stays on the caller's stack. The reader creates its scratch vectors
on the first load, sized to the block: scans that copy straight to the output
never allocate them. LoadColumnsDataFromMeta's release no longer moves the
IOVector to the heap. The checkpoint readers no longer copy vector headers
that share ownership of their buffers.

VectorsCopyToBatch becomes CopyBatch; its test now checks the appends.

In containers, VectorPool picks an element with math/rand/v2 instead of a
linkname to runtime.cheaprand (about 3 ns per GetVector), and both runtime*.go
files are removed; runtime.go was never built.

Add benchmarks for tombstone reads, a reader's life, and the vector pool.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
containers/mock.go holds test data generators but was part of the production
package. Move it, with its test, to tae/testutils. catalog.MockBatch, a wrapper
over it in a non-test file, becomes testutils.MockSchemaBatch, so no production
package imports testutils. It takes an interface: testutils cannot import the
catalog without import cycles.

MockNullableBatch, only the body of MockBatch, is merged into it. The
containers tests that use the mocks become package containers_test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 →

@mergify

mergify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

The same switches moved from tae/containers/mock.go to tae/testutils/mock.go;
no entry is added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The type-switch baseline may only shrink: tag MockVector and MockVector2,
whose default handles the remaining types, and drop their baseline entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fengttt
fengttt merged commit 4e50e2d into matrixorigin:main Nov 30, 2026
4 of 6 checks passed
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 30, 2026

This branch was successfully deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/refactor Code refactor size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants