Repository navigation
refactor(types): type dispatch design (#10181), oidscan, DML dispatch fixes, traits table - #33338
Merged
Merged
Conversation
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]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Contributor
|
This pull request is merged. |
Contributor
|
mo-bot review · Commit: Review belongs to an older commit; it is not a review of the current head. |
…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]>
Merged
2 of 7 tasks
1 of 7 tasks
This was referenced Nov 26, 2026
Merged
fengttt
added a commit
that referenced
this pull request
Nov 26, 2026
…#10181 steps 4, 4b) (#33339) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [x] Code Refactoring ## Which issue(s) this PR fixes: issue #10181 ## What this PR does / why we need it: **Stacked on #33338.** This branch contains #33338's commits. Review only the last three: `cea83426fa` (oidscan `-list`/`-dir`), `d96e48d87d` (vector type-ops table, step 4) and `2ef75a7532` (step 4b). Once #33338 merges, this PR's diff shrinks to those three. This is steps 4 and 4b of `docs/design/20261126-type-vft.md`. **`pkg/container/vector/type_ops.go`** - One row per type id, giving the Go element type that stores it (`fixedOps[T]()` or `varlenOps()`). - The 7 type ids no operation here supports (`any`, `star`, `int128`, `uint128`, `interval`, `Objectid`, `tuple`) are listed explicitly. **Moved onto the table:** `GetAny`, `AppendAny`, `Shrink`, `ShrinkByMask`, `Shuffle` and `shuffleWithBufData`. - Each used to switch over 47 type ids. I extracted their switches mechanically and 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, and the others panic with their own message. **No change in behavior** - The six switch implementations are kept in `type_ops_legacy_test.go`. - `TestTypeOpsMatchLegacy` runs old and new on random vectors of every type id, with NULLs and with varlenas both inline and in the area. It compares returned values, resulting vectors, errors and panics, and checks the mpool is back to zero afterwards. - I checked the test catches a wrong row: `int16` for `date` (wrong size), and `uint32` for `date` (right size, wrong Go type). - `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` and its varlen flag against the type. **Step 4b: five more on the table** - `getUnionAllFunction`: 853 lines of hand-written per-type closures become `unionAllFixed[T]` and `unionAllVarlen`. `T_any` keeps its own closure, and the local `unionNsp` helper moves to package level unchanged. - `MakeAppendBytesFunc` and `NewFunctionResultWrapper` read the fixed-size case from the table. Variable-length types are still handled first, as before. - `canonicalVectorTypeSize` and `isVarlenaMarshalType` read the table instead of listing the type ids again. - `TestTypeOpsConstructorsMatchLegacy` compares old and new on every type id: union from plain, const and const-null sources into a vector with a different data area; append-bytes; function result; and canonical size, with right and wrong sizes. I checked it fails when a varlena type is given the fixed-size union. My first version missed that, because it appended into a copy of the source, whose identical area hid the bug. - Union benchmarks are within ±1%. **`getConstSetFunction` stays a switch.** Its closures run once per probe row per column in `SetJoinBatchValues`. A generic version measured about 1 ns (8%) slower per call (12.0 → 13.0 ns), because Go compiles one body per memory layout with type lookups at run time, while the hand-written closures are fully specialized. Instead, `TestConstSetCoversTypeOps` ties the switch to the table: it must return a function for every supported type id and panic for every other one except `T_any`. A new type therefore can't be forgotten there either. The design doc records this as a general rule for switches on per-row paths. **What stays in `vector`:** 12 switches that encode meaning rather than storage. They are formatting (`String`, `RowToString`), ordering (`GetMinMaxValue`, `compareVectorRows`, the sort functions, `supportsInplaceSort`), summing with widening (`GetSumValue`), and small helpers. **Step 4 benchmarks** (6 runs each): within noise. | | table | switch | |---|---|---| | `GetAny` int64 | 10.2 ns | 10.1 ns | | `GetAny` varchar | 19.6 ns | 19.3 ns | | `GetAny` Blockid | 13.1 ns | 13.2 ns | | `Shrink` (Dup + Shrink + Free) | unchanged | | **Also:** `optools/oidscan` gains `-list` and `-dir`, which print one package's switches. That's how the six were picked. **Tests** - The full `container/vector` suite, all of `sql/colexec/...`, `sql/plan/function`, `container/batch`, `container/pSpool` and `vm/engine/tae/containers` pass, after both 4 and 4b. - All of `./pkg/...` builds. - `molint` and `golangci-lint` report 0 issues on `container/vector`. - `typeswitch_baseline.txt` is unchanged (the six switches were complete). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
fengttt
added a commit
to fengttt/matrixone
that referenced
this pull request
Nov 27, 2026
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]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #10181
What this PR does / why we need it:
Design plus steps 1–3 of the plan in
docs/design/20261126-type-vft.md.Design doc. Measures the type-id switches in
pkg/and proposes anOid-indexed type table (types.Traits) and per-package operation tables with completeness tests. The switches that stay are covered by extending the existingTestTypeSwitchFamiliescheck (more families, plus an "all types" rule for dispatch switches). The table is indexed byOidrather than stored as a pointer intypes.Type, becauseTypehas a fixed 16-byte stored layout.Step 1:
optools/oidscan. A standalone, standard-library-only module that reports switch counts, a case-count histogram, the switches inside loops, and which of those have a type that is fixed for the loop. It is a report, not a check.go run . -root ../.. -loops -invariantgives the worklist for step 6.Step 2: dispatch out of row loops in DML.
multi_updateandpreinserteach had a copy of the zero-temporal check with a type switch per row. Both now callcolexec.CheckZeroTemporalVector, which switches once per vector. Error codes, messages and row numbers are unchanged.postdmldecides how to quote the primary key once per batch instead of once per row.deletioncopied each deleted key throughgetNonNullValue+AppendAny: boxed, with two type switches per row. ItsgetNonNullValuecopy panicked on key types it didn't list (the low-precision floats,year, most vector types). The key is now copied withUnionOne, and that copy ofgetNonNullValueis removed.typeswitch_baseline.txtwas regenerated. Lines were only removed: the twodeletionentries, plus 12 entries already fixed upstream.Step 3: one table of per-type facts in
types.traits_table.gohas one row perT_constant: family flags,TypeLen,FixedLength, the default typeTryToTypereturns, and theString/OidStringnames. These methods and theT.IsXxx()predicates (plusType.IsInt/IsUInt/IsFloat/IsDecimal) now read the table instead of each switching on the type id.traits_legacy_test.goas an oracle, andTestTraitsMatchLegacycompares every method on all 256Tvalues, including the existing panics forint128,uint128,Objectidandstar. I confirmed the test fails when a row is changed.falseor "unknown"), so a forgotten size fails loudly instead of returning 0.TestTraitsCoverEveryOidfails when aT_constant has no row.TestTraitsFlagFamiliesties the float and vector flags to theTestTypeSwitchFamiliesfamilies.FixedLength106 vs 124 ns,IsFloat31 vs 39 ns,IsDateRelate31 vs 33 ns).types.gothat are now table rows.Tests
TestCheckZeroTemporalVectorcovers nulls, const and const-null vectors, the timestamp lower bound, and error row numbers.TestCollectBatchInfoCopiesKeyscovers int64, out-of-line varchar, decimal128 and float16 keys, checks grouping by block, and checks the mpool is back to zero afterwards.oidscanhas fixture tests.typessuite passes, and so do thecontainer/vector,container/batch,sql/plan/functionandvm/engine/tae/containerssuites. All of./pkg/...builds.colexec,multi_update,preinsert,postdmlanddeletion, andTestTypeSwitchFamilies, pass.molintandgolangci-lintreport 0 issues on the changed packages,pkg/container/typesincluded.🤖 Generated with Claude Code