Skip to content

fix(enum): trim trailing spaces from ENUM labels like MySQL - #32885

Merged
fengttt merged 11 commits into
matrixorigin:mainfrom
fengttt:fix-enum-trailing-space-labels
Nov 19, 2026
Merged

fengttt merged 11 commits into
matrixorigin:mainfrom
fengttt:fix-enum-trailing-space-labels

Conversation

@fengttt

@fengttt fengttt commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Ref #30538 (follow-up: #30683 fixed the value side; this fixes the label side)

What this PR does / why we need it:

MySQL removes trailing spaces from ENUM members at CREATE TABLE and rejects members that are duplicates after that. MO stored labels verbatim, so ENUM('a ','b') kept "a ", and only the exact input 'a ' matched it: 'a' and 'a ' were rejected (strict) or truncated to 0.

labels input before after (= MySQL)
'a ','b' 'a' 0 / error 1
'a ','b' 'a ' 0 / error 1
'a','b' 'a ' 1 1

Changes

  • DDL (build_util.go): new types.NormalizeEnumValues trims trailing ASCII spaces from labels and rejects members equal case-insensitively after trimming (duplicate enum member), mirroring the existing NormalizeSetValues. Leading spaces, NBSP and tabs stay significant.
  • Lookup (types.ParseEnum and the batch enumValueIndex in func_mo.go): one pass comparing with trailing spaces trimmed on both sides, so tables created before this change with padded labels also match. Both paths keep identical semantics.

Behavior change for legacy definitions: a table created earlier with labels equal after trimming (e.g. ENUM(' ','red','') from the #29840 test, which MySQL rejects) now resolves both ' ' and '' to the first such label. Already-stored rows are unchanged. Tests that pinned the old raw-first matching were updated accordingly.

Tests

  • New: TestNormalizeEnumValues, TestEnumDDLRejectsMembersEqualAfterTrim, ENUM cases in TestEmptyDomainTypeReplay (DDL → format → replay round trip).

  • Updated: TestEnumAssignmentParsing, TestEnumValueIndexAssignmentBoundaries (covers both linear and indexed paths), TestMySQLSpecialOrderProvenanceRejectsNonReversibleEnum, two external LOAD tests.

  • BVT load_data/issue_29840_load_empty_enum_set.sql: its table used ENUM(' ','red',''), now invalid DDL; switched to ENUM('red','') and added a statement asserting the duplicate DDL is rejected.

  • Unit tests pass locally for pkg/container/types, pkg/sql/plan, pkg/sql/plan/function, pkg/sql/colexec/external, pkg/sql/compile, pkg/frontend.

  • BVT: regenerated .result for load_data/issue_29840_load_empty_enum_set (member indexes shift; duplicate DDL rejected) and dtype/enum (padded labels now trimmed, so their display, length, reverse, concat, rpad and find_in_set results follow). Ran all 71 BVT case files that use enum( against a dev cluster built from this branch: 0 failures.

🤖 Generated with Claude Code

MySQL removes trailing spaces from ENUM members at CREATE TABLE and rejects
members that are then duplicates. MO stored labels verbatim, so a padded
label such as 'a ' only matched the exact input 'a ' -- 'a' and 'a  ' were
rejected or truncated.

- DDL: NormalizeEnumValues trims trailing spaces and rejects members equal
  case-insensitively after trimming, mirroring the existing SET rules.
- Lookup: ParseEnum and the batch enumValueIndex compare with trailing
  spaces trimmed on both sides, so tables created before this change with
  padded labels also match. For legacy definitions whose labels are equal
  after trimming, the first such label wins.

Ref matrixorigin#30538

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 →

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Nov 18, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Nov 18, 2026
@mergify

mergify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

fengttt and others added 2 commits November 17, 2026 20:38
dtype/enum declares labels with trailing spaces, which are now trimmed at
CREATE (display, length, reverse, concat, rpad and find_in_set follow);
issue_29840 now uses ENUM('red','') and asserts the ' '/'' duplicate DDL is
rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fengttt

fengttt commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the three findings from the review in b9efb06 (plus a comment-only follow-up dadd264).

P2 build_util.go: LIKE / CLONE of a legacy ENUM(' ','red','') fails. When LIKE/CLONE/COPY replays a column whose rendered ENUM labels exactly match the domain it already stores, the domain is kept verbatim. CREATE-time trimming and duplicate checks are skipped (replayedEnumDomainUnchanged → rawEnumDomainKey). New declarations and changed columns are still normalized. Snapshot/PITR restore goes through the same CLONE planner, so it is covered too.

  • Tests: TestCreateTableLikePreservesLegacyPaddedEnumDomain (end-to-end LIKE through BuildPlan) and TestEnumReplayPreservesLegacyDomain (replay keeps the domain; a new or changed declaration is still normalized or rejected). The LIKE test fails without the fix with duplicate enum member "".

P2 enum.go:159: '' silently reassigned to the space member. Lookups again follow the released precedence, in both types.ParseEnum and the indexed enumValueIndex path:

  1. the raw value against raw labels;
  2. the value without trailing spaces against raw labels;
  3. only then, padded stored labels compared trimmed.

On ENUM(' ','red',''), '' → 3 and ' ' → 1 again. I restored the released expectations in enum_test.go, enum_set_assignment_test.go ("a ,a": a/a → 2), enum_set_csv_boundary_test.go and enum_set_empty_test.go.

  • New test: TestEnumValueIndexLegacyPaddedLabels, on both the linear path and the indexed (8 labels / 64 rows) path.
  • Domains created after this change have no padded labels, so step 3 never applies to them, and the LOAD/dtype BVT expectations stay unchanged.

P2 enum.go:174: ENUM('Σ ','ς') accepted but ς is unselectable. CREATE-time duplicate detection now keys on util.EqualFoldKey, the same equivalence as strings.EqualFold used at assignment, so the pair is rejected. Covered by {"Σ ", "ς"} and {"K", "K"} in TestNormalizeEnumValues.

Local runs: pkg/container/types, pkg/sql/plan, pkg/sql/plan/function/... and pkg/sql/colexec/external all pass.

@mergify

mergify Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

queue

🛑 The queue request has been cancelled: new commits were pushed

Details

@fengttt pushed to this pull request after queue was requested. Review the new commits and request it again.

TestArenaPoolCountCap crashed in CI with "reset of synctest timer from
outside bubble": TestArenaBurstReleasedWhileStillActive frees arenas inside
a testing/synctest bubble, which armed the global SimpleCAllocator mmap
cache timer in that bubble, and a later free outside it called
timer.Reset on put.

expire already re-arms the timer from lastPut, so put only needs to record
lastPut. The idle deadline is unchanged, the free path no longer touches
the timer, and only the arming goroutine or the timer's own callback
operates on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XuPeng-SH

XuPeng-SH commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 07a92eb9fd169618c7c75cb7f959c7c32c484532

"interrupted"

@fengttt
fengttt merged commit 3cd5f71 into matrixorigin:main Nov 19, 2026
XuPeng-SH added a commit that referenced this pull request Nov 20, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #32951
Fixes #32946
Fixes #32893
Fixes #32953
Fixes #32956

Related to #32952, #32954, #32955, #32745 and #32885. The first three
issues stay open for Linux confirmation of tenant cleanup, a
duration-neutral batch deadline fix, and diagnosis of the remaining
embedded and multi-CN failures.

## What this PR does / why we need it:

- Seed the virtual-clock arena test with small buffers tracked by the
arena memory pool. This keeps it on the real arena list and reaper path
without installing a timer in the process-wide mmap cache.
- Preserve the caller's cancellation cause throughout WAL record reads,
including client checkout and retry backoff. Keep transient retries and
the closed-pool error.
- Choose a session offset distinct from the process offset in the
frontend temporal test without writing the global timezone.
- Consolidate tenant cleanup into one DROP ACCOUNT, which also removes
the tenant source database. Retain the two-minute account cleanup
timeout already on main from #32885. Four CI runs showed five tenant
cases timing out at the 20-second account cleanup after their progress
assertions. Both tenant scenarios retain their COPY, lock, and data
assertions.

- Preserve physical offsets when writing the snapshot of an old
appendable data object. Rows without an eligible append node remain
invisible placeholders so a reader that holds an existing RowID still
reaches the same value after the in-memory object is replaced by its
persisted snapshot. Ordinary logtail range collection stays dense.
- Record the remaining Go test budget when a race batch starts. Keep the
shared 40-minute budget, existing process pool and 120-minute outer UT
watchdog.
- Stop dependent LOAD statements after a pinned session fails and retain
the existing shared SQL deadline. Run role-policy tenant cleanup through
the admin pool, and check account absence only after a successful drop,
within the existing SQL timeouts. Failed shared generations still retire
through their current owner.
- Enable the breaker in the morpc regression and assert the open-circuit
error and nil backend. Remove the 20 ms wall-clock assertion.

Validated on Go 1.27.1 with the full frontend, objectio and WAL driver
packages under race, the complete scalar refresh regression under race,
the affected timezone regression with a non-UTC process timezone, and
incremental formatting, vet and lint checks. The linked Linux CI runs
establish the original failures.

The additional changes passed the full morpc, TAE tables and append-MVCC
packages under race, the focused TAE flush and TestDelete4 cases, the
role-policy and LOAD fixtures under race, and the UT scheduler harness.
The sparse snapshot regression fails with the old code and passes after
the fix. A separate local run replayed WAL after restart and reproduced
the old panic before checking the fix. The unit test also covers modern
and legacy layouts. Targeted local coverage exercised all 16 changed Go
production blocks counted by the CI parser. A cold Linux runner can
still reach the independent outer UT deadline.

---------

Signed-off-by: XuPeng-SH <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — bf6704ff Deployed Nov 19, 2026 by fengttt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants