Skip to content

feat(collation): wire native Unicode CI semantics - #29601

Merged
XuPeng-SH merged 31 commits into
matrixorigin:mainfrom
daviszhen:codex/issue-29206-unicode-collations
Oct 10, 2026
Merged

XuPeng-SH merged 31 commits into
matrixorigin:mainfrom
daviszhen:codex/issue-29206-unicode-collations

Conversation

@daviszhen

@daviszhen daviszhen commented Oct 4, 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:

Related to #29206

What this PR does / why we need it:

This is the first executable integration stage for native Unicode case-insensitive collations.

  • Adds distinct utf8_unicode_ci (utf8mb3) and utf8mb4_unicode_ci type identities instead of mapping them to general_ci.
  • Wires UCA400 comparison keys into scalar comparisons, BETWEEN/IN, sorting, MIN/MAX, grouping/hash joins, distinct canonical keys, and serialized/index keys.
  • Exposes DDL, SHOW CREATE, protocol, and information-schema metadata, with regressions for case/accent/ß-vs-ss, ordering, and utf8mb3/utf8mb4 repertoire rules.

This does not claim the complete #29206 rollout. UCA0900, durable relation/index key-format migration markers, mixed-version admission, old-table rebuild/recovery, persisted-filter migration, and full distributed BVT coverage remain follow-up work.

How has this been tested?

  • go test ./pkg/common/collation
  • go test ./pkg/container/types
  • Planner/executor tests with the repository native CGo include/library paths:
    CGO_CFLAGS="-I./cgo -I./thirdparties/install/include" CGO_LDFLAGS="-L./cgo -L./thirdparties/install/lib" go test ./pkg/sql/plan/function ./pkg/sql/plan -count=1
  • Embedded MySQL-protocol regression:
    go test ./pkg/tests/sqlintegration -run '^TestUnicodeCollationConsumerContract$' -count=1 -v
  • gofmt and git diff --check

The latest reviewer findings are addressed as follows:

  • Native Unicode columns are rejected as new PRIMARY KEY parts (inline, table-level, and ALTER paths) until storage lock/write-dedup canonicalization is collation-aware. This prevents collation-equivalent values from committing as distinct primary keys.
  • Native Unicode columns are likewise rejected as UNIQUE key parts across CREATE TABLE, CREATE UNIQUE INDEX, ALTER ADD UNIQUE, and conversion of an existing UNIQUE column until the secondary-index lock/write-dedup path is collation-aware. Ordinary legacy UNIQUE indexes remain allowed.
  • Composite-key filter merging now fails open when a participating key column has native Unicode semantics, retaining the original collation-aware predicates instead of replacing them with raw serialized-key equality.
  • Comparison coercion preserves the selected native Unicode CollationVersion on both rebuilt operands, including derived-expression comparisons such as LOWER(s) = 'a'.

The integration regression covers single/composite primary-key admission rejection, UNIQUE admission/conversion rejection with a legacy control, derived comparison, equality/IN/NOT IN, full and limited ORDER BY, window peers/partitions, GROUP BY, lossless generic SERIAL, and utf8mb3/invalid UTF-8 admission.

@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 →

@daviszhen

Copy link
Copy Markdown
Contributor Author

Re-reviewed exact head b8ec1e1a2909e77b2f1bebdaf031f3682b46c207 against current base 83d82b8ee0cd694e0c6a7146902d74ae4dfb415a. No new SQL correctness blocker was reproduced, but recommend request changes to finish the declared consumer-cost acceptance evidence before treating the integration gate as closed. This is a comment, not a formal review-state change.

[P2] Supply the consumer measurements required by the new resource gate

The documentation update closes the previous contract-description gap: the versioned supported subset, intentional PRIMARY/UNIQUE rejection, restore/ownership boundaries and per-value resource bounds are now explicit. Maintainer approval is recorded; I am not reopening the approval-absence claim.

However, the new acceptance requirement calls for actual ns/op, B/op, allocs/op measurements at 8/64/1024-byte inputs and 256/64-row batches for sort, grouping/hash and shuffle, Unicode versus binary/legacy controls, and no retained-memory growth after release. The release matrix likewise requires consumer resource evidence.

The evidence reported in the latest author comment covers semantic tests and a short-input backend key benchmark, not those integration-consumer requirements. I reran BenchmarkUCA400Key on this head: ASCII/expansion/spaces reported approximately 191.7/161.5/110.1 ns/op, 144/112/104 B/op, and 2 allocs/op on this machine. That benchmark reuses backend scratch; it cannot establish repeated nil-scratch sort-comparison costs, hash sizing plus encoding work, batch-retained keys, or release/accounting behavior.

