Skip to content

[Bug]: Database Data Branch and CLONE filter persistent user tables by internal-looking names #26121

Closed

Description

@Ariznawlll

Describe the bug

Database-level CLONE and Data Branch database operations incorrectly ignore
queryable user tables when their names match internal-looking names or
prefixes. The create paths silently omit the tables, while
DATA BRANCH DELETE DATABASE can skip the same tables during validation and
delete the database that contains them. Confirmed examples are:

  • an ordinary persistent relkind='r' table named __mo_tmp_user_data;
  • an ordinary persistent relkind='r' table named __mo_account_lock;
  • a user-created, queryable table named mo_increment_columns.

The tables remain queryable and can be copied correctly with the table-level
Data Branch statement. The database-level create statements nevertheless
return success without creating them in the destination.

Tested at commit 2eb7f523e5a10f352d3e258183ed8440510388de.

Steps to reproduce

drop database if exists g4d_tmp_prefix_branch;
drop database if exists g4d_tmp_prefix_clone;
drop database if exists g4d_tmp_prefix_src;

create database g4d_tmp_prefix_src;
use g4d_tmp_prefix_src;
create table `__mo_tmp_user_data` (
  id int primary key,
  note varchar(30)
);
create table `__mo_account_lock` (
  id int primary key,
  note varchar(30)
);
create table `mo_increment_columns` (
  id int primary key,
  note varchar(30)
);
insert into `__mo_tmp_user_data` values (1, 'persistent-user-row');
insert into `__mo_account_lock` values (2, 'ordinary-lock-name');
insert into `mo_increment_columns` values (3, 'ordinary-auto-name');

select relname, relkind
from mo_catalog.mo_tables
where account_id = 0
  and reldatabase = 'g4d_tmp_prefix_src'
  and relname in (
    '__mo_tmp_user_data',
    '__mo_account_lock',
    'mo_increment_columns'
  );

data branch create table direct_branch
  from `__mo_tmp_user_data`;
data branch create table direct_lock
  from `__mo_account_lock`;
data branch create table direct_auto
  from `mo_increment_columns`;
select * from direct_branch;
select * from direct_lock;
select * from direct_auto;

data branch create database g4d_tmp_prefix_branch
  from g4d_tmp_prefix_src;
create database g4d_tmp_prefix_clone
  clone g4d_tmp_prefix_src;

select reldatabase, relname, relkind
from mo_catalog.mo_tables
where account_id = 0
  and reldatabase in (
    'g4d_tmp_prefix_branch',
    'g4d_tmp_prefix_clone'
  )
  and relname in (
    '__mo_tmp_user_data',
    '__mo_account_lock',
    'mo_increment_columns'
  );

-- Deletion-validation comparison.
data branch create database g4d_delete_normal
  from g4d_tmp_prefix_src;
create table g4d_delete_normal.ordinary_keep(
  id int primary key,
  note varchar(30)
);
insert into g4d_delete_normal.ordinary_keep values (10, 'must-remain');
data branch delete database g4d_delete_normal;

data branch create database g4d_delete_filtered
  from g4d_tmp_prefix_src;
create table g4d_delete_filtered.`__mo_tmp_user_keep`(
  id int primary key,
  note varchar(30)
);
insert into g4d_delete_filtered.`__mo_tmp_user_keep`
  values (11, 'must-remain');
data branch delete database g4d_delete_filtered;

select count(*)
from mo_catalog.mo_database
where datname = 'g4d_delete_filtered';

Actual behavior

The first two source tables are normal persistent relations:

__mo_tmp_user_data  r
__mo_account_lock   r

All three table-level branches contain the expected rows:

1  persistent-user-row
2  ordinary-lock-name
3  ordinary-auto-name

Both database-level statements return success, but the destination metadata
query returns no row for any of the three tables.

The Data Branch database path was reproduced with three independent
destinations. All three silently contained only the other source tables.

For deletion, the ordinary ordinary_keep table correctly prevents
DATA BRANCH DELETE DATABASE, and both the database and row remain. Replacing
that table with the normal persistent relation __mo_tmp_user_keep
(relkind='r') changes the result: the delete statement succeeds and the
database count becomes zero. The prefix case was reproduced with three
independent branch databases. The exact names __mo_account_lock and
mo_increment_columns are ignored by the same validation path.

Expected behavior

A database-level copy should not omit a queryable user-created table solely
because its legal name resembles an internal object name. It should distinguish
internal relations using object metadata rather than only the user-visible
name.

At minimum, a database-level statement must not report a complete successful
copy while silently dropping a source base table. The delete statement must
also reject a database that contains any ordinary non-branch table, regardless
of that table's legal name.

Code context

Both database-level paths use collectCloneDatabaseSource, which calls
getTableInfos. buildTableInfoListWhereClause excludes every matching name:

relname not like '__mo_tmp\\_%' escape '\\'

The same filter also excludes the exact names mo_increment_columns and
__mo_account_lock. These predicates do not verify that a relation is the
corresponding internal object. Consequently, queryable user tables are removed
from srcTblInfos before cloning begins.

branchDeleteDatabaseTableIDsSQL reuses
buildTableInfoListWhereClause. As a result, the same user tables are removed
from the set passed to validateActiveBranchChildTableIDs. The validator never
sees them, so database deletion proceeds even though they are ordinary
non-branch tables.

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]: Database CLONE and DATA BRANCH silently skip persistent tables named __mo_tmp_*[/-] [+][Bug]: Database CLONE and DATA BRANCH silently skip persistent tables with internal-looking names[/+] on Jul 23, 2026
  5. changed the title [-][Bug]: Database CLONE and DATA BRANCH silently skip persistent tables with internal-looking names[/-] [+][Bug]: Database Data Branch and CLONE filter persistent user tables by internal-looking names[/+] on Jul 23, 2026
  6. added a commit that references this issue on Jul 29, 2026
    a7f667b
  7. VioletQwQ-0 commented on Jul 29, 2026

    @VioletQwQ-0
    Collaborator

    PR #26219 merged as a7f667b08f9760fd8bce048b7db13948adacce2c (reviewed head 6a801415130fd7afb9339985352115b17733205f). The issue-linked regression and replacement exact-head CI passed before merge.

    QA handoff on main f6dab28046d70412cec132f0068840896852101c:

    • Create persistent user tables whose names resemble internal MatrixOne names.
    • Run database CLONE and DATA BRANCH and verify those user tables, rows, indexes, and dependent objects are copied.
    • Verify genuine internal tables remain excluded.

    Pass: all persistent user objects are preserved without leaking genuine internal objects. Fail: user-table omission or internal-object inclusion.

  8. Ariznawlll commented on Jul 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在最新 main 分支完成验证。

    测试版本:52ea9f874f492c368a20efef16b46ab8ced2de37
    测试拓扑:Proxy + 2 CN
    重复次数:3 轮

    测试过程:

    1. 创建名称类似 MatrixOne 内部表、但实际属于用户的持久化表。
    2. 为这些表写入数据并创建唯一索引。
    3. 分别执行数据库级 CLONE 和数据库级 Data Branch。
    4. 检查用户表、数据、索引和依赖对象是否完整复制。
    5. 同时覆盖全文索引隐藏存储对象,确认真正的内部对象仍按规则处理。

    测试结果:

    • 普通用户表不会再仅因为名称类似内部表而被过滤。
    • 表数据和唯一索引均正确保留。
    • CLONE 和 Data Branch 结果一致。
    • 全文隐藏存储相关删除/过滤逻辑没有把普通用户对象误判为内部对象。
    • 连续 3 轮通过,未发现用户表遗漏或内部对象泄漏。

    结论:该问题在上述最新 main commit 上验证通过。

  9. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在 main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c 补充完成黑盒和白盒验证。

    黑盒验证:

    • MOTR 用例:issue_26121_data_branch_internal_names.test
    • 覆盖 __mo_tmp_*、__mo_account_lock、mo_increment_columns 等 internal-looking 用户表。
    • 同时执行数据库 Data Branch 和数据库 CLONE,检查表、精确数据、dependent View 和 unique index 行为。
    • 增加真正的 fulltext 内部存储对象作为控制,确认内部对象仍由系统管理。
    • 在 active branch 数据库中新建 internal-looking 普通用户表后执行 DATA BRANCH DELETE DATABASE,要求拒绝删除并检查数据库和行仍存在。

    结果:该 case 32/32 条 SQL/断言通过;本轮 Data Branch 全集 13/13 case、280/280 条 SQL/断言通过。

    白盒验证:

    go test ./pkg/tests/issues \
      -run '^TestIssue26121DatabaseOperationsKeepOrdinaryInternalLookingTables$' \
      -count=1
    ok github.com/matrixorigin/matrixone/pkg/tests/issues
    

    Unhappy path / 对象过滤边界:

    • 使用与系统内部对象同名或同前缀、但 metadata 明确为普通用户表的对象,防止按名称误过滤。
    • 在 active branch 数据库中新增该类普通表后执行 DATA BRANCH DELETE DATABASE,操作必须被拒绝。
    • 拒绝后检查数据库仍存在且用户行仍可读,验证不会静默丢表或误删库。
    • 使用真正的 fulltext hidden relation 作反向控制,确保放宽用户表过滤不会把内部对象当成独立用户表复制。

    结论:系统现在按 relation metadata 区分内部对象和同名用户对象,复制与删除保护路径均验证通过;黑盒回归已加入 motr#69。

  10. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    Unhappy Path / 对象误过滤专项验证

    测试版本:main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c

    专项使用名称看起来像内部对象、但 metadata 为普通用户表的对象:

    __mo_tmp_*
    __mo_account_lock
    mo_increment_columns
    

    验证内容:

    1. database CLONE/Data Branch 不能因为名称而静默漏表。
    2. 在 active branch 数据库中新建该类普通表。
    3. 执行 DATA BRANCH DELETE DATABASE,必须拒绝删除。
    4. 拒绝后数据库仍存在,用户数据仍可读取。
    5. 使用真正的 fulltext hidden relation 作反向控制,避免放宽过滤后错误复制内部对象。

    结果:用户表没有被误过滤;数据库删除被正确拒绝且数据保留;真正内部对象仍按系统对象处理。专项用例 32/32 条 SQL/断言通过。

    测试结论

    测试通过。

  11. added 6 commits that reference this issue on Sep 17, 2026
    fc50ded
    a150279
    f66e7ad
    1a0c41a
    9ec4877
    5dc6d46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions