Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Actual Behavior
DELETE cannot correctly maintain keys whose storage type is ENUM or SET:
- with a regular secondary index on an
ENUMorSETcolumn, a matchingDELETEsilently reports 0 affected rows and leaves the base row unchanged; - with an
ENUMprimary key,DELETEreturns an internal panic stack because aVARCHARvector is consumed as[]types.Enum; - with an
ENUMunique key,DELETEfails withinvalid argument cast to uint16.
The secondary-index case reproduces 3/3 on CN1, 3/3 on CN2, and 3/3 through Proxy. It is independent of JDBC: the same behavior occurs in a minimal SQL session.
This also makes ordinary Spring Data JPA entity deletion fail as an optimistic-lock conflict. Hibernate issues DELETE ... WHERE id=? AND version=?, receives affected row count 0, and raises ObjectOptimisticLockingFailureException even though the row and version both exist.
Steps to Reproduce
Secondary ENUM index silently prevents DELETE
create database enum_delete_repro;
use enum_delete_repro;
create table t (
id int primary key,
e enum('A','B','C'),
index ix(e)
);
insert into t values (1,'A'),(2,'B'),(3,'C');
delete from t where id=3;
select row_count(), count(*) from t;Actual result:
row_count() count(*)
0 3
Replacing ENUM with SET('A','B','C') produces the same result.
ENUM primary key returns an internal panic
create table pk_t (
e enum('A','B') primary key,
v int
);
insert into pk_t values ('A',1),('B',2);
delete from pk_t where e='B';Actual error:
internal error: panic type mismatch: casting VARCHAR vector to []types.Enum
ENUM unique key returns a cast error
create table uk_t (
id int primary key,
e enum('A','B','C') unique
);
insert into uk_t values (1,'A'),(2,'B'),(3,'C');
delete from uk_t where id=3;Actual error:
invalid argument cast to uint16, bad value C
Expected Behavior
All three DELETE statements should remove exactly one row and return affected row count 1. Index maintenance must use the same typed representation that INSERT used to create the index key.
Code and physical-key analysis
For an inline regular index on ENUM, INSERT stores the enum ordinal in the hidden serialized key. For example, C is stored using its numeric ordinal. During DELETE, pkg/sql/plan/bind_delete.go builds serial_full directly from the scan projection, whose ENUM/SET value is the display VARCHAR. The generated label-based key does not equal the ordinal-based hidden key, so the INNER JOIN used by Multi Update removes zero rows.
The current UPDATE binder already contains an explicit fix for this representation boundary: pkg/sql/plan/bind_update.go casts old ENUM/SET display values back to their typed storage representation before index maintenance. The equivalent conversion is absent from DELETE.
Physical-key control:
- an existing row backfilled by
ALTER TABLE ... ADD INDEX(e)has a label-based key and can initially be deleted; - a new row inserted after that ALTER receives an ordinal-based key and again cannot be deleted;
- ordinary VARCHAR/DECIMAL secondary-index controls delete correctly.
This issue is separate from #28994: that issue concerns IVFFLAT hidden-table schema metadata during vector-index construction; this one affects ordinary DELETE planning and regular primary/unique/secondary index maintenance.
Activity
fix(plan): preserve enum and set values on delete (#29198)
Ariznawlll commentedon Sep 22, 2026
测试版本
main3727c5c5436ca136d7b0312f75bc223a11692a85原问题验证
按 issue 原始场景创建带 ENUM/SET 主键、唯一索引和普通二级索引的表后执行 DELETE。原始路径重复 3 次,目标行均被正确删除,
row_count()为 1,剩余行和索引查询结果一致;已删除的 ENUM 唯一键可以重新插入。未再出现 affected rows 为 0、类型错误或 panic。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
修复 PR #29198 增加了 DELETE 规划器的 ENUM/SET 类型保持测试;本轮以公开 SQL 和 MOTR 黑盒回归为主。
回归测试
回归已随修复合入
test/distributed/cases/dtype/enum_index_update.sql。目标文件连续 3 轮均为 107/107;dtypesuite 为 7354/7354(32 条既有 ignore),FAILED 0、ABNORMAL 0。测试证据
测试结论
测试通过。