Skip to content

[Compatibility]: generated-column dependencies block MySQL-supported base-column MODIFY operations #28242

Closed

Description

@Ariznawlll

问题描述

只要普通列被生成列表达式引用,MatrixOne 就会拒绝多类不会破坏依赖关系的 ALTER TABLE ... MODIFY COLUMN。MySQL 可以完成相同变更,并继续基于修改后的普通列正确计算生成列。

当前行为把“列仍然存在且表达式引用仍然有效”的安全类型调整和列位置调整,与删除/改名依赖列等破坏性操作一并阻止,导致包含生成列的表无法执行常见 schema 演进。

环境

  • MatrixOne: latest main, commit e7bb0572235ec4bac81eb098eb0ad8900f0065ab
  • MySQL: 8.3.0(对照)

最小复现

create database gc_modify_repro;
use gc_modify_repro;

create table t (
  id int primary key,
  a int,
  b int,
  g bigint generated always as (a + 5) stored
);
insert into t values (1, 10, 20, default);

alter table t modify column a bigint;
insert into t(id,a,b) values (2,4000000000,30);
select id,a,g from t order by id;

MatrixOne 行为

ALTER TABLE 返回:

Cannot modify column 'a': generated column 'g' depends on it

MySQL 8.3.0 行为

INT -> BIGINT 修改成功;已有行保持 g=15,新行可保存 a=4000000000 并生成 g=4000000005。

受影响的安全变更

在独立表上逐项验证,下列 MySQL 支持的修改均被 MatrixOne 以相同依赖错误拒绝:

alter table t modify column a bigint;
alter table t modify column a int unsigned;
alter table t modify column a int not null;
alter table t modify column a int after b;

-- decimal 表
alter table td modify column a decimal(20,4);

其中包括整数扩宽、改为无符号、收紧 NULL 属性、调整列顺序和 DECIMAL 精度扩宽。

已确认边界

  • 保持完全相同类型的 MODIFY a INT 可以执行。
  • 修改被依赖列的 DEFAULT 或 COMMENT 可以执行。
  • VARCHAR(5) -> VARCHAR(30) 可以执行,说明限制并非覆盖所有类型扩宽。
  • 删除或改名被依赖列应当拒绝,不属于本问题。

期望行为

对于不删除列、不改变列名,且修改后生成表达式仍可合法绑定的 ALTER,MatrixOne 应重新校验表达式并允许变更;只有会使依赖失效或发生不允许转换的操作才应拒绝。

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. Ariznawlll commented on Sep 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    在最新 main(fc621e3616d229c7a29d0c80e73ed8eb1997459c)补充确认:该限制也阻断 DECIMAL 从 Decimal128 到 Decimal256 的安全扩宽。

    CREATE TABLE gen(
      id INT PRIMARY KEY,
      d DECIMAL(38,0),
      g DECIMAL(41,0) GENERATED ALWAYS AS (d+1) STORED
    );
    INSERT INTO gen(id,d) VALUES(1,1);
    ALTER TABLE gen MODIFY COLUMN d DECIMAL(40,0);

    MatrixOne 返回:

    invalid input: Cannot modify column 'd': generated column 'g' depends on it
    

    这里生成列 g DECIMAL(41,0) 足以容纳扩宽后的 d+1,表达式和列名均未改变。去掉生成列后,相同的 DECIMAL(38,0) -> DECIMAL(40,0) 可以执行,原值保持精确,并可继续写入 40 位值;存在 40 位值时再缩回 DECIMAL(38,0) 会拒绝且表结构、数据均保持不变。MySQL 8.0.46 对上述带生成列的安全扩宽可以执行。

    因此该场景仍属于 issue 描述的“无破坏性类型扩宽被生成列依赖统一阻断”,不另建重复 issue。

  6. XuPeng-SH commented on Sep 12, 2026

    @XuPeng-SH
    Contributor

    2026-09-12 — COPY ALTER support for generated-column dependencies

    • Status: PR fix: allow modify of generated column sources #28770 is open and mergeable at abd3972aefa8ff4e048b980fb5ec7a71654e2037; CodeQL and CI preflight have started. This issue remains open pending exact-head tests and merge.
    • Root cause: MODIFY COLUMN rejects any source referenced by a generated column, even when COPY ALTER can rebind the expression against the final schema and recompute its values. Index classification also needs to account for the transitive generated dependency closure; otherwise a stale generated-key index can be cloned.
    • Change: PR #28770 removes only the over-broad MODIFY guard, tracks original-column lineage, and rebuilds indexes affected directly or through chained generated columns while keeping unrelated indexes cloneable. When the closure reaches a real primary-key component, it rebuilds all secondary indexes because their entries carry the base row's PK. DROP/rename dependency rejection, type checks, and unique-key deduplication remain unchanged.
    • Evidence and review: planner tests cover lineage, chains, reordering, same-name CHANGE, unrelated index cloning, and ADD-then-MODIFY. BVT coverage includes type widening, UNSIGNED/NOT NULL, Decimal128→Decimal256, index refresh, and failed COPY rollback. GPT-6 Astra medium's final source review passed exact tracked diff c1c93775ca111cc08a8eff778d03ac7d68ac67dab63801a05bf5bddd34ee8eb3 plus the new planner test a2b68eca20888935177df44d7b70d3e3e1db7a472f60db96b85d6ff6ddd71ff5. During review, a weak ordinary-index test was replaced by a UNIQUE(payload) forced lookup selecting base columns and compared against IGNORE INDEX, making stale hidden PK payload observable.
    • Validation: gofmt, git diff --check, incremental molint vet (exit 0; only pre-existing findings in unchanged files), and incremental golangci-lint (0 issues) passed. The prescribed CGo test wrapper stopped before compilation because this isolated macOS worktree lacks provenance-validated cgo/libmo.dylib; local UT and BVT are not claimed as run. No unrelated MatrixOne services were touched.
    • Performance: dependency closure is computed once during planning; only affected indexes rebuild in the common case. All secondary indexes rebuild only when generated PK values may change. No added table-data pass.
    • Remaining risk / next: require exact-head CI to execute planner UT, shared tests, and generated-column BVT; resolve any relevant failure before considering the issue verified.
  7. added a commit that references this issue on Sep 14, 2026
    07b2596
  8. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:07b25969bfea9d4b76d3bf05d5b0497e4f36eba0
    • 部署:本地独立 1 CN / 1 TN / 1 LogService;每轮均重新启动服务后执行。
    • 执行:每项 SQL 回归连续 3 轮,输出逐轮一致。

    原问题验证

    • 生成列依赖不再阻塞 MySQL 支持的基础列 MODIFY 操作。

    Happy Path 覆盖

    • 覆盖 BIGINT、UNSIGNED、NOT NULL、AFTER 和 DECIMAL widening 等安全 MODIFY,均成功。

    Unhappy Path 覆盖

    • 覆盖删除生成列依赖源列,仍按预期拒绝,避免破坏依赖。

    白盒验证

    • 以 MOTR 同时固定允许与拒绝的 DDL 路径。

    回归测试

    测试证据

    • 以上结果均在该 main commit 的独立环境获得;每轮无 stderr,三轮结果一致。

    测试结论

    测试通过。

  9. added 3 commits that reference this issue on Sep 17, 2026
    ee994f3
    0b79172
    dc5f079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions