Repository navigation
Description
Description
ALTER TABLE ... RENAME COLUMN does not rewrite the stored SQL text of CHECK constraints. Constraint execution continues to use the correct internal column IDs, but SHOW CREATE TABLE emits stale, invalid SQL and later ALTER validation resolves the obsolete name.
Reproduced three independent times, including after a full service restart, on current main commit 45a917d7f8f7b2f32c28ca0a734318875722a00e.
Reproduction
drop database if exists repro_check_rename;
create database repro_check_rename;
use repro_check_rename;
create table t(
id int primary key,
a int not null,
b int not null,
constraint ck_ab check(a < b)
);
insert into t values (1,1,2);
alter table t rename column a to x;
show create table t;
insert into t values (2,2,3);
insert into t values (3,5,4);
alter table t drop column x;Actual result
SHOW CREATE TABLE emits a column named x but a CHECK expression that still references the removed name a:
CREATE TABLE `t` (
`id` int NOT NULL,
`x` int NOT NULL,
`b` int NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `ck_ab` CHECK (`a` < `b`)
)Executing that output as a new CREATE TABLE fails because column a does not exist. Renaming both constrained columns leaves both old names in SHOW CREATE. ALTER TABLE t DROP COLUMN x also fails through the stale expression with column 'a' does not exist.
The runtime constraint itself remains active: valid rows insert successfully and invalid rows return 3819 before and after restart. CREATE TABLE ... LIKE t also preserves the working ID-bound constraint, so this is specifically a stale SQL/DDL dependency representation.
Expected result
Renaming a to x must rewrite the CHECK expression to CHECK (x < b). SHOW CREATE output must be executable, and later ALTER operations must resolve the current column names.
Analysis
updateRenameColumnInTableDef updates the column definition, primary key, indexes, cluster key, and plugin metadata, but does not update CHECK definitions. The bound CHECK expression retains valid column IDs, while its formatted/original expression text keeps obsolete identifiers.
Activity
fix: preserve table integrity across ALTER and TRUNCATE (#26893)
Ariznawlll commentedon Aug 11, 2026
测试版本
maind01c85974f9540f8baa2e768ca86fea952941fe2mo-service,1 Log / 1 TN / 1 CN,MySQL 文本协议原问题验证
将受 CHECK 约束列
a重命名为x后,SHOW CREATE 三轮均输出CHECK (x < b),不再保留旧列名。Happy Path 覆盖
(1,1,2)可插入,约束 SQL 与当前列名一致。Unhappy Path 覆盖
(2,3,2)每轮均返回 3819,证明约束重写后仍有效。白盒验证
不适用:通过 SHOW CREATE 与约束执行验证存储 DDL 表示。
回归测试
已加入
suites/14_issue_regression/t/issue_26820_26825_26827_26838_26839_26896_sql_semantics.test,PR #89,提交f6c496413efcbb7807d85643ac50cb836139a7c1。测试证据
该 motr 用例与同批用例连续 3 轮通过,共 216 条断言成功。
测试结论
测试通过。
fix: preserve table integrity across ALTER and TRUNCATE (matrixorigin…
fix: preserve table integrity across ALTER and TRUNCATE (matrixorigin…
fix: preserve table integrity across ALTER and TRUNCATE (matrixorigin…