Skip to content

[Bug]: Table rebuild operations discard Data Branch identity and protection metadata #26064

Closed

Description

@Ariznawlll

Describe the bug

Table-rebuild operations on an active Data Branch table silently discard its branch identity. The confirmed entry points are:

  • TRUNCATE TABLE branch_t
  • DELETE FROM branch_t without a WHERE clause (optimized to truncate)
  • ALTER TABLE branch_t ADD COLUMN ...
  • ALTER TABLE branch_t ALTER COLUMN ... SET DEFAULT ...
  • ALTER TABLE branch_t DROP COLUMN ...
  • ALTER TABLE branch_t ALTER COLUMN ... DROP DEFAULT

These implementations replace the old physical table with a new one. The ordinary drop hook marks the old mo_branch_metadata row deleted and reclaims its branch-protection snapshot, but the newly created table ID is not attached to equivalent branch metadata.

Afterward, the table still exists and DATA BRANCH DIFF can run, but it no longer has its original branch ancestry. DATA BRANCH DELETE TABLE rejects it as not being an active branch table.

Tested at commit 2eb7f523e5a10f352d3e258183ed8440510388de.

Steps to reproduce

drop database if exists g4d_truncate_lifecycle;
create database g4d_truncate_lifecycle;
use g4d_truncate_lifecycle;

create table base_t(id int primary key, v int);
insert into base_t values (1,10),(2,20);
data branch create table branch_t from base_t;

set @old_id = (
  select rel_id from mo_catalog.mo_tables
  where reldatabase='g4d_truncate_lifecycle' and relname='branch_t'
);

truncate table branch_t;

set @new_id = (
  select rel_id from mo_catalog.mo_tables
  where reldatabase='g4d_truncate_lifecycle' and relname='branch_t'
);

select @old_id, @new_id;
select table_id, p_table_id, table_deleted
from mo_catalog.mo_branch_metadata
where table_id in (@old_id, @new_id);

data branch delete table branch_t;

The same metadata transition occurs when replacing truncate table branch_t with either:

delete from branch_t;

or:

alter table branch_t add column extra_value int default 0;

The same result also occurs for:

alter table branch_t alter column existing_value set default 7;

and for:

alter table branch_t drop column removable_value;
alter table branch_t alter column existing_value drop default;

For comparison, DELETE FROM branch_t WHERE TRUE, RENAME TABLE branch_t TO renamed_t, ALTER TABLE ... RENAME COLUMN, and ALTER TABLE ... MODIFY COLUMN preserve the same physical table ID and retain the active branch row. Creating ordinary, full-text, and IVF-FLAT indexes also preserves the branch identity.

Actual behavior

  • @new_id differs from @old_id.
  • The old metadata row changes to table_deleted = true.
  • No active metadata row exists for @new_id.
  • The __mo_branch_<old_id> protection snapshot is removed.
  • DATA BRANCH DELETE TABLE branch_t returns:
internal error: DATA BRANCH DELETE target g4d_truncate_lifecycle.branch_t is not an active branch table

Expected behavior

Rebuilding a Data Branch table should either:

  1. preserve/migrate the branch relationship to the replacement table ID, including the required protection metadata; or
  2. reject TRUNCATE explicitly if preserving branch identity is not supported.

It should not silently turn an active Data Branch into an ordinary table.

Reproducibility

Reproduced in 3/3 runs for TRUNCATE, DELETE without WHERE, ALTER TABLE ADD COLUMN, ALTER COLUMN SET DEFAULT, DROP COLUMN, and ALTER COLUMN DROP DEFAULT. In every run the table ID changed, the old branch row was marked deleted, the protection snapshot was removed, and the replacement table had no active branch row.

Code context

Scope.TruncateTable and the ALTER rebuild path replace the physical relation. The DROP path runs the Data Branch cleanup for the old physical ID, but the CREATE/replacement path does not migrate mo_branch_metadata or the matching branch-protection snapshot to the new physical ID.

Activity

  1. added this to the MO-202607 milestone on Jul 23, 2026
  2. added
    kind/bug
    on Jul 23, 2026
  3. added theissue type on Jul 23, 2026
  4. changed the title [-][Bug]: TRUNCATE TABLE discards Data Branch identity and protection metadata[/-] [+][Bug]: Table rebuild operations discard Data Branch identity and protection metadata[/+] on Jul 23, 2026
  5. gouhongshen commented on Sep 4, 2026

    @gouhongshen
    Contributor

    Automated AI triage

    This issue requires human involvement and cannot currently be completed independently by the
    automated fix loop.

    Reason

    Needs a Data Branch lifecycle-contract decision. A maintainer must choose between migrating branch identity and protection state to rebuilt table IDs or rejecting rebuild operations on active branches, then specify transactional behavior.

    Evidence

    The issue explicitly accepts either preservation or rejection; those choices require substantially different DDL and metadata semantics.

    Please use this analysis to provide the missing decision, environment, evidence, or ownership
    needed before the issue is returned to the AI candidate pool.

  6. added
    severity/s0
    ai-easy
    and removed on Sep 4, 2026
  7. gouhongshen commented on Sep 4, 2026

    @gouhongshen
    Contributor

    PR #28148 is trying to fix this issue.

  8. gouhongshen commented on Sep 5, 2026

    @gouhongshen
    Contributor

    PR #28148 has merged and is awaiting manual validation. The issue remains open.

  9. added and removed
    severity/s0
    on Sep 16, 2026
  10. Ariznawlll commented on Sep 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:9572bd3311abb16d1df939956408a727bcf83eba
    • 部署方式:TKE,Proxy + 3 CN + 1 TN
    • 测试日期:2026-09-16

    原问题验证

    在 3 个独立数据库中分别创建 branch table 后,执行 TRUNCATE、无 WHERE 的 DELETE、ADD COLUMN、ALTER COLUMN SET DEFAULT、DROP COLUMN、ALTER COLUMN DROP DEFAULT,每个操作后均执行 DATA BRANCH DELETE TABLE,18/18 成功。

    Happy Path 覆盖

    1. 六类原问题中的重建型 DDL/DML 均保留可删除的 Data Branch 身份。
    2. 三轮全部完成,没有错误或遗留 branch table。

    Unhappy Path 覆盖

    1. 采用无 WHERE 的 DELETE,覆盖优化为 truncate 的原故障路径。

    白盒验证

    不适用。本次为部署 SQL 验收。

    回归测试

    已加入 motr PR #181:suites/12_git4data/t/issue_26068_26064_branch_lifecycle.test。

    测试证据

    motr PR #181;三轮矩阵 6 operations × 3 runs 均完成。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions