Repository navigation
Description
Why do you want to refactor this code?
A shutdown upgrade must preserve what users can read from an existing ENUM column. On v4.2.8, both ENUM('a,b','c') and ENUM('a','b','c') produce the same catalog string. The released reader can store and display 'c' at ordinal 3. Reconstructing the two-member declaration from the saved CREATE SQL would change existing data. In a new two-member declaration, 'a,b' must be one label and 'c' must have ordinal 2. v4.2.8 writer · v4.2.8 reader
The branches have diverged. After #32723, 4.2-dev chooses between two encodings for new definitions based on the labels. main still joins them with commas. This issue tracks the branch work needed to ship one durable definition and preserve released data. The existing behavior reports remain useful for their SQL reproductions. 4.2-dev writer · main writer
Describe the solution you'd like
Shared contract
- Keep the row value as a
uint16ordinal. For every newly declared ENUM, write one explicitly tagged, byte-length-delimited list in declaration order. Reuse the existing type metadata slot and catalog payload. Keep the existing 16-byte native and 20-byte marshaled type layouts unchanged in size. Publish and copy the tag and payload together. Reject unknown tags and malformed lengths before using the definition. - On opening a released v4.2.8 column, use its original member boundaries, ordinal mapping and lookup rules, including historically distinct padded labels. A metadata copy or unrelated ALTER must preserve that interpretation. Startup requires no user-table rewrite. A user-requested change of ENUM members or collation goes through the normal ALTER conversion. Unreleased branch snapshots impose no migration or mixed-version RPC requirements.
- For new declarations, resolve the effective column collation and trim trailing ASCII spaces from declared labels once during DDL. Use the same collation semantics for duplicate detection and label assignment. Persist the effective identity with the column. Keep the encoding tag and the collation identity distinct. Ordinary assignment between different domains resolves the source label in the target domain. A physical copy may reuse ordinals only when their meanings are preserved.
Work on 4.2-dev
- Simplify the ENUM portion of [4.2-dev] fix SDK contracts and exact ENUM member replay #32723. Keep its explicit tag, length-delimited codec and legacy reader. Route every new ENUM declaration through the one new writer. Keep the legacy path for released catalog data and persisted expressions. Preserve unrelated changes already merged in that PR.
- Narrow fix(enum): resolve assignments in the destination domain on 4.2-dev #32824 to the fix for [4.2] ENUM assignment collapses case-distinct members under binary collation #32814. Carry the effective collation through DDL, catalog reopen, prepared and bulk writes, and ALTER COPY. A transfer from binary
ENUM('A','a')to binaryENUM('a','A')must store'A'at ordinal 2 and'a'at ordinal 1. Keep independently reproducible dump, recovery and table-default changes separately reviewable. - Validate the next 4.2 build against a data directory and backup created by the released v4.2.8 binary. Retain a small fixture from the final 4.2 writer for the main-branch check.
Work on main
- Adopt the same new writer, tag values, legacy reader and collation identity as
4.2-dev. Consolidate the DDL portion of fix(enum): trim trailing spaces from ENUM labels like MySQL #32885 with the assignment portion of Fix ENUM identity and physical index serialization #32826. Keep the useful Fix ENUM and SET assignment compatibility with MySQL #30683 behavior for numeric input and strict/IGNORE diagnostics. Use an existing column definition as the source of truth for scalar, prepared and vector execution. - Isolate the physical index fix in Fix ENUM identity and physical index serialization #32826. Index backfill on existing rows and index maintenance on later writes must produce identical physical keys and retain the original primary key. Exercise both paths on the same values.
- Use the effective column collation in fix: respect ci collations in ENUM/SET comparisons #32874 for ENUM text predicates such as
=andIN, including through projections. Binary and case-insensitive columns need distinct controls. Keep SET-specific behavior under its existing issue, [Bug]: ENUM/SET comparisons are case-sensitive under ci collation #31364. - Verify that main reads both the released v4.2.8 fixture and the fixture written by the final 4.2 implementation. Compare visible label bytes, numeric ordinals and subsequent assignments.
Describe alternatives you've considered
Inferring the format from a string prefix is ambiguous because old labels may contain those exact bytes. An eager upgrade from saved CREATE SQL can reinterpret rows whose original declaration is already unrecoverable from the catalog. Keeping two writers for newly declared columns makes lookup and replay depend on which characters occur in a declaration. The explicit tag lets both readers select the right interpretation at the column-definition boundary. Existing format and collision example
Additional information
Acceptance checks for both branches
- On v4.2.8, record
HEX(CAST(e AS CHAR))ande+0before shutdown for the comma example above and for both members ofENUM('a ','a'). Compare after upgrade, restart and physical restore. Repeat the old assignments. This catches silent reinterpretation even when two displayed strings look alike. - For fresh DDL, round-trip a comma-bearing member, a singleton empty member, a trailing ASCII space and a binary case-distinct pair. Distinguish a valid empty label at ordinal 1 from the error member at ordinal 0. Check one case-insensitive duplicate under the supported SQL mode. Check reordered-domain assignment through a prepared parameter and an INSERT ... SELECT. Verify strict errors and IGNORE warnings.
- Measure single-row prepared writes, small batches and bulk label lookup/display under identical conditions against each branch baseline. Report time and allocations by workload. A fixed definition should decode at most once per batch, with no per-row splitting or trimming of stored labels. Investigate any repeatable regression in ordinary ENUM workloads before release.
Related behavior is tracked in #30771, #32814, #31893 and #31364.
Activity
[4.2-dev] Preserve ENUM definitions across schema rebuilds and honor …
fix(enum): resolve assignments in the destination domain on 4.2-dev (#…