Repository navigation
feat: define collation key sidecar envelope - #28520
VioletQwQ-0 wants to merge 83 commits into
Conversation
fengttt
left a comment
There was a problem hiding this comment.
OK, what is a "sidecar"? Something I have no clue ...
And what is the solution to this -- it is super complicated at this moment, but allow me to ask if there is a simpler solution. Why don't we normalize text string with respect to collation and call it done? Well, even if normalization does not work -- some collation is indeed strange, so why the fix is not on the comparison function? All we need is string compare using strcoll, passing in correct collation. Only need to take care that if collation is C and we use the cheaper function.
At least we need to answer these questions.
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? |
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
Scope reviewed
69 files (+24,082/−9,779): new pkg/common/collationkey (MOKY codec, registry/digest, capability + activation fences, locators, sidecar store/txn, migration gates), HAKeeper RSM durable state, additive proto fields, and v2-gated planner integration across INSERT/ODKU/REPLACE/UPDATE/DELETE, FK locks, apply_indices and build_ddl.
Reachability (established, not assumed)
The whole v2 path is dormant in production. collationkey.WithAdmission has no non-test caller, and nothing outside tests sets TableDef.UniqueKeyCodecVersion, so tableUsesCollationKeyV2 always returns (false, nil) and validateUniqueKeyCodec{,Read}Admission short-circuit on the nil check. Fail-closed therefore holds today: no legacy plan shape changes.
Live changes I verified as safe
- FULLTEXT ODKU no-op marker (
pkg/sql/plan/bind_insert.go:3998) now casts both row images to VARBINARY before<=>. With today's bytewise comparator this is semantically a no-op and only future-proofs the marker. Cast availability checked againstsupportedTypeCast: the only sources lacking→varbinaryare json/TS/Rowid/array types, and MO rejects json/blob/text in primary keys (build_alter_add_column.go:272-306,build_ddl.go:3187) while fulltext parts are restricted to VARCHAR/TEXT (pkg/fulltext/plugin/plan/plan.go:74), so the marker's column set (PK + fulltext parts) is always castable. The plan-shape oracle was updated accordingly. prefixLengthshoisting inbind_delete.go:287/bind_update.go:1904adds no new failure for legacy paths (index params are planner-generated and validated earlier); the checkedoldColName2Idxlookup inbindUpdatereplaces a silentint32(0)on a missing PK column.- Eager unique-index resolution in
bind_replace.go:1606iterates onlygetValidIndexesoutput, which filters!idxDef.TableExist(bind_insert.go:245), and the resolver is cached. buildTableDefspkeyName/colMap reassignment (build_ddl.go:3824) is an identity operation for legacy tables: composite PKs already store the sameCompPkeyColpointer incolMap(build_ddl.go:3709-3718), and single/fake PKs re-read the same name.- Proto changes are additive with free tag numbers (
plan.TableDef=40,api.SchemaExtra=20,CNStoreHeartbeat=25,TNStoreHeartbeat=15,CNStoreInfo=27,TNStoreInfo=14,CheckerState=19/20,HAKeeperRSMState=43/44) and noreservedconflict; generated.pb.gomatches. New function IDs 579/580 are appended without renumbering andFUNCTION_END_NUMBER=581 stays consistent withpredefinedFunids, soTest_funidsholds. Capability/gate copies inpkg/pb/logservice/logservice.godefensively clone digest bytes and maps before storing them in replicated state.
Accepted as documented design intent (not findings)
The unregistered comparator adapter (CollationKeyEqual/CollationKeyNullSafeEqual, called only from tests) and the durable UniqueKeyMigrationGates field with no production writer are both explicitly declared staged/unwired in docs/design/issue-28164-collation-key-identity.md (lines ~960 and ~1028). fengttt's open review thread questions the "sidecar" concept and whether a simpler strcoll/normalization fix exists; that design debate is his unaddressed thread and I am not duplicating it.
Verification limits
go build/go test pass for ./pkg/common/collationkey/... and ./pkg/pb/logservice/.... ./pkg/sql/plan/..., ./pkg/hakeeper/... and ./pkg/vm/engine/... cannot be compiled in this environment because the CGo third-party headers are absent (xxhash.h, roaring.h, usearch.h, jemalloc.h); planner-side conclusions above are from code reading, not execution.
One non-blocking inconsistency with the PR's own fail-closed contract is reported below.
P2 - v2 key builders silently fall back to legacy serial() when relation metadata is malformed, contradicting the documented fail-closed contract (pkg/sql/plan/collation_key_expr.go:232)
makeInsertUniqueIndexKeyExpr (line 231-232) and makeUniqueIndexKeyExprFromInputExprsForRelation (line 303-304) both do:
useV2, err := tableUsesCollationKeyV2(builder.GetContext(), metadataDef)
if err != nil || !useV2 {
... legacy serial()/single-part path ...
}tableUsesCollationKeyV2 returns a non-nil error only when RelationMetadata.Validate() rejects the relation's UniqueKeyCodecVersion (line 44-46). Merging that error into the !useV2 branch converts a malformed-v2 relation into a legacy bytewise key instead of failing, and the swallowed err is then reused as the loop variable in the fallback body, so the diagnostic is lost entirely.
This is the opposite direction from every other v2 gate in the same PR, which propagates the same error: replaceEqualCondition and replaceNonEqualCondition (apply_indices.go:2570, :2680), appendPreInsertPlan/appendDeleteIndexTablePlan/recomputeMoCPKeyViaProjection (build_dml_util.go), bindUpdate, bindDelete, appendReplaceConflictLookup, appendMergedPhysicalTargetUniqueChecks, and makeCompPkeyExprForTable. It also contradicts the contract the PR states for itself — docs/design/issue-28164-collation-key-identity.md requires that "codec capability mismatch and malformed metadata fail-closed" (line 787) and that the behavior "remains fail-closed" (lines 1243, 1277, 1293) — and undoes commit f815075 ("fix: fail closed on malformed v2 index metadata") at exactly the two places that materialize the persisted key bytes.
Consequence once v2 is reachable: an INSERT/ODKU/UPDATE/DELETE against a relation whose metadata fails validation would write and probe a serial() key into a relation declared v2, while the sibling read paths for the same statement return an error. That is precisely the "two different identities under the same activation fence" outcome the design forbids, and it would be silent rather than an error.
Note the same err != nil || useV2 shape in apply_indices.go:2377 (applyExtraFiltersOnIndex) and :3999 (tryIndexOnlyScan) is not a problem and should stay: there the degraded action is to skip an optional rewrite (keep the predicate on the base scan / skip index-only scan), which preserves semantics. The difference is that these two sites degrade to a different physical key encoding.
Suggested change is local: propagate the error (if err != nil { return nil, err }) and keep if !useV2 { ...legacy... } in both functions.
Non-blocking because it is unreachable today — no production code installs an Admission in the planner context or sets UniqueKeyCodecVersion, so err can never be non-nil on any live path — and because the fix is two lines that do not affect the dormant v2 behavior.
|
Closing this unmerged PR because the old collation-key implementation series is no longer being pursued. The replacement design is tracked in #28842 and reuses existing unique-index tables, hidden physical primary keys, and tuple framing. Implementation continues separately at https://github.com/VioletQwQ-0/matrixone/tree/codex/issue-28164-collation-integration . This closure records the design change; it does not claim that the replacement implementation or production validation is complete. Issue #28164 remains open. The branch and commits are retained for reference. |
What type of PR is this?
Which issue(s) this PR fixes:
issue #28164
What this PR does / why we need it:
This draft is a staged implementation increment for the shared, versioned
string unique-key identity path described by the approved #28423 design. It
adds the MOKY codec and frozen registry, relation metadata, capability and
activation fences, stable locators, deterministic sidecar/checkpoint envelopes,
transactional sidecar contracts, and guarded planner/index-probe integration
for INSERT/ODKU, REPLACE, UPDATE, DELETE and foreign-key locking. Composite
and prefix unique keys use the same relation-local codec metadata; unsafe range,
residual, index-only and runtime-filter rewrites fall back instead of treating
opaque v2 bytes as raw SQL strings.
CREATE INDEX and ALTER ADD UNIQUE propagate validated relation codec metadata
and reject unregistered v2 parts. User-visible values and legacy relations are
unchanged. The v2 path remains fail-closed and disabled: current services do
not advertise the capability, ordinary SQL cannot create or write a v2
relation, and no default-v2 rollout or administrator enablement is present.
DDL scoping is relation-local: an
INT PRIMARY KEYremains legacy while asupported textual secondary UNIQUE relation receives its own v2 metadata; an
unregistered mixed key is rejected and a legacy table is not implicitly
migrated by
CREATE INDEXorALTER ADD UNIQUE.The in-memory sidecar transaction contract supports an atomic delete-then-put
locator replacement for one encoded key, with regression coverage. This is a
correctness contract for the future storage adapter; it does not claim that
TN/catalog sidecar persistence or the management migration path is connected.
This increment is not the complete production fix. Real TN/catalog sidecar
persistence and commit validation, all SQL collation/hash/group consumers,
bulk/LOAD/S3/partition ingestion, management migration commands, upgrade and
mixed-version validation, and QA remain follow-up increments. It does not
confirm the customer workload root cause.
Validation:
Exact-head candidate after rebase: head
1a08bb171fbd680cac1575df1cf4deac1d4ef561, base23b20ea909e8ed7e68e331d2bff1a10fce3635f9, clean worktree at push; exactsnapshot diff SHA256
0a969e02d16cbbad2047b404212f64826d853521557f06b1ac4a28241e1d9ec8.The latest increment also makes FULLTEXT value-change markers compare
VARBINARY stored-value images, keeping tokenizer identity separate from
future SQL collation equality for eligible VARCHAR/TEXT parts.
pkg/common/collationkeyunit, race and vet tests: PASS.pkg/sql/plan: PASS.pkg/sql/plan/function: PASS.make build: PASS; exact-headmo-serviceSHA256621b21144b7c7874acb2a4505a93825dc077816ad52a2852a8b70d47ba3d7ad5.git diff --check: PASS.34589705956
is pending for head
1a08bb171fbd680cac1575df1cf4deac1d4ef561; terminal statusis not yet known. Earlier runs 34587578046 and 34589157539 belong to
superseded heads and are not used.
capability admission remains fail-closed.
draft does not enable v2.