Repository navigation
Description
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_tDELETE FROM branch_twithout aWHEREclause (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_iddiffers 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_treturns:
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:
- preserve/migrate the branch relationship to the replacement table ID, including the required protection metadata; or
- 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
[-][Bug]: TRUNCATE TABLE discards Data Branch identity and protection metadata[/-][+][Bug]: Table rebuild operations discard Data Branch identity and protection metadata[/+]gouhongshen commentedon Sep 4, 2026
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.
gouhongshen commentedon Sep 4, 2026
PR #28148 is trying to fix this issue.
fix: preserve Data Branch lineage across TRUNCATE (#28148)
gouhongshen commentedon Sep 5, 2026
PR #28148 has merged and is awaiting manual validation. The issue remains open.
Ariznawlll commentedon Sep 16, 2026
测试版本
main9572bd3311abb16d1df939956408a727bcf83eba原问题验证
在 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 覆盖
Unhappy Path 覆盖
DELETE,覆盖优化为 truncate 的原故障路径。白盒验证
不适用。本次为部署 SQL 验收。
回归测试
已加入 motr PR #181:
suites/12_git4data/t/issue_26068_26064_branch_lifecycle.test。测试证据
motr PR #181;三轮矩阵
6 operations × 3 runs均完成。测试结论
测试通过。
fix: preserve Data Branch lineage across TRUNCATE (matrixorigin#28148)
fix: preserve Data Branch lineage across TRUNCATE (matrixorigin#28148)
fix: preserve Data Branch lineage across TRUNCATE (matrixorigin#28148)