Skip to content

test(types): check decimal and temporal switches; baseline records missing members (#10181 step 7) - #33346

Merged
fengttt merged 14 commits into
matrixorigin:mainfrom
fengttt:type-vft-step7
Nov 28, 2026
Merged

fengttt merged 14 commits into
matrixorigin:mainfrom
fengttt:type-vft-step7

Conversation

@fengttt

@fengttt fengttt commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • Test and CI

Which issue(s) this PR fixes:

issue #10181

What this PR does / why we need it:

Step 7 of docs/design/20261126-type-vft.md.

Two new families in TestTypeSwitchFamilies

decimal (IsDecimal) and temporal (IsDateRelate). Both are defined by the traits table flags, so a type joins them through its row in traits_table.go. In a chain, IsDecimal() and IsDateRelate() name their members.

I measured the candidate families first:

  • decimal: 137 of the 155 flagged switches miss exactly T_decimal256.
  • temporal: 81 of the flagged switches miss exactly T_year.

Both are types added after the others in their family, which is the forgotten-type pattern.

integer and string were left out. Their flagged switches follow deliberate width and charset groupings (54 handle only int64/uint64), so those families would be noise.

The baseline now records what each switch misses

It used to store only a count per (file, function, family). A type added to a family therefore went unnoticed in every switch already listed: the count didn't change.

Each line now also lists the members those switches miss, and the test fails when a listed switch misses another one. As an experiment, I added a fake T_decimal512 to types.go and traits_table.go, and 154 old switches failed. TestTypeSwitchBaselineProblems checks the rules on made-up sites.

typeswitch_baseline.txt is regenerated in the new format:

  • the float and vector entries are unchanged apart from the new column;
  • the 373 decimal and temporal entries are the switches that predate the new families.

The README for the check is updated.

The "all types" rule from the design is left out: the dispatch switches it targeted moved onto tables in steps 3–5.

Tests

./pkg/container/types passes. Lint reports 0 issues.

🤖 Generated with Claude Code

fengttt and others added 12 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]>
Step 6 of docs/design/20261126-type-vft.md (matrixorigin#10181).

fillNullableStr's general loop (key vectors with NULLs, or const) switched
on the type id and re-read the vector's type, size, data, const flag and
NULL bitmap on every row. It now resolves them once and runs a loop typed
for the vector: float32, float64, other fixed-size, varlena. The key
bytes are unchanged.

BenchmarkFillNullableStr (256 rows with NULLs, 6 runs, median):
  decimal128  1865 -> 1305 ns  -30%
  float32     2060 -> 1472 ns  -29%
  float64     1977 -> 1401 ns  -29%
  int32      ~1975 -> 1516 ns  -23%
  varchar     2152 -> 2159 ns   ~0 (dominated by the copy)

The old loop is kept in fill_nullable_legacy_test.go;
TestFillNullableStrMatchesLegacy compares the encoded keys and the
not-inserted marks for 15 key types, plain, const and const-NULL
vectors, maps with and without NULL keys, and a start offset.

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

Step 6 measured every loop-invariant switch first. Only nullable hash-key
encoding was worth changing (previous commit). castToJSON (42 ns/row for
int64, 25 ns/row even for the json-to-json append), jsonToNumeric,
NormalizeL2Array, the prepared-cursor estimators, timewin, ivf_create and
productl2 do far more work per row than a ~1 ns switch.

Step 6b: BenchmarkColumnSlicesRows encodes 1024-row batches through the
result-row path (appendResultSetTextRow2 / BinaryRow2): 37 ns/cell text,
27 ns/cell binary for int64, 107-124 ns/cell for mixed columns. A CPU
profile puts all type dispatch under 4%; the cost is Conn.Append (18%),
IsNull per cell (11%), and fmt.Sprintf in Datetime.String2 and
Decimal64.Format (15% of the mixed case). Per-column encoders are
therefore not worth it; the benchmark stays for a formatting change.

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

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

TestTypeSwitchFamilies gains two families, defined by traits table flags
so a type joins them by its row in traits_table.go: decimal (IsDecimal)
and temporal (IsDateRelate). In a chain, IsDecimal() and IsDateRelate()
name their members.

Candidates were measured first. Of the switches each family flags, 137 of
155 decimal ones miss exactly T_decimal256 and 81 temporal ones miss
exactly T_year, both types added after the others. Integer and string
families were left out: their flagged switches follow deliberate width
and charset groupings (54 handle only int64/uint64), so they would be
noise.

The baseline now also records the members each listed switch misses, and
the test fails when a listed switch misses another one. It used to store
only a count per file, function and family, so a type added to a family
went unnoticed in every switch already listed. Adding a fake
T_decimal512 to types.go and traits_table.go now fails 154 old switches.
TestTypeSwitchBaselineProblems checks the rules on made-up sites.

typeswitch_baseline.txt is regenerated in the new format. Its float and
vector entries are unchanged apart from the new column; the 373 decimal
and temporal entries are the switches that predate the new families.

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#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
fengttt merged commit 25ab7b1 into matrixorigin:main Nov 28, 2026
3 of 5 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, 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants