Skip to content

[Bug]: CREATE DATABASE CLONE fails when the source contains an external table #27103

Closed

Description

@Ariznawlll

Description

CREATE DATABASE ... CLONE aborts the entire database clone when the source database contains a readable external table. The implementation enumerates the external relation as a source table, sends it through the base-table clone path, and returns is not BASE TABLE; ordinary tables in the same database are therefore not cloned either.

The documented CLONE restrictions do not list external tables, and the documentation states that database CLONE copies table/database structure, data, and related metadata. External data itself does not need to be copied, but an external table should not make the whole database unclonable: its definition/metadata should be recreated, or it should be skipped consistently and explicitly if that is the intended product contract.

Environment

  • Branch: main
  • Commit: 1d7b6311ce91df0968da435bb405f3d68137c595
  • Deployment: standalone mo-service, isolated local data directory, MySQL protocol port 6002

Steps to reproduce

Create a small CSV on the MatrixOne host:

printf '1,alpha\n2,beta\n' > /tmp/mo_clone_ext_probe.csv

Run:

DROP DATABASE IF EXISTS clone_ext_src;
DROP DATABASE IF EXISTS clone_ext_dst;

CREATE DATABASE clone_ext_src;
CREATE TABLE clone_ext_src.control_t(id INT PRIMARY KEY);
INSERT INTO clone_ext_src.control_t VALUES (1);

CREATE EXTERNAL TABLE clone_ext_src.ext_t(
    id INT,
    payload VARCHAR(20)
)
INFILE{
    'filepath'='/tmp/mo_clone_ext_probe.csv',
    'format'='csv'
}
FIELDS TERMINATED BY ',';

-- Passing source control: returns two rows.
SELECT * FROM clone_ext_src.ext_t ORDER BY id;

CREATE DATABASE clone_ext_dst CLONE clone_ext_src;

Actual behavior

The database clone fails:

ERROR 20101 (HY000): internal error: clone_ext_src.ext_t is not BASE TABLE

The target database does not exist after the failure, so the statement rolls back atomically, but the ordinary table control_t is not cloned either.

Expected behavior

An external table must not abort cloning every supported object in the database. Database CLONE should either:

  1. recreate the external table definition/metadata in the target while leaving the external data in place; or
  2. skip external tables consistently with the snapshot/PITR bulk-restore policy and clearly document/report that limitation without failing the whole database clone.

Stability and controls

  • Reproducer: 3/3 independent source/target database pairs failed with the same is not BASE TABLE error.
  • Control: a database containing only control_t cloned successfully and the target contained the expected row.
  • Source validity: each source external table returned exactly two rows before the clone and remained readable after the failure.
  • Failure atomicity/data check: each failed target database count was 0; source data was unchanged; the service remained responsive.

Evidence

Three-run output excerpt:

control_clone_rows = 1

run1_source_ext_rows = 2
ERROR 20101 (HY000): internal error: clone_ext_src_1.ext_t is not BASE TABLE
run1_target_db_count = 0
run1_source_still_readable = 2

run2_source_ext_rows = 2
ERROR 20101 (HY000): internal error: clone_ext_src_2.ext_t is not BASE TABLE
run2_target_db_count = 0
run2_source_still_readable = 2

run3_source_ext_rows = 2
ERROR 20101 (HY000): internal error: clone_ext_src_3.ext_t is not BASE TABLE
run3_target_db_count = 0
run3_source_still_readable = 2

service_alive = 1

Code analysis

  • pkg/frontend/clone_database_source.go::collectCloneDatabaseSource collects all relations returned by getTableInfos, including external tables.
  • pkg/frontend/clone.go::handleCloneDatabaseWithSource skips only views in its general loop and calls the table-clone path for every other relation.
  • pkg/sql/plan/build_ddl.go explicitly rejects catalog.SystemExternalRel in the CREATE TABLE ... LIKE/CLONE path with %s.%s is not BASE TABLE.
  • In contrast, snapshot/PITR bulk-restore code explicitly skips external tables because their data is stored outside MatrixOne.

The likely defect is missing external-table routing in database CLONE: it neither recreates/skips the metadata nor excludes the relation before invoking base-table CLONE.

Regression coverage

Add a BVT under test/distributed/cases/git4data/clone/ that creates one ordinary table and one local-file external table, runs database CLONE, and verifies the documented external-table policy plus successful cloning of the ordinary table. Cover live and snapshot database CLONE if external-table behavior is intended to be identical.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 13, 2026
  2. added
    kind/bug
    on Aug 13, 2026
  3. added theissue type on Aug 13, 2026
  4. gouhongshen commented on Aug 13, 2026

    @gouhongshen
    Contributor

    Automated AI triage

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

    Reason

    Requires clone product owners to decide whether database clone recreates external-table metadata or explicitly omits external tables. The human next action is to approve and document one contract.

    Evidence

    The current clone path treats non-view relations as cloneable base tables, while the issue explicitly offers two incompatible expected behaviors.

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

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

    @gouhongshen
    Contributor

    PR #28146 is trying to fix this issue.

  7. gouhongshen commented on Sep 5, 2026

    @gouhongshen
    Contributor

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

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

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    在两个 CN 都放置可读 CSV 后,源库包含 2 行可读 external table 和 1 行普通表。连续 3 个独立源/目标库执行 CREATE DATABASE ... CLONE 均成功:源 external table 每次返回 2 行,目标库存在且普通表返回 1 行;目标 SHOW TABLES 仅包含普通表,符合外部表跳过策略。

    Happy Path 覆盖

    1. 可读 external table 不再阻断数据库 CLONE。
    2. 同库普通表及其数据可被正确克隆。

    Unhappy Path 覆盖

    1. 验证目标没有被误建 external table,避免将仅在源 CN 可读的本地文件元数据带入目标。

    白盒验证

    实现 PR 已新增 clone source/权限重映射相关单测;本次不以白盒结果替代部署 SQL 验收。

    回归测试

    已由 MatrixOne PR #28146 添加 test/distributed/cases/git4data/clone/issue_27103_clone_external_table.sql 及 result,覆盖 external table 跳过和普通表克隆。

    测试证据

    PR #28146 文件清单;三轮环境实测均为 source external rows=2、target db=1、control rows=1。

    测试结论

    测试通过。

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