Repository navigation
Description
Summary
DATA BRANCH CREATE DATABASE mishandles database objects when a database, foreign-key table, or dependent view name contains the legal identifier character #.
For foreign-key table names containing #, the statement reports success, but none of the affected tables or rows are copied. For a source database name containing #, the statement fails while resolving the foreign key and rolls the destination back. Dependent view names containing # either make the operation fail or produce a successful destination that is missing all views. The ordinary database CLONE path has the same table-name behavior because both paths share the database source collector.
Environment
- Branch:
main - Commit:
2eb7f523e5a10f352d3e258183ed8440510388de - MatrixOne endpoint: local standalone server
Reproduction
DROP DATABASE IF EXISTS g4d_hash_fk_src;
DROP DATABASE IF EXISTS g4d_hash_fk_dst;
CREATE DATABASE g4d_hash_fk_src;
USE g4d_hash_fk_src;
CREATE TABLE `parent#p` (
id INT PRIMARY KEY,
note VARCHAR(32)
);
CREATE TABLE `child#c` (
id INT PRIMARY KEY,
parent_id INT,
CONSTRAINT fk_hash_parent
FOREIGN KEY (parent_id) REFERENCES `parent#p`(id)
);
INSERT INTO `parent#p` VALUES (1, 'one'), (2, 'two');
INSERT INTO `child#c` VALUES (10, 1), (20, 2);
DATA BRANCH CREATE DATABASE g4d_hash_fk_dst FROM g4d_hash_fk_src;
SHOW FULL TABLES FROM g4d_hash_fk_dst;The source objects and join are valid:
child#c BASE TABLE
parent#p BASE TABLE
10 one
20 two
Actual result
DATA BRANCH CREATE DATABASE returns success, while SHOW FULL TABLES FROM g4d_hash_fk_dst returns no rows.
The result reproduced in 3 out of 3 independent destination databases. The source database remained readable after every attempt.
The shared ordinary path behaves the same way:
CREATE DATABASE g4d_hash_fk_clone_dst CLONE g4d_hash_fk_src;
SHOW FULL TABLES FROM g4d_hash_fk_clone_dst;It also succeeds with an empty destination.
A source database name containing # reproduces the same key-decoding defect through a different later path:
CREATE DATABASE `g4d#hash_fk_src`;
USE `g4d#hash_fk_src`;
CREATE TABLE parent_p (id INT PRIMARY KEY);
CREATE TABLE child_c (
id INT PRIMARY KEY,
parent_id INT,
FOREIGN KEY (parent_id) REFERENCES parent_p(id)
);
DATA BRANCH CREATE DATABASE g4d_hash_fk_db_dst FROM `g4d#hash_fk_src`;This variant failed in 3 out of 3 attempts with:
internal error: can't find fkTable from fk ...child_c.(parent_id)
The failed destination database was absent after each attempt, so rollback remained atomic.
Dependent views are affected by the same key representation:
CREATE DATABASE g4d_hash_view_src;
USE g4d_hash_view_src;
CREATE TABLE base_t (id INT PRIMARY KEY, v INT);
CREATE VIEW `view#1` AS SELECT id, v FROM base_t;
CREATE VIEW `view#2` AS SELECT id, v + 1 AS v2 FROM `view#1`;
DATA BRANCH CREATE DATABASE g4d_hash_view_dst FROM g4d_hash_view_src;
SHOW FULL TABLES FROM g4d_hash_view_dst;Across four attempts, every result was incorrect:
- two attempts returned success but copied only
base_t, silently omitting both views; - two attempts failed while restoring
view#1and rolled the destination back.
A single view whose name contains # but does not depend on another view copied successfully. The defect appears when the encoded object keys participate in dependency ordering.
Expected result
Both foreign-key-related tables, their data, and the foreign-key definition should be present in the destination database. If this identifier form cannot be supported, the statement should return an explicit error and leave no successful-but-empty result.
Code analysis
Database cloning represents an object key as:
const KeySep = "#"
func genKey(dbName, tblName string) string {
return fmt.Sprintf("%s%s%s", dbName, KeySep, tblName)
}The reverse operation uses an unrestricted split and keeps only the first two components:
func splitKey(key string) (string, string) {
parts := strings.Split(key, KeySep)
if len(parts) >= 2 {
return parts[0], parts[1]
}
return parts[0], ""
}For g4d_hash_fk_src#parent#p, this resolves the table name as parent instead of parent#p. getTableInfoMap therefore cannot populate the expected table information. Later, handleCloneDatabaseWithSource skips these tables in the ordinary loop because they are foreign-key members, but the foreign-key loop has no valid table information to clone.
For a key such as g4d#hash_fk_src#parent_p, the decoded database and table are g4d and hash_fk_src, so foreign-key restoration cannot find the referenced table. The same lossy decoding is used while rewriting and ordering dependent views.
Relevant locations:
pkg/frontend/util.go:genKey,splitKeypkg/frontend/snapshot.go:getFkDeps,getTableInfoMap,fkTablesTopoSortpkg/frontend/clone.go:handleCloneDatabaseWithSource
Activity
[-][Bug]: Database CLONE and DATA BRANCH silently skip FK tables whose names contain #[/-][+][Bug]: Database CLONE and DATA BRANCH mishandle FK identifiers containing #[/+][-][Bug]: Database CLONE and DATA BRANCH mishandle FK identifiers containing #[/-][+][Bug]: Database CLONE and DATA BRANCH mishandle object identifiers containing #[/+]VioletQwQ-0 commentedon Jul 29, 2026
PR #26230 merged as
c6d7a1168c5c02e4578359dedaee27dd1dc1950e(reviewed head9b1c5bcc20601780a9351eab5359b5e1fa3741ea). The corrected repeatable embedded regression, codec coverage, and required CI passed.QA handoff on main
f6dab28046d70412cec132f0068840896852101c:#in database, table, and view identifiers.Pass: identifiers round-trip losslessly and all rows/FKs/views survive both copy modes. Fail: truncated identity, omitted dependency, wrong FK target, or repeat-run cleanup failure.
VioletQwQ-0 commentedon Jul 29, 2026
PR #26230 merged as
c6d7a1168c5c02e4578359dedaee27dd1dc1950e(reviewed head9b1c5bcc20601780a9351eab5359b5e1fa3741ea). The corrected repeatable embedded regression, codec coverage, and required CI passed.QA handoff on main
f6dab28046d70412cec132f0068840896852101c:#in database, table, and view identifiers.Pass: identifiers round-trip losslessly and all rows/FKs/views survive both copy modes. Fail: truncated identity, omitted dependency, wrong FK target, or repeat-run cleanup failure.
Ariznawlll commentedon Jul 29, 2026
已在最新
main分支完成验证。测试版本:
52ea9f874f492c368a20efef16b46ab8ced2de37测试拓扑:Proxy + 2 CN
重复次数:3 轮
测试过程:
#。测试结果:
#的标识符均能无损 round-trip,没有被截断。结论:该问题在上述最新 main commit 上验证通过。
Ariznawlll commentedon Jul 30, 2026
已在
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c补充完成黑盒和白盒验证。黑盒验证:
#。结果:该 case
27/27条 SQL/断言通过;本轮 Data Branch 全集13/13case、280/280条 SQL/断言通过。白盒验证:
Unhappy path / 依赖完整性:
#的 database/table/view dependency key 做 round-trip,防止 split 后静默丢失对象。结论:含
#object key 的编码/兼容解码以及数据库复制依赖路径均验证通过,黑盒回归已加入 motr#69。Ariznawlll commentedon Jul 30, 2026
Unhappy Path / 依赖完整性专项验证
测试版本:
main@0ebba1c0c96bbcf0ff4091236e10df7b97e24a0c专项覆盖:
#。#的 object key 做 encode/decode round-trip,避免 split 后静默丢对象。结果:两种非法 FK 写入均被拒绝;失败后无部分数据写入;源/branch/clone 相互隔离;重建成功。专项用例
27/27条 SQL/断言通过,object key 和 issue Go 测试返回ok。测试结论
测试通过。