Skip to content

[Bug]: RENAME COLUMN leaves stale names in CHECK constraint SQL #26839

Closed

Description

@Ariznawlll

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

  1. added this to the MO-202608 milestone on Aug 9, 2026
  2. added
    kind/bug
    on Aug 9, 2026
  3. added theissue type on Aug 9, 2026
  4. added
    severity/s0
    and removed on Aug 9, 2026
  5. assigned and unassigned on Aug 11, 2026
  6. Ariznawlll commented on Aug 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:d01c85974f9540f8baa2e768ca86fea952941fe2
    • 部署方式:本地 mo-service,1 Log / 1 TN / 1 CN,MySQL 文本协议
    • 测试日期:2026-08-11

    原问题验证

    将受 CHECK 约束列 a 重命名为 x 后,SHOW CREATE 三轮均输出 CHECK (x < b),不再保留旧列名。

    Happy Path 覆盖

    1. 合法行 (1,1,2) 可插入,约束 SQL 与当前列名一致。

    Unhappy Path 覆盖

    1. 非法行 (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 条断言成功。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions