Skip to content

[Bug]: CREATE DATABASE ... CLONE silently omits sequences and leaves dependent views unusable #27049

Closed

Description

@Ariznawlll

Bug Description

CREATE DATABASE dst CLONE src silently skips sequence objects. The statement succeeds without warnings, but the destination database has no corresponding sequence. If a cloned view references that sequence, the view is created successfully but becomes unusable with ERROR 1146 ... no such table dst.seq1.

DATA BRANCH CREATE DATABASE dst FROM src is affected by the same source-object collection path.

Environment

  • MatrixOne: latest official origin/main
  • Commit: 6b81a6d364dad13b1b2b1e52a9c3ac1f212d92bb
  • Deployment: local single-process cluster, 1 Log + 1 TN + 1 CN
  • Client: MySQL protocol, port 6001

Steps to Reproduce

drop database if exists clone_seq_src;
drop database if exists clone_seq_dst;
create database clone_seq_src;

create sequence clone_seq_src.seq1 increment 3 start with 7 no cycle;
create table clone_seq_src.t1(id int primary key);
insert into clone_seq_src.t1 values (1);
create view clone_seq_src.seq_view as select nextval('seq1') as n;

-- The source sequence and dependent view both work.
select * from clone_seq_src.seq_view;

create database clone_seq_dst clone clone_seq_src;
show warnings;

show full tables from clone_seq_src;
show full tables from clone_seq_dst;
select reldatabase, relname, relkind
from mo_catalog.mo_tables
where reldatabase in ('clone_seq_src', 'clone_seq_dst')
order by reldatabase, relname;

select * from clone_seq_dst.t1;
select * from clone_seq_dst.seq_view;

Minimal sequence-only variant:

drop database if exists clone_seq_only_src;
drop database if exists clone_seq_only_dst;
create database clone_seq_only_src;
create sequence clone_seq_only_src.seq1 increment 2 start with 11 no cycle;

create database clone_seq_only_dst clone clone_seq_only_src;
show warnings;
show full tables from clone_seq_only_dst;

Actual Behavior

  • The database clone returns success (mysql exit code 0) and SHOW WARNINGS is empty.
  • The source catalog contains seq1 with relkind = 'S'; the destination catalog contains no sequence.
  • Ordinary base-table data is cloned correctly.
  • The destination seq_view exists, but querying it fails:
ERROR 1146 (42S02): no such table clone_seq_dst.seq1
  • With a source database containing only a sequence, cloning succeeds but creates an empty destination database.
  • The result reproduced 3/3 for live database clone and also reproduced with snapshot clone.
  • DATA BRANCH CREATE DATABASE also succeeds while omitting the sequence.

Expected Behavior

Database clone should preserve supported sequence objects, including their definition and state, so cloned dependent views remain usable. If sequences are intentionally unsupported, the statement should fail explicitly and atomically instead of silently producing an incomplete database.

Stability and Controls

  • Reproduced 3/3 on the commit above.
  • Snapshot database clone reproduces the same omission.
  • Passing control: a database containing a normal base table and normal view clones successfully; the destination view returns the expected row.
  • Constraint control: cloned CHECK and UNIQUE constraints remain enforced.
  • Generated-column control: stored/virtual generated columns and indexes work after both table clone and database clone.
  • Source objects remain healthy after cloning; the source sequence-backed view continues returning values.

Code Analysis

The omission occurs before clone execution:

  • pkg/frontend/clone_database_source.go:84 calls getTableInfos(...) to enumerate database objects.
  • pkg/frontend/snapshot.go:2106 unconditionally appends and relkind != catalog.SystemSequenceRel to the metadata query.
  • pkg/frontend/clone.go:987-1047 clones the enumerated tables and then restores views, but has no path that recreates an excluded sequence.
  • pkg/frontend/data_branch.go:565-585 uses the same collectCloneDatabaseSource and handleCloneDatabaseWithSource functions, explaining the Data Branch result.

As a result, the sequence is absent from the clone plan while a dependent view is still restored and committed.

Suggested Regression Coverage

Add BVT coverage for live and snapshot database clone with:

  1. a sequence-only source database;
  2. a base table plus sequence plus sequence-dependent view;
  3. verification of the cloned sequence definition/state and dependent-view usability;
  4. explicit error/rollback assertions if sequences are intentionally unsupported.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 12, 2026
  2. added
    kind/bug
    on Aug 12, 2026
  3. added theissue type on Aug 12, 2026
  4. added
    severity/s0
    and removed on Aug 12, 2026
  5. Ariznawlll commented on Aug 13, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充 Snapshot 模块影响范围:数据库级恢复也会走同一对象枚举路径,因此该问题不只影响 CLONE / Data Branch。

    验证环境

    • 分支:main
    • commit:d72332412e4419c760ead858ea1aa9526bf0cc9c
    • 部署:本地单进程,1 Log + 1 TN + 1 CN
    • 日期:2026-08-13

    最小复现

    create database sx_seq_db;
    use sx_seq_db;
    create table control_t(id int primary key, v varchar(20));
    insert into control_t values (1,'at-snapshot');
    create sequence seq_t as bigint increment 5 start 10;
    select nextval('seq_t'); -- 10
    create snapshot sx_seq for database sx_seq_db;
    
    insert into control_t values (2,'after-snapshot');
    select nextval('seq_t'); -- 15
    restore database sx_seq_db{snapshot="sx_seq"};
    
    use sx_seq_db;
    select * from control_t order by id;
    select nextval('seq_t');
    show tables;

    实际结果

    连续 3/3 次均出现:

    control_t:
    1 | at-snapshot
    
    ERROR 1146 (HY000): no such table sx_seq_db.seq_t
    
    SHOW TABLES:
    control_t
    

    普通表对照每次都正确恢复到 Snapshot 时刻,只有 Sequence 消失;错误后服务仍可正常执行 SELECT version(), 1。

    代码定位

    restoreToDatabaseOrTable 调用 getTableInfos 枚举恢复对象,而 pkg/frontend/snapshot.go:2106 无条件追加:

    whereClause += fmt.Sprintf(" and relkind != %s", quoteSQLStringLiteral(catalog.SystemSequenceRel))

    因此 RESTORE DATABASE ... {snapshot=...} 与 Issue 中的 CLONE/Data Branch 是同一根因,建议回归用例同时覆盖数据库级 Snapshot 恢复,并校验 Sequence 定义/状态及依赖视图可用性。

  6. added
    ai-easy
    on Aug 20, 2026
  7. gouhongshen commented on Aug 20, 2026

    @gouhongshen
    Contributor

    PR #27401 is trying to fix this issue.

  8. gouhongshen commented on Aug 21, 2026

    @gouhongshen
    Contributor

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

  9. added and removed
    severity/s0
    on Aug 25, 2026
  10. Ariznawlll commented on Aug 25, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:22b91fe986b269d24a6b8816eafdd1fa6327c8e1
    • 部署方式:本地 1 CN / 1 TN / 1 Log,MySQL 协议
    • 测试日期:2026-08-25

    原问题验证

    在源库创建 seq1、依赖 NEXTVAL('seq1') 的 seq_view 和数据表后,执行 CREATE DATABASE CLONE 。连续 3 轮中,目标库均保留 sequence、view 与表;切换至目标库后查询 seq_view 返回 10,表数据计数为 1。

    Happy Path 覆盖

    1. CREATE DATABASE ... CLONE ... 后,目标库的 seq1、seq_view、t1 均存在,且对象类型分别为 sequence、view、table,3/3 通过。
    2. 目标库的 sequence-backed view 可执行并返回预期值,3/3 通过。

    Unhappy Path 覆盖

    1. 对已存在的目标库执行 CLONE,3/3 返回 ERROR 1007;目标库中的 sentinel 数据保持,且未生成源库对象,失败原子性通过。

    白盒验证

    不适用。本次按用户可见的 CLONE/SQL 接口完成黑盒验证。

    回归测试

    已有 BVT:clone_database_sequence.sql 及其 .result,覆盖 sequence database clone 的回归路径。

    测试证据

    latest main 22b91fe 上原始复现和已存在目标库拒绝路径均连续执行 3 轮,结果如上。

    另发现从不同默认数据库访问 qualified sequence-backed view 时的名称解析问题,已作为独立 issue #27581 跟踪;该问题不影响本 issue 的 CLONE 保留对象验收。

    测试结论

    测试通过。

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