Skip to content

[Refactoring]: Unify ENUM definitions on 4.2-dev and main while preserving v4.2.8 ordinals #32886

Open

Description

@XuPeng-SH

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 uint16 ordinal. 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

Work on main

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)) and e+0 before shutdown for the comma example above and for both members of ENUM('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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions