Repository navigation
fix: respect ci collations in ENUM/SET comparisons - #32874
gouhongshen wants to merge 2 commits into
Conversation
Preserve ENUM/SET collation identity through DDL, expression binding, subqueries, CTEs, compatible set operations, and grouped references. Rewrite equality-family string predicates with a ci equality key while retaining binary, numeric, NULL, CAST, LIKE, and assignment semantics. Separate logical SET metadata from physical uint64 vector transport. Add focused planner regressions and a 182-statement public BVT fixture. The primary regression fails on the assigned base and passes after the fix; the final planner package, build, vet, static checks, and two BVT runs pass. Related to matrixorigin#31364
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? |
|
This pull request is closed, so it cannot be queued. Reopen it to get the box back. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 6ee34e6bbe31977297f5ec042d060ee3b71ea8d0
Assessment: request_changes
The patch fixes the reported case-insensitive ENUM and SET comparisons and keeps comparison provenance separate from storage ordering. Three correctness gaps remain. Schema copies drop column collations, mixed IN lists lose existing numeric matches, and legacy recovery can mistake a later table default for the original column collation. The cross-component change also requires a versioned design that covers these contracts.
Model: gpt-6.2-sol / xhigh
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
-
P1
pkg/sql/plan/build_util.go:605: Run SHOW CREATE TABLE or CREATE TABLE LIKE on a table whose ENUM or SET column collation differs from the table default.
Impact: The generated DDL drops the column override. A clone silently adopts the table default and can return different rows for the same data and predicates.
Evidence: The binder now stores the column collation, but the shared formatter at pkg/sql/plan/build_show_util.go:953 skips ENUM and SET. CREATE TABLE LIKE reparses its output at pkg/sql/plan/build_ddl.go:3019. The MySQL-protocol probe reproduced both directions. Case-insensitive columns changed from 1,1 to 0,0 and binary columns changed from 0,0 to 1,1 in schema.jsonl. Preserve effective ENUM and SET collations through the shared DDL formatter and replay path. -
P2
pkg/sql/plan/mysql_special_collation.go:255: Compare an ENUM display label such as '01' against a mixed list such as IN ('0', 1) under utf8mb4_general_ci.
Impact: An existing match disappears because the integer arm becomes a string comparison against '1'.
Evidence: The same MySQL-protocol probe returned 1 with the merge-base production code and 0 at the candidate head, in both list orders. Pure numeric ordinal and ordinary string controls were stable. The list rewrite converts numeric members to VARCHAR before the mixed comparison owner at pkg/sql/plan/base_binder.go:6594 can apply numeric coercion. Apply collation keys to string comparisons while preserving the existing numeric arm and NULL semantics. -
P2
pkg/sql/plan/legacy_mysql_special_collation.go:86: After upgrading a 4.2 table whose stored CREATE omitted collation, change its table default to utf8mb4_general_ci without converting its existing columns.
Impact: A default-only ALTER can make subsequent queries compare existing ENUM and SET labels case-insensitively even though the columns were never converted.
Evidence: The v4.2.8 catalog retained CREATE SQL and table identity without a durable collation default. The current default-only ALTER updates the table default in place. The planner probe exercised that ALTER and then recovery, which changed both column identities from 0 to 3 at schema version 1. Equal physical and logical IDs do not establish the original default. Recover inherited collation only when creation-time evidence supports it, and retain legacy behavior otherwise. -
P2
pkg/sql/plan/mysql_special_collation.go:60: The change introduces durable ENUM and SET collation semantics across catalog recovery, DDL replay, planner provenance, and vector transport.
Impact: The repository's required design artifact is missing for the new ownership and compatibility rules. The schema-copy and legacy-default failures show concrete gaps at those boundaries.
Evidence: The change touches 965 non-generated production lines. The scope triggers .agents/skills/mo-dev/references/feature-design-review.md:22 and :38 through its size, persistence changes, and cross-component ownership. The frozen submission contains implementation and test summaries but no linked versioned design. Supply the applicable design revision and close the DDL round-trip, legacy authority, and comparison coercion contracts together.
Validation:
-
Isolation preflight, frozen patch verification, diff --check, and native input verification passed. Receipts 1794956702959427454-2.json and 1794956736172013020-2.json.
-
Focused collation, type, vector, plan, compile, and embedded SQL tests passed. Additional cache, tuple-comparison, and function-registration controls passed. See candidate.jsonl and boundary-tests.jsonl with receipts 1794957122877667720-2.json and 1794957392081615076-2.json.
-
The public SQL probes reproduced the schema-copy failure and the mixed-list regression against the verified merge-base overlay. See schema.jsonl, base.jsonl, and candidate.jsonl with receipts 1794957275958140924-2.json, 1794957276008487601-2.json, and 1794957122877667720-2.json.
-
The legacy planner probe failed the default-only ALTER invariant. See legacy-default.jsonl and receipt 1794957367162875784-2.json. The evidence audit matched all seven receipts to retained logs and verified complete discussion coverage.
Limitations:
- The legacy probe exercised the planner with a 4.2-shaped catalog fixture. A full stopped upgrade and the distributed BVT suite were not rerun locally. The author's BVT result checksum matches the frozen fixture, but raw logs for the reported runs were unavailable.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #31364
What this PR does / why we need it:
ENUM and SET string comparisons under
general_ci/unicode_cican reach byte-sensitive equality because their declared collation is lost during planning. This PR makes ci ENUM case variants and ci SET member lists compare using the source column collation. For example,e = 'RED'matches storedRed, ands = 'A,B'matches storeda,b; binary collations remain case-sensitive.Root causes
ProjectionBinderreplaced grouped expressions withColRefs whose storage-order resolver rejected explicitCOLLATEadapters.uint64vector transport so remote batch admission retained the logical type without corrupting its physical representation.Exact changes
=,<=>,!=/<>,IN, andNOT INstring comparisons through an internal helper undergeneral_ci/unicode_ci.LIKEsemantics. Register the helper as non-zonemappable.COLLATEwrappers through context-aware scalar and derived provenance, including explicit-ci overrides on binary sources, while retaining arbitraryCASTcoercion boundaries.IN/NOT INoperands and carry bounded statement-local metadata through derived bindings.CorrColRefprovenance by walking exactlyCorrColRef.Depthbinder-owning lexical parents and reconstructing the owning relation/column identity there, covering direct, derived, and nested correlated predicates.COLLATEadapters and arbitrary-CASTboundaries without changing grouping semantics.uint64vectors after plan validation, retaining fail-closed raw decoding and ordinaryuint64admission checks.test/distributed/cases/charset_collation/issue_31364_enum_set_comparison.sqlBVT fixture with independently checked results.Issue-to-test proof
7fcd9bdff8433d72983f0399fd5c10dcab91a00a, real SQL returned zero rows for the reported ci ENUM case variants and ci SETA,B; exact-case controls still matched. The primary planner regression also failed on that base. After the change, the ci predicates return the expected rows while binary and SET member-order controls retain their results.IN,<=>,!=,NOT IN, explicitCOLLATE, Unicode-ci, derived columns,LIKE, member order, and assignments. Scalar/materialized/dependent-subquery and legacy-recovery regressions provide their own red/green evidence.CAST/ordinary-string controls. The identical selection passes all 21 cases after the repair; its expanded 17-case CTE/set-operation selection also passes compatible multi-branch and mixed-collation negative controls.UNION ALLmatches with row multiplicity preserved, explicit-ci overrides on binary sources, and zero matches for explicit-binary/arbitrary-CASTcontrols.TestMySQLSpecialPhysicalVectorCollationandTestUnicodeSetRemoteBatchAdmissionfailed before the logical/physical boundary repair and passed afterward; native catalog controls passed. That transport code is unchanged in the final planner repair.44175407291completed PASS against the current source: all eight current regressions passed, including the exact reproduction and all 28 supported advanced assertions, with no coverage gaps and clean database audits. The retained historical exploratory nested-left quantifiedINform reaches the pre-existing ERROR 20105 restriction; this PR does not change that unsupported form.Validation commands and results
Assigned-base red reproduction (expected exit 1):
mo-cgo-test -mod=readonly -v -count=1 -timeout=5m \ -run '^(TestBuildCreateTablePreservesEnumSetCollation|TestEnumSetStringComparisonUsesColumnCollation)$' \ -o /tmp/issue-31364-red/plan.test ./pkg/sql/planOriginal fixed comparison/recovery selection (exit 0; all recovery/admission tests and 29 comparison subtests passed):
mo-cgo-test -v -count=1 -timeout=180s \ -run '^(TestBuildCreateTablePreservesEnumSetCollation|TestRecoverLegacyEnumSetCollation|TestUnsupportedLegacyEnumSetIdentityDoesNotBlockTinyText|TestRecoverLegacyEnumSetCollationRejectsStaleEvidence|TestUnicodeEnumSetInsertPlanAdmission|TestEnumSetStringComparisonUsesColumnCollation)$' \ -o /tmp/issue-31364-red/plan.test ./pkg/sql/planFinal pre-repair red and post-repair green focused selection (red exit 1 with 12 discriminating failures; green exit 0 with all 21 cases passing):
mo-cgo-test -mod=readonly -v -count=1 -timeout=300s \ -run '^(TestEnumSetCTEAndSetOperationComparisonUsesColumnCollation|TestEnumSetGroupedComparisonUsesColumnCollation)$' \ -o /tmp/issue-31364-review-r4-red/plan.test ./pkg/sql/planExpanded compatible/mixed-collation selection (exit 0; all 17 cases passed):
mo-cgo-test -mod=readonly -v -count=1 -timeout=300s \ -run '^TestEnumSetCTEAndSetOperationComparisonUsesColumnCollation$' \ -o /tmp/issue-31364-review-r4-derived/plan.test ./pkg/sql/planFinal planner package (exit 0,
ok 194.191s):Final build and static validation (all exit 0;
go vetused the repository's documented CGo environment; selected molint and golangci-lint reported zero issues):Public result generation (exit 0; independent result checking passed and final result SHA256 is
c2824c9ea799c676ed16ff55551b24c23401d492dd34d507f60b0dc45ae91549):java -Xms1024M -Xmx1024M \ -cp '/Users/ghs-mo/MOWorkSpace/mo-tester:/Users/ghs-mo/MOWorkSpace/mo-tester/lib/*' \ io.mo.Tester \ path=/Users/ghs-mo/MOWorkSpace/tmp/issue-fix/issue-fix-loop/state/worktrees/issue-31364-main-8e482b24/test/distributed/cases/charset_collation/issue_31364_enum_set_comparison.sql \ method=genrs rate=100 ignore nometa pprofNormal public BVT (the same command with
method=runwas executed twice from isolated mo-tester working directories against the owned service; both exited 0 withtotal=182 success=182 failed=0):java -Xms1024M -Xmx1024M \ -cp '/Users/ghs-mo/MOWorkSpace/mo-tester:/Users/ghs-mo/MOWorkSpace/mo-tester/lib/*' \ io.mo.Tester \ path=/Users/ghs-mo/MOWorkSpace/tmp/issue-fix/issue-fix-loop/state/worktrees/issue-31364-main-8e482b24/test/distributed/cases/charset_collation/issue_31364_enum_set_comparison.sql \ method=run rate=100 ignore nometa pprofSupporting earlier-revision owning-package and race evidence for unchanged components (all exited 0; these are supporting evidence for this final revision):
Final delivery checks also passed:
gofmt -lreported no files,git diff --checkexited 0, and the complete 35-file patch matched the independently approved patch byte-for-byte with SHA2563a1537e85913916fab7f85d23d84a6db3fe46747bab3744cb0ba75f5e334b3c7.Residual risks and limits
ORDER BY,BETWEEN, grouping,DISTINCT, CTE materialization policy, incompatible-source set-operation coercion, and assignment validation retain existing semantics.CASTexpressions retain their existing coercion boundary, and the existing nested-left quantified-subquery ERROR 20105 restriction remains unchanged.mo_loggerstatement_infoflush after SIGTERM began.