Repository navigation
Description
Description
CREATE TEMPORARY TABLE dst CLONE src is accepted by the SQL grammar, but it cannot create a usable temporary destination. The first execution returns ERROR 1146 for the destination itself and leaves a stale session alias. Within that session, the table is simultaneously:
- absent to
SHOW,SELECT,INSERT, andDROP; - present to all later
CREATE TEMPORARY TABLEstatements.
Even DROP TEMPORARY TABLE IF EXISTS returns success without clearing the ghost alias. The session cannot reuse the name until it disconnects.
Environment
- Branch:
main - Commit:
2d9ee9c75398b5492f14db7d9bd4d9f777251bd3 - Test date:
2026-08-12 - Deployment: local single process, 1 Log Service + 1 TN + 2 CN; reproduced through CN1
Steps to reproduce
Run all statements in one session:
DROP DATABASE IF EXISTS clone_temp_target;
CREATE DATABASE clone_temp_target;
USE clone_temp_target;
CREATE TABLE src(id INT PRIMARY KEY, v VARCHAR(20));
INSERT INTO src VALUES (1,'one'),(2,'two');
CREATE TEMPORARY TABLE temp_dst CLONE src;
SHOW CREATE TABLE temp_dst;
SELECT * FROM temp_dst;
CREATE TEMPORARY TABLE temp_dst CLONE src;
CREATE TEMPORARY TABLE temp_dst(id INT PRIMARY KEY, v VARCHAR(20));
DROP TEMPORARY TABLE IF EXISTS temp_dst;
CREATE TEMPORARY TABLE temp_dst(id INT PRIMARY KEY, v VARCHAR(20));Actual behavior
CREATE TEMPORARY TABLE temp_dst CLONE src;
ERROR 1146 (HY000): no such table clone_temp_target.temp_dst
SHOW CREATE TABLE temp_dst;
ERROR 1146 (HY000): no such table clone_temp_target.temp_dst
SELECT * FROM temp_dst;
ERROR 1146 (HY000): table "temp_dst" does not exist
CREATE TEMPORARY TABLE temp_dst CLONE src;
ERROR 1050 (HY000): table temp_dst already exists
CREATE TEMPORARY TABLE temp_dst(id INT PRIMARY KEY, v VARCHAR(20));
ERROR 1050 (HY000): table temp_dst already exists
DROP TEMPORARY TABLE IF EXISTS temp_dst;
Query OK
CREATE TEMPORARY TABLE temp_dst(id INT PRIMARY KEY, v VARCHAR(20));
ERROR 1050 (HY000): table temp_dst already exists
There is no permanent catalog row for the target.
Expected behavior
Because the grammar explicitly supports the temporary option for CLONE, the statement should create a queryable session-local table containing the source rows.
If temporary CLONE is intentionally unsupported, it must be rejected before creating physical or session state, with a clear unsupported-operation error. A failed statement must never reserve an unusable name in the session.
Stability and controls
- Reproducer:
3/3with independent namestemp_dst_r1,temp_dst_r2, andtemp_dst_r3in one session. - Every first attempt returned
1146; every second attempt returned1050. DROP TEMPORARY TABLE IF EXISTSreturned success but did not clear the stale name.- Permanent catalog count for all three target names:
0. - Fresh-session control: ordinary temporary creation, insert, select, and drop using the same name all succeeded.
CREATE TEMPORARY TABLE ... LIKE srcplusINSERT ... SELECTsucceeded and returned both source rows.- Temporary-source control: cloning a temporary source into a permanent destination succeeded and returned the exact row.
- Source rows remained unchanged.
Evidence
The complete reproducer is preserved at:
/private/tmp/mo-clone-2d9-validation/temp_target.sql
Three-round signature:
r1: first=1146, second=1050
r2: first=1146, second=1050
r3: first=1146, second=1050
permanent-catalog-count=0
Code analysis
The failure crosses the temporary-table create path and the generic block-clone path:
pkg/sql/parsers/dialect/mysql/mysql_sql.y:9843-9854explicitly acceptsCREATE temporary_opt TABLE ... CLONE ...and stores the temporary flag.pkg/sql/compile/ddl.go:1397-1406rewrites the destination to a generated session-local physical name. After creation,pkg/sql/compile/ddl.go:1505-1513registers the user alias;pkg/sql/compile/ddl.go:2091-2095commits that alias beforeCreateTablereturns success.pkg/sql/compile/ddl.go:4033-4047then unconditionally entersRestoreTable.- The clone operator still resolves
Ctx.DstTblName, which is the user-facing alias.pkg/sql/colexec/table_clone/table_clone.go:321-325callsdstDB.Relationwith that alias instead of the generated physical temporary-table name, producing1146. - The statement rollback removes the physical relation, but the already-committed session alias is outside transaction rollback. Subsequent create checks
session.GetTempTableatpkg/sql/compile/ddl.go:1355-1359and returns1050.
This also explains why disconnecting clears the problem while DROP ... IF EXISTS does not.
Regression coverage
Add a same-session distributed CLONE BVT under test/distributed/cases/git4data/clone/ that asserts:
- temporary destination CLONE returns the exact source schema and rows;
- the target is invisible from a second session;
- disconnect removes it;
- any injected or unsupported failure leaves no physical relation and no session alias;
DROP TEMPORARY TABLE IF EXISTStruly releases the name.
Add a focused planner/operator test that verifies the clone destination is the generated temporary physical name, not the user alias.
Related
No matching open or closed issue or fix PR was found using exact searches for CREATE TEMPORARY TABLE ... CLONE, temporary CLONE no such table, and stale temporary-table aliases. #26087 concerns concurrent Data Branch quota accounting and is not a duplicate.
Activity
Ariznawlll commentedon Aug 13, 2026
在最新官方
main上复测,问题仍稳定存在。1d7b6311ce91df0968da435bb405f3d68137c5953/3同一会话内的对照结果:
CREATE TEMPORARY TABLE like_temp LIKE src正常,结构和唯一索引均保留;CREATE TEMPORARY TABLE clone_temp CLONE src每次均返回ERROR 1146: no such table clone_temp_repro.clone_temp,目标不可查询;SHOW FULL TABLES中没有目标永久表。最新代码路径仍与 issue 描述一致:
CREATE temporary_opt TABLE ... CLONE ...:pkg/sql/parsers/dialect/mysql/mysql_sql.y:9911;Scope.TableClone创建临时目标后无条件进入RestoreTable:pkg/sql/compile/ddl.go:4040-4054;TableClone.Prepare使用逻辑目标名执行dstDB.Relation(...):pkg/sql/colexec/table_clone/table_clone.go:296-298,无法解析已编码的会话临时物理关系。服务端日志也明确记录失败发生在
[RestoreTable] clone (s.Run)之后,statement status 为 fail,错误即目标逻辑名不存在。fix: support cloning into temporary tables (#27070)
gouhongshen commentedon Sep 8, 2026
Automated AI triage
This issue requires human involvement and cannot currently be completed independently by the
automated fix loop.
Reason
The frontend/release owner must validate the repaired supported revision and disposition the open issue, or provide a new post-fix failing sequence. No additional independent implementation is established.
Evidence
The reported inconsistent alias/physical-table state is already addressed by merged PR #27070, commit 37fcd20. Inspected origin/main contains physical destination resolution, alias transaction ownership, and temporary_table_clone.sql; local c838d31 predates the repair.
Please use this analysis to provide the missing decision, environment, evidence, or ownership
needed before the issue is returned to the AI candidate pool.
fix: support cloning into temporary tables (matrixorigin#27070)
fix: support cloning into temporary tables (matrixorigin#27070)
fix: support cloning into temporary tables (matrixorigin#27070)
gouhongshen commentedon Oct 15, 2026
已修复
Ariznawlll commentedon Oct 15, 2026
测试版本
main83222fa8371007c7969d3aeca3ab8ced90695f4c127.0.0.1:16001,数据目录与其他测试隔离。原问题验证
使用原 issue 的
src(id INT PRIMARY KEY, v VARCHAR(20))与两行(1,'one'), (2,'two'),在同一会话执行CREATE TEMPORARY TABLE dst CLONE src。修复后建表成功,SELECT id,v ORDER BY id精确返回上述两行,SHOW CREATE TABLE显示临时表与主键;不再出现原先首次1146、之后名称被幽灵别名占用的现象。使用独立临时表名重复 3/3 轮,均成功;每轮 DROP 后同名普通临时表可创建、写入、查询。Happy Path 覆盖
MIN(id)=1、MAX(id)=2,源表始终为 2 行、SUM(id)=3。DROP TEMPORARY TABLE后立即复用同名,分别写入7/8/9并查询,均为 1 行且值准确。1146;B 可独立创建同名临时表并读到自己的99,A 仍读到原来的(1,'one'), (2,'two')。A 断开后,其他会话仍看不到其临时表,同名可重新创建。Unhappy Path 覆盖
1050;原临时表仍是两行,未重复追加或损坏。1064;随后同会话立即创建同名普通临时表、写入10并读到 1 行,确认失败没有留下不可用的会话别名。1146,不会越过会话可见性边界;两会话同名表互不覆盖。(1,'one'), (2,'two');测试库已删除。白盒验证
本轮未做内部注入;原缺陷和失败原子性可由公开 SQL 与双会话直接观察。未把本地单 CN 测试扩大解释为多 CN 故障注入结果。
回归测试
12_git4datasuite 运行 81 例:79 通过、1 跳过、1 失败。失败是另一用例issue_26072_special_float_materialization的冲突错误文案 golden 差异(预期 DELETE/DELETE,实际 UPDATE/UPDATE);该用例仍返回冲突并保持目标数据不变,与 [Bug]: CREATE TEMPORARY TABLE ... CLONE leaves an unqueryable session ghost after failing #27042 的 3/3 结果无关。未修改其 golden。测试证据
/private/tmp/motr-27042-20261015.sa72nP/motr/var/log/run-1792064439020229000,摘要total=3 success=3 failed=0、stmts=81 ok=81 fail=0。/private/tmp/motr-27042-20261015.sa72nP/motr/var/log/run-1792064301301602000;失败项差异已在上文说明。测试结论
测试通过。