Please attach a reproducible exact-head consumer measurement report satisfying the stated matrix, including input/batch sizes, controls and ownership/release observations. If equivalent evidence exists elsewhere, link it explicitly and map it to each row. This does not request bytewise performance parity, a cache, a new state machine, or full Unicode PK support. It is an outstanding acceptance-evidence gap, not a claim that a performance regression or leak has been measured.

Fresh correctness verification

  • Targeted Unicode/collation/UNIQUE/physical/composite-filter/function-ID planner and function tests pass (2.393s / 1.204s). Updated TestUnicodeCollationConsumerContract passes.
  • Independent real-MySQL-client challenge on a fresh one-CN embedded cluster passes: single/composite native PRIMARY/UNIQUE rejection; CREATE UNIQUE INDEX and ALTER ADD/ADD COLUMN/MODIFY/CHANGE fencing; binary UNIQUE acceptance and exact-duplicate rejection; LOWER/UPPER comparisons; full/leading-prefix composite CLUSTER BY predicates before/after flush; and non-unique Unicode index DML/result agreement under FORCE versus IGNORE hints, including after flush. Hint agreement does not prove physical index selection for every query.
  • PR diff whitespace check passes. No production source edits were made.

Earlier reproduced correctness findings remain closed for the intentionally fenced new-authoring subset. Existing experimental Unicode PK/UNIQUE catalogs, mixed-version deployment, old-binary migration and full local distributed/repository suites were not tested. Latest-head UT/SCA/coverage/distributed BVT were still running when checked; historical green runs are not counted as current-head completion. My earlier scoped correctness approval was conditional on rollout gates and is not evidence that this newly explicit cost matrix has been executed.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Resolved the remaining consumer-cost acceptance gate at exact head 6c0d413.\n\nChanges:\n- Added reproducible consumer benchmarks for sort, grouping/hash window partition, and shuffle.\n- Covered 8/64/1024-byte values with 256/256/64-row batches.\n- Recorded ns/op, B/op, and allocs/op for legacy, binary, and native Unicode controls.\n- Added repeated release checks (16 iterations per control) asserting mp.CurrNB() == 0 after operator/vector release.\n\nThe full matrix, benchmark command, host/toolchain, and methodology are documented in docs/design/issue-29206-uca400-backend.md under “Exact-head consumer report”.\n\nExact-head local verification:\n- Release checks for sort/hash/shuffle: PASS.\n- Consumer benchmark matrix with benchtime=100ms: PASS.\n\nThe report shows Unicode workspace/allocation growth bounded by input bytes and retained rows, while the release assertions show no retained mpool bytes after cleanup.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Re-reviewed exact head 6c0d4139fdc0b1e6e665b3edcb4f6758c254efe9. Recommendation: request changes for one P2 in the new release-evidence harness/report. The previously missing consumer runtime/allocation matrix is now supplied and independently reproducible; I am not repeating the claim that consumer benchmarks are absent.

[P2] Finish fixture cleanup and limit the release claim to the memory actually observed

The new sort/shuffle release tests allocate a fresh mpool.MustNewZero() repeatedly, free the vector and check mp.CurrNB(), but never delete the pool. See sort release test; shuffle uses the same pattern. NewMPool registers the pool in globalPools, and DeleteMPool removes it. A zero live allocation counter does not remove that global reference.

Independent reproduction using the same three controls and 16 repetitions, sorting/freeing vectors and asserting zero on every iteration:

All 48 vector-release assertions passed;
registered must_new_zero pool records before=0 after=48 delta=48

The hash benchmark also creates NewProcessWithOwnedMPool(b, ...) inside every timed iteration. That helper registers benchmark-level pool deletion, process cleanup and filesystem cleanup. Its fixtures create temporary filesystem services; those cleanup closures/resources accumulate until the subbenchmark ends. Calling proc.Free() does not execute all registered cleanup callbacks immediately. Thus the per-iteration release assertion does not demonstrate that the fixture has been fully released before the next iteration, and measurements include fixture construction/cleanup-registration overhead.

Additionally, UCA key/weight buffers are ordinary Go-heap slices (CollationKey(..., nil, ...) and make), not allocations charged to this vector's mpool. CurrNB()==0 cannot observe their retention. The report's conclusion that these tests establish no retained-memory growth after release is broader than its oracle supports.

Please delete the caller-owned sort/shuffle pools after checking their counters, and reuse explicitly owned process/filesystem fixtures per hash subbenchmark or release them per iteration without accumulating benchmark-level cleanup. Clarify what fixture work is timed. Keep the useful mpool-zero assertions, but either add an appropriate repeated-cycle heap/ownership observation for the claimed Go-heap lifetime or narrow the report to the evidence actually gathered. Regenerate affected measurements after fixing the fixture lifecycle. This is a test/report defect, not proof of a production UCA leak or a newly reproduced SQL failure.

Fresh evidence and closed portions

I ran the complete documented benchmark matrix with -benchmem -benchtime=100ms, together with all three release tests, on this exact head. All cases pass. Representative UCA sort results were approximately 0.413/1.958/5.563 ms per batch for 8/64/1024-byte cases, with 587,328/3,140,931/14,282,542 B/op; these are consistent with the recorded allocation costs. Legacy/binary prepared sort and shuffle remain allocation-free in the measured paths. The new tests add no production behavior change.

TestUnicodeCollationConsumerContract passes (10.102s); delta whitespace check passes. Earlier PRIMARY/UNIQUE new-authoring fences and supported-subset documentation remain in place. No production source edits were made during review. Full repository/distributed suites, existing experimental-catalog migration and mixed-version rollout were not run. Latest-head CI was still in progress when checked. Maintainer approval and the previously repaired SQL correctness findings are not reopened by this review.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Addressed the P2 release-evidence finding in commit 78a6dcb.\n\nFixture/lifecycle fixes:\n- Sort and shuffle release tests now delete each caller-owned mpool after asserting mp.CurrNB() == 0.\n- Hash release tests now use explicitly owned process/file-service fixtures and delete them per cycle.\n- The hash benchmark creates the process/file-service fixture once outside the timed loop, reuses it across iterations, and cleans it up once after the subbenchmark. The timed region now covers input/operator/hash processing rather than fixture construction and cleanup registration.\n- The updated benchmark matrix was regenerated after this lifecycle change.\n\nScope clarification:\n- The report claims no retained mpool-owned bytes after release.\n- UCA comparison-key/weight scratch is ordinary Go-heap memory, so mp.CurrNB() cannot prove heap retention. The design report now explicitly does not make that stronger claim and calls for a separate heap-lifetime profile before claiming it.\n\nExact-head validation:\n- TestUnicodeCollation(Sort|Hash|Shuffle)ConsumerRelease: PASS (all 16-cycle controls).\n- Consumer benchmark matrix with benchtime=100ms: PASS.\n- git diff --check: PASS.\n\nThe updated matrix and lifecycle methodology are in docs/design/issue-29206-uca400-backend.md under “Exact-head consumer report”.

@daviszhen

Copy link
Copy Markdown
Contributor Author

CI failure resolved by rerunning the failed jobs (run 37881001887, attempt 2).

  • The original Ubuntu/x86 UT failure was limited to the existing pkg/vm/engine/tae/db/test:TestDelete4 case (expected 0x41, actual 0x40), with checkpoint/GC cancellation messages in the same log.
  • PR feat(collation): wire native Unicode CI semantics #29601 does not modify pkg/vm/engine/tae/db/test/db_test.go.
  • Local TestDelete4 passed with -count=100.
  • The rerun completed successfully: Ubuntu/x86 UT passed in 1h16m43s and CI Required passed.

No source change was needed; this was a transient existing TAE test failure.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of ebd9911c3c1bf65d80de09acbc037c6fe479b053 against merge-base c2c1031d0ba4b1034849f6bd3d267252a11eb6c9: REQUEST_CHANGES.

P1 — newly admitted Unicode types lose their revision in composed string expressions. The native identity now requires revision V1, but existing common string type derivation still assigns only Charset. On the exact head, a real single-CN SQL integration probe creates (id INT PRIMARY KEY, s VARCHAR(64) COLLATE utf8mb4_unicode_ci) with (1,'A'),(2,'a'). Each of these predicates fails with 20105: not supported: unknown collation identity/revision 10/0:

WHERE coalesce(s,'x')='a'
WHERE coalesce('x',s)='a'
WHERE case when id=1 then 'a' else s end='a'
WHERE if(id=1,s,'a')='a'
WHERE least(s,'z')='a'
WHERE greatest(s,'0')='a'

The adjacent lower(s)='a' and concat(s,'')='a' controls both return 2. This reproduced in two fresh native runs. commonConditionalStringType updates Charset without CollationVersion; LEAST/GREATEST's width promotion and merged string type similarly rebuild a legacy type and copy only Charset. Complete type derivation must preserve the identity/revision contract together, including the other Charset-only result builders, using the existing type owner. Add real expression-composition regression coverage, including NULL and mixed-width branches; the current consumer integration test only checks LOWER among composed expressions.

Historical comments: the PK restriction/reader admission, IN/NOT IN, invalid-byte separation and mb3 rejection, generic SERIAL round-trip, and sort/window fixes are present. The existing TestUnicodeCollationConsumerContract passed locally at this head (8.50s). All five inline threads remain marked unresolved on GitHub; that UI state is distinct from the verified code fixes. The earlier supported-subset and allocation-cost design requests have substantive answers in the revised document; I am not reopening the approval-paperwork objection.

Design/engineering review covered all 82 changed files and the existing producer/consumer owners. Increment: implementation +1124/-118 (52 files), tests/benchmarks/fixtures +1209/-14 (29), documentation +191/-15 (1). The key/comparison owner and explicit admission guards are preferable to another state machine. The bounded benchmark fixtures and real SQL integration add useful evidence, but miss the type-composition boundary above. A suspected CREATE INDEX/DML key mismatch did not reproduce in either literal or INSERT SELECT public probes: early/late index creation produced the same persisted key and deletion removed both base/index rows; it is not filed as a finding.

Performance: native UCA is materially more expensive than byte comparison. The documented sort cases show roughly 59x at 8-byte/256-row and 230x at 64-byte/256-row with substantial Go allocations; sort recomputes keys per comparison. Hash/shuffle also allocate. The document now exposes these limits and does not claim TP throughput parity; these microbenchmarks do not establish TP or prepared-statement regression numbers. No new evidence justifies replacing the recorded native-cost tradeoff with another approval gate.

Validation: exact-head CI run 37900232172 is successful; local native CGo prerequisites were rebuilt in the isolated worktree. The existing public consumer test passed, while the review-only adjacent-contract probe failed as detailed above. No production changes were made.

Comment thread pkg/container/types/types.go Resolved
@daviszhen

Copy link
Copy Markdown
Contributor Author

Updated the branch with commit 7e7c423fd7e2d7d9679be17e1ddf3b9bddb674a8.

Addressed the P1 by making common string type reconstruction preserve the collation identity and revision together:

  • CASE/IF/COALESCE now retain CollationVersion when merging native Unicode branches, including typed NULL and mixed-width branches.
  • LEAST/GREATEST width-promotion and mixed-string paths use the same metadata owner.
  • Other reconstruction paths were audited and fixed as well: case-conversion, literal-width refinement (REPEAT/SUBSTR/LPAD/RPAD), GROUP_CONCAT, and pure-CHAR set-operation types.
  • Added the shared types.MergeStringCollationMetadata helper, which preserves explicit revisions and repairs legacy zero-valued native Unicode identities to V1.
  • Added unit coverage plus real SQL coverage for COALESCE, CASE, IF, LEAST, GREATEST, typed NULL, mixed widths, and REPEAT.

Validation passed:

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout 300s ./pkg/container/types ./pkg/sql/plan/function ./pkg/sql/colexec/aggexec ./pkg/sql/plan
  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout 300s ./pkg/tests/sqlintegration -run '^TestUnicodeCollationConsumerContract$' -v
  • git diff --check

@daviszhen

Copy link
Copy Markdown
Contributor Author

Re-reviewed exact latest head 7e7c423fd7e2d7d9679be17e1ddf3b9bddb674a8, including the fixture-lifecycle repair, main merge, and composed-string revision fix. Recommendation: approve the documented fenced subset, subject to required latest-head CI. No remaining blocking finding was confirmed in this pass. This is a comment, not a formal review-state change.

Closed findings

  • Consumer fixture/release evidence: sort/shuffle now delete their caller-owned pools. Hash reuses one explicitly owned process/file-service fixture per subbenchmark and releases it at case completion rather than registering cleanup on every iteration. Repeated hash release tests close their fixtures locally. The report now correctly limits the zero-retention claim to mpool-owned bytes and explicitly does not claim a Go-heap lifetime proof. These changes close my previous P2; I am not requesting the stronger heap profile after the claim has been narrowed.
  • Composed string revision: common type construction now carries identity and revision together through the shared type owner. CASE/IF/COALESCE and LEAST/GREATEST rebuilding, GROUP_CONCAT, case conversion, known-width refinement and pure-CHAR set-operation construction were updated. This closes the independently reported revision-10/0 failures in the reviewed composed-expression paths.

Fresh exact-head evidence

  • Targeted types/function/aggregate/planner tests for Unicode/collation/conditional/LEAST/GREATEST/string results pass (1.219s, 1.333s, 1.927s, 2.112s).
  • Updated TestUnicodeCollationConsumerContract passes (11.070s), including NULL/mixed-width conditional cases and revised admission controls.
  • All three consumer release tests and the full 8/64/1024-byte, legacy/binary/Unicode benchmark matrix pass with -benchmem -benchtime=100ms. Measurements reproduce the documented allocation costs. For example, 64-byte/256-row Unicode hash was approximately 0.675ms, 1,145,444 B/op and 10,158 allocs/op; prepared sort/shuffle controls remain allocation-free. Native UCA remains substantially more expensive than byte comparison; no parity claim is made.
  • Independent real-MySQL-client checks on a fresh one-CN embedded cluster pass for COALESCE, CASE, IF, LEAST, GREATEST, REPEAT, SUBSTRING, LPAD, RPAD, GROUP_CONCAT and UNION ALL followed by Unicode equality. On 'A'/'a', ordinary composed predicates match both rows; GROUP_CONCAT matches 'a,a', and UNION ALL matches four rows.
  • The same challenge rechecks PRIMARY/UNIQUE CREATE/ALTER/conversion rejection with actual admission diagnostics, binary UNIQUE behavior, non-unique Unicode index insert/update/delete/reinsert under FORCE/IGNORE hints, and composite CLUSTER BY full/prefix predicates before/after flush. All expected result oracles pass. Hint agreement is not proof of physical index selection for every query.
  • Delta whitespace check passes. No production source edits were made during review.

Scope/limits: this is incremental re-review of the repaired boundaries, not a new exhaustive review of unrelated merged main changes. Native Unicode PRIMARY/UNIQUE support and migration of existing experimental catalogs remain excluded. Full repository/distributed suites, mixed-version rollout, live checkpoint restore and a Go-heap retention profile were not run locally. Latest-head CI is still pending when checked; prior green runs are not treated as current-head completion. The documented semantic/cost contract and supported-subset boundaries remain the landing scope.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE at 7e7c423, merge-base c2c1031. No remaining blocking finding confirmed in the admitted native-Unicode subset.

Reviewed all 90 changed files, including the full implementation, tests and design, and the final delta from my ebd9911 review. The previous composition failure is closed at the shared type owners: CASE/IF/COALESCE, LEAST/GREATEST, aggregate/string return construction and pure-CHAR set operations preserve the selected collation revision. Mixed-width and typed-NULL cases have actual SQL result oracles, not only metadata-helper assertions.

Historical closure: new Unicode PK/UNIQUE definitions and conversions are rejected until storage uniqueness semantics support them; unsafe existing raw-key pruning fails open; IN/NOT IN share the comparison domain; valid UCA keys and invalid-byte fallback cannot alias; typed writes reject invalid UTF-8/mb3 supplementary values; generic SERIAL remains lossless while physical key serialization is explicit; full ORDER BY, TopK and window peers use the semantic comparison type. Physical index bytes cannot escape through covering/index-only paths, and nonunique-index fallback retains the source predicate. These close the earlier inline findings in code; this does not assert that every GitHub thread's UI resolved flag was toggled.

Design/ownership: the existing collation/type, comparison, keycodec, vector, planner and operator owners carry the behavior. No additional cache, background worker or lifecycle controller is introduced. I traced the adjacent persisted-scan concern through table-scan vectors constructed from plan types and block materialization into those destination vectors, then their grouping/shuffle consumers; the read path does not require a second persistent collation store. Unsafe physical shortcuts remain conservatively disabled. Unsupported pre-existing experimental Unicode PK/UK catalogs and mixed-version rollout remain outside the admitted deployment contract.

Evidence reused, with source/oracle inspection: exact-head focused type/function/aggregate/planner tests, the public TestUnicodeCollationConsumerContract, independent SQL composition/DDL/index/cluster-key probes and release/benchmark matrix documented in issuecomment-6078625392; CI Required is now successful in run 37914136069, including the formerly pending checks. git diff --check passed locally. This pass did not rerun the same test/benchmark matrix.

Performance acceptance is explicit, not a zero-cost claim: native UCA comparison/key generation has substantial CPU/allocation cost, including per-comparison sort keys and hash sizing plus encoding. The recorded consumer measurements and lifetime scope address the prior cost-report finding; ordinary legacy/binary paths retain their fast-path controls. No TP throughput or Go-heap-retention benchmark is claimed. The recorded design tradeoff is accepted without reopening it absent a new failure.

Increment assessed separately: implementation 56 files +1157/-134; tests/fixtures 33 files +1330/-14; design 1 file +191/-15. The regression set covers distinct consumers, invalid inputs, physical/semantic representation boundaries, release/reuse and public SQL behavior. No further mandatory validation gap or concretely reachable correctness/resource failure remains from this review.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head 7e7c423fd7e2d7d9679be17e1ddf3b9bddb674a8 against declared base/merge-base c2c1031d0ba4b1034849f6bd3d267252a11eb6c9: REQUEST_CHANGES for one reproduced legacy CHAR ordering regression, detailed inline.

Reviewed all 90 changed files/hunks, the complete previous reviews, inline discussions, author replies and thread resolution state, plus the latest composed-string revision propagation delta. The design/cost report and explicitly fenced native-PK/UK subset were considered; I am not reopening those accepted scope/cost decisions.

Change/closure map:

  • Metadata, DDL/protocol and string-result construction: checked executable identity/revision propagation through casts, conditional expressions and least/greatest.
  • Equality/hash/shuffle and aggregate consumers: checked canonical-key equivalence, NULL handling, tagged invalid-input fallback and typed-write admission.
  • SQL full sort, TopN/merge and window peers: checked comparison/peer relation agreement; this exposes the blocking non-Unicode CHAR counterexample.
  • Physical index writes/probes and reader optimizations: checked separate physical-key versus lossless generic SERIAL contracts, native PK/UK rejection, non-covering fallback and unsafe raw-pruning guards.
  • Tests/design: checked consumer fixtures, release/cost evidence, public SQL coverage and platform evidence.

Unhappy-path audit (changed closures):

Question Closure/evidence
Q1: ownership/cleanup Temporary keys are Go-heap values; retained keys/vectors belong to the existing map/operator owners. Checked copied keys and reset/free paths plus release fixtures. No stronger Go-heap-retention claim is inferred from mpool release checks.
Q2: termination/waits No new worker, RPC, channel wait or cancellation protocol is introduced by these key/metadata/comparison changes.
Q3: growth Checked the documented linear per-value key/scratch bounds and existing retained-state ownership; accepted Unicode allocation/CPU costs are recorded in the design, not assumed to match the bytewise fast path.

Validation:

  • Reused exact-head CI run 37914136069: required gate, Ubuntu UT, arm64 SCA, coverage/shared build, and enabled Compose PESSIMISTIC/PROXY BVT succeeded. Skipped upgrade/other jobs are not claimed as passing.
  • Locally executed TestUnicodeCollationConsumerContract: PASS (8.40s).
  • Added an isolated public-MySQL SQL counterexample, TestReview29601LegacyCharOrderPrefix. On this head it repeatedly FAILS: full order [2,1,3], LIMIT 1 [1]. The identical test on the exact declared base PASSES: full order [2,1,3], LIMIT 1 [2] (9.42s). Thus this is a demonstrated PR regression, not an inferred concern.
  • Both revisions were tested in detached temporary worktrees with the repository CGo/native-artifact guard; git diff --check passed. The main workspace was not modified.

Please make the SQL comparison and peer-partition relations consistent for legacy CHAR too (without changing persisted physical-order contracts), and add this public SQL regression case.

Comment thread pkg/compare/strcompare.go Resolved
@daviszhen

Copy link
Copy Markdown
Contributor Author

Updated PR #29601 at head 9f1cd0a4a66b0323a453cb7d176f43a6fda8764e.

Changes:

  • Merged the latest upstream/main and resolved the function_id.go / function_id_test.go conflict while preserving main's existing UUID_SHORT = 587 allocation. The new internal physical serializer IDs now follow it (PHYSICAL_SERIAL = 588, PHYSICAL_SERIAL_FULL = 589, PHYSICAL_COLLATION_KEY = 590, FUNCTION_END_NUMBER = 591).
  • Kept scalar legacy CHAR comparison semantics unchanged, but added CompareStringOrderValues for SQL ordering consumers. Legacy CHAR therefore remains raw-byte ordered consistently with full sort/partition/TopN; native Unicode collations continue to use their UCA order.
  • Added the reviewer regression for CHAR(4) COLLATE utf8mb4_bin: ORDER BY s,id returns 2,1,3, and ORDER BY s,id LIMIT 1 returns 2.

Validation on the merged head:

  • pkg/container/types, pkg/compare, pkg/sql/plan/function, and pkg/sql/plan: PASS
  • pkg/tests/sqlintegration -run '^TestUnicodeCollationConsumerContract$': PASS

@daviszhen

Copy link
Copy Markdown
Contributor Author

Re-reviewed exact latest head 9f1cd0a4a66b0323a453cb7d176f43a6fda8764e, including the legacy CHAR order repair and main merge. Recommendation: approve the documented fenced subset, subject to required latest-head CI. No new blocking finding was confirmed in this incremental pass. This comment does not change the formal GitHub review state.

The previously reported full-sort/TopN inconsistency is closed. strCompare now uses the SQL ordering comparator: native Unicode retains UCA ordering, while non-native CHAR uses the same byte-order relation as full sort and peer partitioning. Scalar CHAR equality remains unchanged; physical/storage ordering is not expanded into Unicode semantics by this repair.

Independent real-MySQL-client reproduction on a fresh one-CN embedded cluster built from this head:

CREATE TABLE chars(id INT PRIMARY KEY,s CHAR(4) COLLATE utf8mb4_bin);
INSERT INTO chars VALUES(1,'a '),(2,'a'),(3,'b');

Verified results:

  • ORDER BY s,id: IDs [2,1,3]; LIMIT 1 [2]; LIMIT 2 [2,1].
  • ORDER BY s DESC,id DESC: IDs [3,1,2]; LIMIT 2 [3,1].
  • WHERE s='a': count 2, preserving scalar trailing-space equality.

The merged function IDs also remain consistent: main's UUID_SHORT=587 is preserved; physical serializers/key functions use 588–590; the sentinel is 591. Definitions, registration and fixed-ID tests agree.

Fresh validation:

  • Targeted types/compare/function/planner/sort/partition Unicode, CHAR, physical-key and fixed-ID tests: PASS.
  • Updated TestUnicodeCollationConsumerContract: PASS (10.894s).
  • Independent composed-expression checks remain passing for COALESCE, CASE, IF, LEAST/GREATEST, REPEAT, SUBSTRING, LPAD/RPAD, GROUP_CONCAT and UNION ALL followed by Unicode equality.
  • The same client challenge rechecks native PRIMARY/UNIQUE admission/conversion rejection with intended diagnostics, binary UNIQUE controls, non-unique Unicode index DML/result agreement under FORCE/IGNORE hints, and composite CLUSTER BY full/prefix lookup before/after flush. All expected oracles pass. Hint agreement is not proof of physical index selection for every query.
  • PR diff against current base passes whitespace check. No production source edits were made during review.

Earlier supported-subset, composed-type and fixture/cost-report closures remain intact. I did not rerun the unchanged benchmark matrix in this pass; the prior independently reproduced measurements and explicitly limited mpool-only release claims remain the relevant evidence. Native Unicode PRIMARY/UNIQUE support, migration of experimental catalogs, mixed-version rollout, full local repository/distributed suites, and Go-heap lifetime profiling remain outside the evidence claimed here. Latest-head required CI is still running; historical green runs are not counted as current completion.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of exact head 9f1cd0a4a66b0323a453cb7d176f43a6fda8764e against declared base/merge-base 0ccc989731f9c2b40d31554a44ca505c656c0e62: APPROVE for code review. My previous legacy-CHAR ordering blocker is fixed, and no new blocking finding was confirmed. Merge/release remains subject to the repository's required latest-head CI; this approval does not declare pending CI passed.

Scope/history:

  • Read the complete review/comment/thread history, including the new author replies and all seven inline threads. GitHub's unresolved/outdated flags were considered separately from actual code closure.
  • Carried forward the complete 90-file change map from my 7e7c423fd7 deep review, compared the current full PR diff against its new base, read all six changed patch blocks, and checked relevant main-merge interactions. The other 84 file patches retain the reviewed changes.
  • The accepted supported-subset/cost design document is unchanged. Native Unicode PK/UNIQUE authoring, experimental-catalog migration and mixed-version rollout remain outside the supported scope.

Verified repair:

  • strCompare now uses CompareStringOrderValues: ordinary CHAR retains the same raw-byte ordering as full sort and peer partitioning; native Unicode delegates to the existing tagged UCA relation.
  • Scalar CHAR comparison still ignores trailing spaces. This restores base compatibility across sorting operators; it is not a claim that every legacy CHAR/MySQL ordering behavior is standardized by this PR.
  • Function-ID merge closure preserves main's UUID_SHORT=587, assigns physical serializers/key functions 588–590, and sets the sentinel to 591. Constants, name registration, overload registration and fixed-ID tests agree.
  • Rechecked the unchanged historical admission, IN/NOT IN, tagged-invalid-input, mb3-write, composed-revision, lossless SERIAL/physical-key separation, sort/window and conservative reader/index fallback closures.

Fresh local validation at this head, Linux/amd64, Go 1.27.1, normal CGo mode:

  • Rebuilt native prerequisites only in the detached temporary worktree with top-level make -j2 cgo; the guarded wrapper correctly refused stale primary-worktree artifact reuse.
  • Updated TestUnicodeCollationConsumerContract PASS (8.359s), including the committed original counterexample. A review-only extension also passed: ascending full IDs [2,1,3], LIMIT 1 [2], LIMIT 2 [2,1], OFFSET 1/LIMIT 1 [1]; descending full IDs [3,1,2], LIMIT 2 [3,1]; scalar s='a' still matches 2 rows. Those temporary assertions were removed after validation.
  • Nine named focused tests PASS across types, compare, function, sort, hash-partition and shuffle: key/order semantics, plan-type ownership, fixed IDs, physical/generic serialization, and all three Unicode consumer-release checks. Release checks were rerun because the merged base changed mpool accounting.
  • Reused the exact-head author package/planner and adjacent public-SQL evidence within its stated scope after source/oracle inspection; did not rerun the unchanged benchmark matrix or claim TP throughput/Go-heap retention evidence.
  • Current PR and temporary-test diffs pass whitespace/format checks; the main workspace was not modified.

Incremental unhappy-path check:

Q Closure
Q1 ownership No new key/vector owner is introduced by the comparator split. Sort/hash/shuffle release checks pass under the merged allocator; this does not prove general Go-heap non-retention.
Q2 termination The repair adds no worker, wait or cancellation protocol. Existing operator terminal paths are unchanged.
Q3 boundedness Legacy ordering remains allocation-free byte comparison; Unicode delegates to the reviewed per-value key bounds and existing retained-state owners.

Latest-head CI run 38019062185 is still running at review time (Ubuntu UT, arm64 SCA and enabled Compose BVT). Historical green CI is not substituted for current completion; required branch-protection/release gates must finish successfully before merge.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE the documented fenced native-UCA400 subset at 9f1cd0a against declared base 0ccc989. This head is unchanged from my immediately preceding review; required CI is now green.

The implementation direction is appropriate: carry collation identity and revision together, retain generic SERIAL's lossless value contract, and use explicit physical/equality comparison keys. Native Unicode PRIMARY/UNIQUE authoring is rejected until storage dedup/locking can honor that relation. Raw-byte index/probe shortcuts and opaque-key covering projections are conservatively disabled rather than allowed to discard equivalent rows or expose weight bytes as text. Typed invalid/repertoire checks and tagged comparison fallbacks remain separate owners. The latest legacy CHAR repair preserves bytewise SQL ordering consistently with full sort/TopN while leaving scalar trailing-space equality unchanged.

Independent exact-head Linux probe executed the actual types comparison/key/admission helpers. Straße/STRASSE, é/e, A/a and trailing-space cases compare equal and produce equal canonical keys; b/a remains ordered distinctly. utf8mb4 accepts a supplementary character, utf8mb3 rejects it, invalid UTF-8 is rejected, and legacy CHAR retains equality=0 but order=1 for a-space versus a. Read the approved design, core metadata/consumer/index/DML boundaries and regression oracles; no confirmed blocker in those reviewed contracts. Diff whitespace checks pass.

Evidence reuse/limits: the author reports exact-head owning tests and public-session checks across composed expressions, PRIMARY/UNIQUE rejection, non-unique index DML and composite CLUSTER BY predicates before/after flush. The documented consumer measurement/release report supplies the declared bounded-scaling evidence and limits zero retention to mpool-owned bytes. Those SQL/package/benchmark runs were not independently repeated locally; the probe above is my own execution, not a live SQL or restore run. Current required CI, UT/SCA/coverage and proxy/pessimistic BVT are successful. This is not exhaustive certification of every historical collation path or fresh full implementation/restore validation.

Operational caveat: UCA sorting/hashing has substantial allocation and CPU cost compared with byte comparison. The approved contract accepts bounded scaling, not performance parity; Go-heap scratch lifetime is not proved by mpool release counters. Approval does not enable native PRIMARY/UNIQUE keys, migrate experimental catalogs, or establish mixed-version/old-binary rollout or live checkpoint restore support beyond the documented subset.

@mergify

mergify Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-10 06:32 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-10 06:50 UTC · at b89e1e5f8898ebfa0a039cce19c8b1a51e15e7e9

This pull request spent 17 minutes 44 seconds in the queue, with no time running CI.

Reason

Pull request #29601 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — b89e1e5f Deployed Oct 10, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants