Repository navigation
Description
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 (
mysqlexit code 0) andSHOW WARNINGSis empty. - The source catalog contains
seq1withrelkind = 'S'; the destination catalog contains no sequence. - Ordinary base-table data is cloned correctly.
- The destination
seq_viewexists, 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 DATABASEalso 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
CHECKandUNIQUEconstraints 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:84callsgetTableInfos(...)to enumerate database objects.pkg/frontend/snapshot.go:2106unconditionally appendsand relkind != catalog.SystemSequenceRelto the metadata query.pkg/frontend/clone.go:987-1047clones the enumerated tables and then restores views, but has no path that recreates an excluded sequence.pkg/frontend/data_branch.go:565-585uses the samecollectCloneDatabaseSourceandhandleCloneDatabaseWithSourcefunctions, 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:
- a sequence-only source database;
- a base table plus sequence plus sequence-dependent view;
- verification of the cloned sequence definition/state and dependent-view usability;
- explicit error/rollback assertions if sequences are intentionally unsupported.
Related
- [Bug]: CREATE TEMPORARY TABLE ... CLONE leaves an unqueryable session ghost after failing #27042 (this issue was found while continuing the same CLONE module exploration)
- [Bug]: CREATE TABLE IF NOT EXISTS ... CLONE mutates an existing table and creates duplicate primary keys #27039, [Bug]: CREATE DATABASE IF NOT EXISTS ... CLONE ignores IF NOT EXISTS for an existing target #27040, [Bug]: CREATE DATABASE ... CLONE accepts a nonexistent source and creates an empty target #27041 (other CLONE semantics issues; different symptoms/root causes)
Activity
Ariznawlll commentedon Aug 13, 2026
补充 Snapshot 模块影响范围:数据库级恢复也会走同一对象枚举路径,因此该问题不只影响 CLONE / Data Branch。
验证环境
maind72332412e4419c760ead858ea1aa9526bf0cc9c最小复现
实际结果
连续 3/3 次均出现:
普通表对照每次都正确恢复到 Snapshot 时刻,只有 Sequence 消失;错误后服务仍可正常执行
SELECT version(), 1。代码定位
restoreToDatabaseOrTable调用getTableInfos枚举恢复对象,而pkg/frontend/snapshot.go:2106无条件追加:因此
RESTORE DATABASE ... {snapshot=...}与 Issue 中的 CLONE/Data Branch 是同一根因,建议回归用例同时覆盖数据库级 Snapshot 恢复,并校验 Sequence 定义/状态及依赖视图可用性。fix: preserve expression defaults in SHOW CREATE TABLE and CLONE (#27136
gouhongshen commentedon Aug 20, 2026
PR #27401 is trying to fix this issue.
fix: preserve sequences in database clone and restore (#27401)
gouhongshen commentedon Aug 21, 2026
PR #27401 has merged and is awaiting manual validation. The issue remains open.
Ariznawlll commentedon Aug 25, 2026
测试版本
原问题验证
在源库创建 seq1、依赖 NEXTVAL('seq1') 的 seq_view 和数据表后,执行 CREATE DATABASE CLONE 。连续 3 轮中,目标库均保留 sequence、view 与表;切换至目标库后查询 seq_view 返回 10,表数据计数为 1。
Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
不适用。本次按用户可见的 CLONE/SQL 接口完成黑盒验证。
回归测试
已有 BVT:clone_database_sequence.sql 及其 .result,覆盖 sequence database clone 的回归路径。
测试证据
latest main 22b91fe 上原始复现和已存在目标库拒绝路径均连续执行 3 轮,结果如上。
另发现从不同默认数据库访问 qualified sequence-backed view 时的名称解析问题,已作为独立 issue #27581 跟踪;该问题不影响本 issue 的 CLONE 保留对象验收。
测试结论
测试通过。
fix: preserve expression defaults in SHOW CREATE TABLE and CLONE (mat…
fix: preserve sequences in database clone and restore (matrixorigin#2…
fix: preserve expression defaults in SHOW CREATE TABLE and CLONE (mat…
fix: preserve sequences in database clone and restore (matrixorigin#2…
fix: preserve expression defaults in SHOW CREATE TABLE and CLONE (mat…
fix: preserve sequences in database clone and restore (matrixorigin#2…