Skip to content

fix(plan): preserve enum and set values on delete - #29198

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29188-delete-enum-set
Sep 22, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29188-delete-enum-set

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

Summary

Fixes #29188.

DELETE index maintenance consumed the display VARCHAR projection of ENUM and SET columns, while INSERT stores ENUM ordinals and SET bitmaps. This caused missed deletes, ENUM type errors, and unique-key cleanup failures.

  • Restore the physical ENUM/SET representation at the DELETE old-row boundary using the existing special-type casts.
  • Preserve the raw storage argument from the display wrapper, including empty ENUM labels and empty SET members.
  • Follow unary projection and ordering nodes so ORDER BY/LIMIT uses the same physical value.
  • Add focused planner UT and regular/primary/unique/composite/nullable/ordered SQL regressions.

Validation

  • mo-cgo-test ... ./pkg/sql/plan: pass.
  • go list, go vet, git diff --check, and incremental golangci-lint: pass, 0 issues.
  • Exact mo-tester normal comparison on a clean test-owned service: 95/95 pass, repeated on the same instance; teardown verified with information_schema.
  • Final GPT-6 medium review: APPROVE, no blockers.

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

@XuPeng-SH
XuPeng-SH force-pushed the codex/issue-29188-delete-enum-set branch from d70a42d to adf6d88 Compare September 21, 2026 21:31
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Sep 21, 2026
@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Recommendation: REQUEST_CHANGES

External force review under mo-self-review of head adf6d88ffff0d8436371f2314add7a5b61574003, base/merge-base 020ab74ec87fba141e50645231ccf212cd1da157. Both still match GitHub. All four files and every changed hunk reviewed. CI readiness was not a gate. This is a comment only because the PR is self-authored.

One blocker — P2: the physical old-row boundary is fixed only in the modern DELETE planner.

The new call at bind_delete.go:298 is bypassed by multi-target DELETE, FK fallback, and non-RETURNING irregular-index fallback. buildDelete binds and materializes the display projection without normalization. makePreUpdateDeletePlan subsequently assigns the declared ENUM/SET type to a column reference, but that does not convert the vector: ColumnExpressionExecutor.Eval forwards it. Thus legacy index maintenance still receives VARCHAR values where it requires stored ordinals/bitmaps. Serialization dispatches on the actual vector type, so display-text keys do not match the inserted physical keys; typed ENUM consumers can also encounter the mismatched vector.

Exact-head diagnostic: using the existing planner fixture with dept.dname ENUM('a','b') and its matching unique-index type, DELETE FROM constraint_test.dept WHERE deptno=1 produces physical ENUM. DELETE d,x FROM constraint_test.dept d JOIN constraint_test.docs_ft x ON d.deptno=x.id WHERE d.deptno=1 instead produces cast_index_to_value(...) and a source SINK column of type 61 (VARCHAR), followed by a column reference labeled type 66 (ENUM). An isolated Go overlay assertion requiring physical ENUM fails on the multi-target case and passes the single-target control. No tracked source was edited. This proves the planner contract violation; I did not rerun this witness through a SQL service. It is an incomplete fix of the existing bug, not a regression introduced by the helper.

Normalize the legacy DELETE source before its first materialization too, preserving raw storage arguments and ordered projections, and add a public fallback-path regression that verifies index cleanup/key reuse.

Coverage and validation:

  • Modern path traced through raw ENUM/SET preservation, empty/zero and NULL behavior, unary/ORDER BY/LIMIT projections, joined-row DISTINCT, RETURNING, regular/unique/composite index keys, PK locks, partition routing, and main/index delete consumers. SET primary/unique keys remain rejected by DDL. No additional blocker found in those closures.
  • Ordinary bug fix: design-document gate exempt; R2 representation/consumer contract. Traversal state is per-call, cycle-checked and removed on unwind; no new asynchronous owner, wait, or runtime resource lifecycle was introduced.
  • Exact-head owning package: .agents/skills/mo-dev/scripts/mo-cgo-test -mod=readonly -count=1 -timeout 300s ./pkg/sql/plan passed, exit 0, package 5.068s. Diff whitespace check passed. Diagnostic overlay failed with expected ENUM 66 / actual VARCHAR 61, exit 1.
  • Inspected historical mo-tester report: enum_index_update.sql, 95/95, and author ledger recording same-instance repeat/teardown. SQL/result and production fix are unchanged from the earlier delivered commit; this is supporting historical evidence, not a newly executed exact-head BVT run.
  • Remaining validation gaps: public fallback-path cleanup; actual deletion of NULL rows (new cases only retain NULL survivors); ENUM zero/empty-label and SET zero deletion; special-type joined/RETURNING execution. Existing composite coverage is secondary, not a new composite-unique/primary regression. These gaps are separate from the concrete legacy-path blocker above.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Implemented the P2 on 4b8e5d91d607bb824ec97f7c7fa569d016a9708b.

  • deleteToSelect now returns the actual source-column positions for each DELETE target.
  • Legacy buildDelete normalizes ENUM/SET old values before appendStep, query creation, or sink materialization, covering multi-target and unsupported fallback paths without changing downstream UPDATE/REPLACE consumers.
  • Added a planner regression with reversed target/source order covering ENUM and SET storage expressions. It fails without the legacy normalization call and passes with it.
  • Added a public multi-target DELETE BVT covering ENUM unique-index cleanup and key reuse.

Validation: full pkg/sql/plan CGo tests, go vet, incremental golangci-lint, and git diff --check pass. The new public BVT has not been locally executed against an exact-head service; the supplied IDC kubeconfig did not load a valid client key, so I am not claiming a local BVT pass. Required CI for the new head is pending.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Force-again review (gpt-6-astra medium, exact head 4b8e5d9).\n\nRecommendation: REQUEST_CHANGES.\n\nThe previous legacy-path production blocker is closed: buildDelete now normalizes before appendStep, optimization, and SINK materialization, so multi-target, FK, and non-RETURNING irregular-index fallback paths reach the physical ENUM/SET boundary. Consumer tracing found no additional production-code blocker; ordinal/bitmap preservation, zero/empty labels, NULL handling, unary/ORDER BY/LIMIT, joined deduplication, RETURNING, PK/regular/unique/composite index consumers are aligned.\n\nOne validation blocker remains: the new public multi-target cleanup/key-reuse BVT has not successfully run against this exact head. Historical 95/95 evidence predates this fix and does not prove the legacy path. Please provide a successful normal-comparison run of the updated public case, including teardown and same-instance repetition, or qualifying exact-head CI evidence. Pending CI is not treated as correctness proof.\n\nAdditional non-blocking coverage gaps to consider: actual NULL-row deletion, ENUM zero/empty-label and SET-zero execution, special-type FK/irregular fallback and joined RETURNING, and dedicated composite primary/unique cleanup cases.\n\nExact-head pkg/sql/plan CGo tests passed; diff whitespace is clean. This is COMMENT-only because the PR is self-authored.

@XuPeng-SH
XuPeng-SH merged commit 1a24bdb into matrixorigin:main Sep 22, 2026
28 checks passed

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DELETE cannot maintain ENUM/SET keys and either skips rows or returns internal type errors

2 participants