Skip to content

refactor(tae): read and update TAE values through the vector type-ops table (#10181 step 5) - #33343

Merged
fengttt merged 11 commits into
matrixorigin:mainfrom
fengttt:type-vft-step5
Nov 27, 2026
Merged

fengttt merged 11 commits into
matrixorigin:mainfrom
fengttt:type-vft-step5

Conversation

@fengttt

@fengttt fengttt commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Code Refactoring

Which issue(s) this PR fixes:

issue #10181

What this PR does / why we need it:

This is step 5 of docs/design/20261126-type-vft.md.

  • The vector type-ops table gains a setAny operation, exported as vector.SetAny, plus vector.SupportsAny.
  • TAE's getNonNullValue is now the support check plus vector.GetAny.
  • UpdateValue is the support check plus vector.SetAny, with its NULL handling unchanged.
  • GenericUpdateFixedValue and GenericUpdateBytes had no other users and are removed.

Bug fixed: TAE's switches had fallen behind the vector code, which is exactly what #10181 is about.

  • getNonNullValue panicked ("No Support") on T_decimal256, T_geometry and T_geometry32.
  • UpdateValue panicked ("not supported") on those and on T_year.

containers.GetValue and UpdateRow go through these. They now work for those types.

Tests

  • The old switches are kept in value_access_legacy_test.go. TestValueAccessMatchesLegacy compares old and new on every type id: same values, same resulting vectors, same panics. The exception is the formerly missing types, which it checks used to panic and now work.
  • TestSetAny covers the new vector operation for every type id.
  • The full ./pkg/vm/engine/tae/..., ./pkg/objectio/..., ./pkg/publication/... and ./pkg/container/vector/ pass.
  • Lint reports 0 issues, and typeswitch_baseline.txt is unchanged.

🤖 Generated with Claude Code

fengttt and others added 9 commits November 26, 2026 11:50
Design and phased plan for issue matrixorigin#10181. Measures the 949 type-id
switches in pkg/, identifies the ones that run per row, and proposes an
Oid-indexed traits table in types, per-package operation tables with
completeness tests, and the exhaustive linter for the switches that stay.

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

Step 1 of docs/design/20261126-type-vft.md (matrixorigin#10181). optools/oidscan is a
standalone, standard-library-only module that scans pkg/ for switch
statements over types.T and reports their count, case-count histogram, the
ones inside a loop, and which of those have a loop-invariant type (the
worklist for moving dispatch out of row loops). It is a report, not a check.

The design doc now builds on the existing TestTypeSwitchFamilies check
(families, typeswitch:partial tags, shrinking baseline) instead of proposing
the exhaustive linter, and records steps 1 and 2 as done.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Step 2 of docs/design/20261126-type-vft.md (matrixorigin#10181).

- multi_update and preinsert each had a copy of the zero-temporal check
  that switched on the column type for every row. Both now call
  colexec.CheckZeroTemporalVector, which switches once per vector and runs
  a typed row loop. Error codes, messages and row numbers are unchanged.
- postdml decides how to quote the primary key once per batch instead of
  per row.
- deletion copied each deleted row's key by boxing it (getNonNullValue)
  and unboxing it again (AppendAny): two type switches per row, and the
  getNonNullValue copy panicked on key types it did not list (the
  low-precision floats, year, most vector types). The key is now copied
  with UnionOne, and that copy of getNonNullValue is removed.
- typeswitch_baseline.txt regenerated: removals only (the two deletion
  entries plus 12 entries already fixed upstream).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Step 3 of docs/design/20261126-type-vft.md (matrixorigin#10181).

traits_table.go holds one row per T_ constant: family flags, TypeLen,
FixedLength, the default type TryToType returns, and the String and
OidString names. String, OidString, TypeLen, FixedLength, TryToType, the
T.IsXxx predicates and Type.IsInt/IsUInt/IsFloat/IsDecimal read the table
instead of each switching on the type id. AllOids() lists the T_ constants
for other packages' completeness tests.

No change in behavior: the switch implementations are kept in
traits_legacy_test.go and TestTraitsMatchLegacy compares every method on
all 256 T values, including the panics for types with no size. A field
left out of a row means "absent" (panic, false or "unknown"), so a
forgotten size fails loudly. TestTraitsCoverEveryOid fails when a T_
constant has no row; TestTraitsFlagFamilies ties the float and vector
flags to the TestTypeSwitchFamilies families. Benchmarks: the table is
as fast as or faster than the switches (FixedLength 106 vs 124 ns,
IsFloat 31 vs 39 ns per pass over all types).

typeswitch_baseline.txt: two entries removed, both switches in types.go
that are now table rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
-list prints every type-id switch (file:line, function, type ids named,
default branch, inside a loop); -dir keeps the switches in files directly
in one directory. Used to pick the switches each step of
docs/design/20261126-type-vft.md moves.

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

Step 4 (pilot) of docs/design/20261126-type-vft.md (matrixorigin#10181).

type_ops.go has one row per type id with the Go element type that stores
it (fixedOps[T] or varlenOps), and lists the 7 type ids no operation here
supports. GetAny, AppendAny, Shrink, ShrinkByMask, Shuffle and
shuffleWithBufData read their per-type function from the table instead of
each switching over 47 type ids; all six had the same type-to-Go-type
mapping. Each keeps its own behavior for an unsupported type: GetAny
returns nil, AppendAny does nothing, the others panic with their own
message.

No change in behavior: the six switch implementations are kept in
type_ops_legacy_test.go, and TestTypeOpsMatchLegacy runs both on random
vectors (with NULLs and out-of-line varlenas) of every type id, comparing
values, vectors, errors and panics. A row with the wrong element type
fails it even when the size matches. TestTypeOpsCoverEveryOid fails when
a T_ constant is neither a row nor listed as unsupported; TestTypeOpsRows
checks each row's element size against types.T.TypeLen.

Benchmarks are within noise: GetAny +1% (int64) to -1% (Blockid),
Shrink unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ch onto the type-ops table

Step 4b of docs/design/20261126-type-vft.md (matrixorigin#10181).

- getUnionAllFunction: 853 lines of per-type closures become
  unionAllFixed[T] and unionAllVarlen, built per row of the table; T_any
  keeps its own closure. unionNsp moves to package level, unchanged.
- MakeAppendBytesFunc and NewFunctionResultWrapper read the fixed-size
  case from the table (varlena types are still handled first, as before).
- canonicalVectorTypeSize and isVarlenaMarshalType read the table instead
  of listing the type ids again.

getConstSetFunction stays a switch: its hand-written closures run per row
in SetJoinBatchValues, and the generic version measured about 1 ns (8%)
slower per call. TestConstSetCoversTypeOps ties it to the table instead:
it must return a function for every supported type id and panic for every
other one but T_any.

No change in behavior: the replaced functions are kept in
type_ops_legacy_test.go, and TestTypeOpsConstructorsMatchLegacy compares
them on every type id (union from plain, const and const-null sources
into a vector with a different area; append-bytes; function result;
canonical size with right and wrong sizes). Checked that it fails when a
varlena type is given the fixed-size union. Union benchmarks are within
+-1%.

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

Fixes matrixorigin#33336 (part of matrixorigin#33335).

containers.Vector was an interface implemented by a wrapper around
*vector.Vector. It is now an alias for *vector.Vector, the wrapper is
gone, and its methods are free functions in containers/vector.go with the
same behavior (GetValue, AppendValue, UpdateRow, Extend, Compact,
Window, CloneWindow, WriteVector/ReadVector, ...). GetDownstreamVector()
and ToTNVector() calls are removed: they were identity on the vector.
TAE Batch stays (matrixorigin#33337); its Vecs are now []*vector.Vector.

Release: Close() becomes ReleaseVector(v). A vector lent by a VectorPool
goes back to its pool; any other vector is freed with its own pool. To
keep pooled release safe without a field on Vector, the pool lends a
fresh vector struct holding the element's buffers and moves them back on
release; a package-level registry records what is lent. A stale second
release then finds an empty struct, so it can never reach a later
borrower of the same buffers, and release stays idempotent as Close was
(pnode.go relies on it).

Behavior changes, all deliberate:
- The wrapper copied a read-only vector on first write (copy-on-write).
  The mutating functions now panic on a read-only vector instead. The
  full TAE suite found two sites: checkpoint backup (replay.go) appends
  to loaded checkpoint vectors, so it now Dups a cache-backed one first,
  as the wrapper did; and TestNull1 updated a window of a mock batch.
- ReleaseVector frees a read-only vector too (dropping references and an
  owned null bitmap); the wrapper skipped Free for those, which leaked
  an owned null bitmap.
- VectorAllocated (used by Batch.Allocated) keeps the wrapper's 0 for a
  read-only vector; vector.Allocated reports referenced capacity.

The call sites were rewritten from compiler errors with a one-off tool
(each "X.M undefined" error located the call to rewrite), then reviewed
by hand: the former GetAllocator() calls (now MPool(), the same pool for
an owned vector), the CloneWindow calls that need a pool, Allocated(),
and every former ToTNVector site for copy-on-write.

Tests: release_test.go covers pooled, unpooled, read-only, placeholder
and closed-pool release, and that a stale release cannot affect the next
borrower. Full ./pkg/vm/engine/tae/..., ./pkg/objectio/...,
./pkg/publication/..., ./pkg/vm/engine/test/... and ./pkg/datasync/...
pass; containers passes under -race.

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

Step 5 of docs/design/20261126-type-vft.md (matrixorigin#10181).

The vector table gains setAny, exported as vector.SetAny, and
vector.SupportsAny. TAE's getNonNullValue is now the support check plus
vector.GetAny, and UpdateValue the support check plus vector.SetAny with
its NULL handling unchanged. GenericUpdateFixedValue and
GenericUpdateBytes had no other users and are removed.

This fixes switches that had fallen behind the vector code:
getNonNullValue panicked ("No Support") on T_decimal256, T_geometry and
T_geometry32, and UpdateValue ("not supported") on those and T_year.
containers.GetValue and UpdateRow go through them.

The switch implementations are kept in value_access_legacy_test.go;
TestValueAccessMatchesLegacy compares them on every type id (same
values, vectors and panics, except that the formerly missing types now
work). TestSetAny covers the new vector operation.

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 26, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

Upstream squash-merged the commits this branch stacked on (matrixorigin#33338,
matrixorigin#33339, matrixorigin#33342). The merged tree is upstream/main plus this branch's
step 5 change; conflict in containers/utils.go UpdateValue resolved to
keep main's const and read-only checks (SetNull/UnsetNull) on top of the
SupportsAny/SetAny dispatch. value_access_test uses Vector.GetValue,
since containers.GetValue was removed by matrixorigin#33342.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fengttt
fengttt merged commit 226f575 into matrixorigin:main Nov 27, 2026
4 of 6 checks passed
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 28, 2026
Upstream squash-merged the commits this branch stacked on (matrixorigin#33342,
matrixorigin#33343, matrixorigin#33344). The merged tree is upstream/main plus this branch's
step 7 change; the design-doc step table keeps main's row 6b and this
branch's row 7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 28, 2026
Upstream squash-merged the commits this branch stacked on (matrixorigin#33342,
matrixorigin#33343, matrixorigin#33344, matrixorigin#33346). The merged tree is upstream/main plus this
branch's step 8 change, which applied cleanly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 28, 2026
Picks up the step 8 branch, which now includes upstream/main (with
matrixorigin#33342, matrixorigin#33343, matrixorigin#33344 and matrixorigin#33346 squash-merged). Two uses of APIs
matrixorigin#33342 removed are updated: containers.AppendValue in mock.go becomes
Vector.MustAppendValue, and containers.Window in the decimal256 index
test becomes Vector.Window.

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

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/bug Something isn't working 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