Skip to content

[Bug]: VARCHAR ALTER on a self-referencing FK table resolves table ID 0 (v4.2.5) #29910

Closed

Description

@dengn

Is there an existing issue for the same bug?

  • I searched exact error strings, failing syntax and affected native applications; no matching issue was identified. Related reports are distinguished below.

Application compatibility replay on official v4.2.5

Branch Name

Official stable release v4.2.5; current main has not been retested for this report.

Commit ID

1a44f3db3056e32975fde86ca0ab69a094996a3f (SELECT git_version() returns 1a44f3d).

Other Environment Information

Linux x86_64 standalone official binary, 4 CPUs, ~16 GiB container memory limit. SELECT VERSION() = 8.0.30-MatrixOne-v4.2.5. PyMySQL 1.2.3 client. Only fresh owned test schemas were used for SQL probes; the native Airflow diagnostic is a read-only SELECT against the retained test fixture.

Actual Behavior

Native application impact: 普通 VARCHAR 长度修改报 20101 can not find table by id 0;小表两行复现,DROP 自引用 FK 后仍失败。

ERROR 20101: internal error: can not find table by id 0: accountId: 0

Expected Behavior

Allow a VARCHAR length change on a self-referencing FK table. Preserve both existing rows and actual foreign-key enforcement; do not resolve the self-reference sentinel as a physical table ID.

Steps to Reproduce

Use a dedicated fresh test schema (create one without DROP DATABASE), then run:

CREATE TABLE self_probe(id INT PRIMARY KEY,parent_id INT NULL,URL VARCHAR(100),CONSTRAINT fk_self FOREIGN KEY(parent_id) REFERENCES self_probe(id));

INSERT INTO self_probe VALUES(1,NULL,'parent'),(2,1,'child');

ALTER TABLE self_probe MODIFY COLUMN URL VARCHAR(125);

Additional information

  • Native applications: InvenTree, Wagtail 的相关自引用表移列适配.
  • This is release v4.2.5 evidence, not a claim that the same failure remains on current main.
  • Observation family MO-OBS-030. App-side workarounds do not constitute an engine fix.
  • All disclosed values are owned synthetic fixtures; no passwords, tokens, application cookies or raw private logs are attached.

Related #26838 concerns TRUNCATE of a self-FK table. This new report uses MODIFY COLUMN VARCHAR with two existing rows. Earlier separate probes also reproduced the ALTER failure after DROP FOREIGN KEY; both original rows and a re-added FK were retained.

Activity

  1. added
    kind/bug
    on Oct 11, 2026
  2. dengn commented on Oct 12, 2026

    @dengn
    ContributorAuthor

    Runtime recheck on current main

    Built and actually ran upstream main 02a2823c2007d5e4fb4ada148e93743df337551a, with git_version() = 02a2823, Go 1.27.1, Linux amd64, the official make build CPU entrypoint, gcc/g++, and separate fresh main cluster storage. Binary SHA-256: ce8b149f0da8c8a06ec8786c4d311795e6893420bd15be29d6e6b9cab44bb2f5. SQL checks ran 2026-10-12 06:04 UTC; upstream main was re-read before execution and still resolved to this SHA.

    Comparison: official v4.2.5 / 1a44f3db3056e32975fde86ca0ab69a094996a3f (git_version() = 1a44f3d). Both sides used fresh owned schemas and identical regression fixture hashes. This checks the disclosed reproducer; complete native application workflows have not been rerun on main. No issue is being closed automatically.

    SQL-SELF-FK-ALTER: stable known_failure → main candidate_fixed

    The reproducer completed and its result/constraint assertions passed on this main snapshot; the stable failure no longer reproduces for this fixture.

    Fixture SHA-256: 1b6ca1ef6334a235e93db4ad8a05ed2fef7a75e159d9fafc0b38a49bc9d7df84. A fresh SELECT 1 after the trigger succeeded: True.

    ALTER TABLE self_probe MODIFY COLUMN URL VARCHAR(125);

    Returned rows: [].

    Independent postchecks: [{"sql": "SELECT id,parent_id,URL FROM self_probe ORDER BY id", "passed": true, "rows": [[1, null, "parent"], [2, 1, "child"]]}, {"sql": "INSERT INTO self_probe VALUES(3,999,'must reject')", "passed": true, "error_code": 1452}].

    Detailed SQL, assertions, source/build identity and JSON evidence (organization regression repository): https://github.com/matrixorigin/matrixone-app-regression/tree/01517d2f73abb5021ca545193c2af38ef653f278/evidence/main-02a2823

  3. Ariznawlll commented on Oct 15, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:官方 main
    • commit:bb2b725d0af4601d02ebf9cc68b1816a2b300022(源码构建的本地测试实例;SELECT git_version() 在 embedded 测试实例返回 unknown,版本以隔离 worktree 的 Git SHA 和构建源码为准)
    • 修复:matrixone #29994,merge commit 5d971d07a7c5a52a71f2c10390b109cebf5c0825,已核对为上述官方 main 的祖先
    • 部署方式:本地隔离 embedded 集群,1 CN / 1 TN / 1 LogService;MySQL 协议,独立新建并清理测试库
    • 测试日期:2026-10-15

    原问题验证

    按 issue 的两行自引用 FK 表复现:(1,NULL,'parent')、(2,1,'child'),执行 ALTER TABLE self_probe MODIFY COLUMN URL VARCHAR(125)。三轮独立建库均成功,原两行保留;没有出现旧版的 can not find table by id 0。每轮结束均删除本轮测试库。

    Happy Path 覆盖

    1. 原始 VARCHAR(100) -> VARCHAR(125) DDL 成功 3/3;原两行及父子关系不变,information_schema.columns.character_maximum_length=125。
    2. 修改后插入合法子行 (3,2,REPEAT('x',125)) 成功 3/3,读回 parent_id=2、LENGTH(URL)=125;验证新长度边界和自引用约束仍可用。
    3. 每轮结束查询 SELECT 1 正常并清理专属 schema。

    Unhappy Path 覆盖

    1. 修改后插入不存在父行的 (4,999,'orphan'),3/3 返回 1452;随后读取原三行,未出现孤儿行,验证拒绝操作的原子性和 FK 未被 ALTER 破坏。

    白盒验证

    本次为公开 SQL 黑盒验收,未新增或运行 Go UT / -race;该路径不依赖内部故障注入。关联修复 PR 的白盒检查不计作本次独立测试。

    回归测试

    • 已提交 MOTR #243:suites/14_issue_regression/t/issue_29910_self_fk_alter.test 与对应 r/issue_29910_self_fk_alter.result,精确断言行、长度、NULL、1452 和失败后的状态。
    • 在上述 main 的隔离集群上定向运行 3/3 成功,42/42 语句符合 golden。PR 目前为 Draft,尚未合入;完整 14_issue_regression suite 和集成 CI 尚未执行,后续继续跟踪,不将其写成已通过。
    • 此 SQL 行为不需要规模、内存阈值、长稳或外部故障,因此无额外 big-data / stability / chaos 用例。

    测试证据

    • MOTR #243 的 SQL 与精确预期。
    • 本地定向运行摘要:total=3 success=3 failed=0 skipped=0 | stmts=42 ok=42 fail=0;独立 Go SQL 探针三轮均为 alter=ok rows=2 invalid_fk=1452 atomic=ok valid_fk=ok cleanup=ok。
    • 原 issue 的 v4.2.5 失败与较早 main 对照见 issue 正文和先前运行评论。完整原生 InvenTree/Wagtail 应用流程本次未重跑;本结论针对 issue 所列 SQL 复现与约束验收。

    测试结论

    测试通过。

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

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions