Repository navigation
Description
Summary
RENAME TABLE <name> TO <new> fails in MatrixOne whenever a same-name TEMPORARY table shadows the base table, even though the statement is valid MySQL DDL whose target (the base table) exists. MatrixOne resolves the name with temporary-table priority inside the standalone RENAME TABLE compiler path and then unconditionally rejects the statement because the resolved def is temporary:
ERROR 20102 (HY000): alter table for temporary table is not yet implemented
The base table never gets renamed. MySQL 8.0 runs the same statement successfully: standard RENAME TABLE semantics do not see temporary tables at all, so the base table is renamed while the temporary table keeps its own (unchanged) name and stays visible to its session.
Note this is a name-resolution failure, not a not supported exclusion: the user never asked to rename the temporary table. The genuinely-temporary rename feature (ALTER TABLE <temp> RENAME TO ...) is already supported in MatrixOne (fixed via #28324 for #28303); only the standalone RENAME TABLE statement resolves the temporary shadow and dies.
Environment
- Branch Name: main
- Commit ID: 553bf39
- Other Environment Information:
- Hardware parameters: Apple silicon (macOS arm64)
- OS type: darwin (macOS)
- Others: single-node
mo-servicestarted viamo-service -launch(launch config copied frometc/launch, all ports offset by +20000, MySQL protocol port 26001, fresh data dir). Reference oracle: MySQL 8.0.46 (Homebrew[email protected]) on the same machine with default settings. All quoted outputs are verbatim.
Actual Behavior
With a base table real1 and a session-local TEMPORARY real1 shadowing it:
mysql> create table real1(x int);
Query OK, 0 rows affected
mysql> insert into real1 values (11);
Query OK, 1 row affected
mysql> create temporary table real1(y int);
Query OK, 0 rows affected
mysql> insert into real1 values (22);
Query OK, 1 row affected
mysql> rename table real1 to real2;
ERROR 20102 (HY000): alter table for temporary table is not yet implemented
mysql> show tables like 'real%';
+------------------+
| Tables_in_loom13 |
+------------------+
| real1 |
+------------------+
mysql> select * from real2;
ERROR 1146 (42S02): SQL parser error: table "real2" does not exist
The base table stays under its old name; nothing is renamed; the user cannot rename real1 at all while the temporary shadow exists (the only workaround is to drop the temporary table first).
Control comparison: ALTER TABLE real3 ADD COLUMN z int under the same shadow resolves to the temporary table and succeeds on it - identical to MySQL - proving that per-statement resolution rules are expected to differ and that only the RENAME TABLE path takes the wrong branch.
Second manifestation: when the name exists ONLY as a temporary table (no base table), MySQL reports ERROR 1146 (42S02): Table '...onlytemp' doesn't exist while MatrixOne reports the same misleading NYI error 20102 alter table for temporary table is not yet implemented.
Expected Behavior
Match MySQL 8.0 semantics for RENAME TABLE under a temporary shadow:
mysql> rename table real1 to real2;
Query OK, 0 rows affected
mysql> show tables like 'real%';
+--------------------------+
| Tables_in_loom13 (real%) |
+--------------------------+
| real2 |
+--------------------------+
mysql> select * from real1; -- the temporary table keeps its name
+------+
| y |
+------+
| 22 |
+------+
mysql> select * from real2; -- the renamed base table
+------+
| x |
+------+
| 11 |
+------+
i.e. RENAME TABLE must not resolve through (nor be blocked by) the session's temporary shadow: it should rename the base table. When only a temporary table holds the name, the statement should fail like MySQL with a no such table / table doesn't exist error rather than the NYI message.
Steps to Reproduce
- Start a fresh single-node MO instance at commit 553bf39 (e.g.
mo-service -launch <config>; no special settings, default sql_mode). - Connect with the mysql client and run:
create database loom13; use loom13;
create table real1(x int);
insert into real1 values (11);
create temporary table real1(y int);
insert into real1 values (22);
rename table real1 to real2; -- MO: ERROR 20102 NYI; MySQL: Query OK, base renamed
show tables like 'real%'; -- MO: real1 (nothing renamed); MySQL: real2
select * from real1; -- both: temp row 22 under old name
select * from real2; -- MO: no such table; MySQL: base row 11
-- temp-only variant
drop table real1; -- drops the shadowing temp on both engines
drop table if exists real2;
create temporary table onlytemp(a int);
rename table onlytemp to onlytemp2;
-- MO: ERROR 20102 alias NYI
-- MySQL: ERROR 1146 (42S02): Table ... doesn't exist- Run the identical script on MySQL 8.0.46 for comparison (outputs quoted above/below).
Additional information
Root cause: buildRenameTable (pkg/sql/plan/build_ddl.go, function starting line 6848) resolves the old name with the ordinary temporary-first resolution:
// line 6874
objRef, tableDef, err = ctx.Resolve(schemaName, tableName, nil)and then unconditionally rejects any temporary def:
// lines 6893-6895
if tableDef.IsTemporary {
return nil, moerr.NewNYI(ctx.GetContext(), "alter table for temporary table")
}So a shadowed base name is diverted into the temporary rejection branch, and the statement fails instead of renaming the base table.
Suggested fix: in buildRenameTable, resolve the BASE table specifically (exclude the session's temporary shadow from resolution, as the RENAME semantics require), e.g. by resolving with the base-catalog path / skipping the temporary alias when the resolved def is temporary while a base table of that name exists. Optionally, when only a temporary table holds the name, surface moerr.NewNoSuchTable to match MySQL's diagnosis. The ALTER TABLE ... RENAME TO path (pkg/sql/plan/build_alter_table.go, allowTempTableAlter whitelist) needs no change: per #28303 its temporary-table support is intentional and MySQL-compatible, and this report deliberately does not ask to change any existing data or ALTER behavior - only the standalone RENAME TABLE resolution.
Dedup check performed against:
- [Compatibility]: temporary tables reject column and rename ALTER operations #28303 (closed): temporary-table ALTER ops incl.
ALTER TABLE <temp> RENAME TO- fixed by PR fix: support altering temporary table columns and names #28324; verified working at HEAD; it did not cover the standaloneRENAME TABLEstatement resolving a shadow, which still fails here. - [Bug] RENAME TABLE with multiple pairs is non-atomic; partial failures leave the database in inconsistent state #25120 (closed): RENAME atomicity across multiple pairs - unrelated.
- [Bug]: COPY ALTER fails on table names containing an embedded backtick #30550 (open): COPY ALTER on backquoted names - unrelated.
No in-repo docs declare RENAME TABLE under a temporary shadow unsupported; the error text mentioning a limitation is a side effect of wrong name resolution, since the executed target was never a temporary table.
Full reproduction, exactly as Loom ran it
-- Minimal repro (MO commit 553bf39dbb vs MySQL 8.0.46, default settings)
create database loom13; use loom13;
create table real1(x int);
insert into real1 values (11);
create temporary table real1(y int);
insert into real1 values (22);
rename table real1 to real2;
-- MO: ERROR 20102 (HY000): alter table for temporary table is not yet implemented
-- MySQL: Query OK, 0 rows affected (renames the BASE table)
show tables like 'real%';
-- MO: real1 (nothing renamed)
-- MySQL: real2
select * from real1;
-- both: the temporary table, row 22, still under the old name
select * from real2;
-- MO: ERROR: table "real2" does not exist
-- MySQL: row 11 (renamed base table)
show create table real2;
-- MO: ERROR 1146
-- MySQL: CREATE TABLE `real2` (`x` int DEFAULT NULL) ... <- the base table
-- second manifestation: name exists only as a temporary table
create temporary table onlytemp(a int);
insert into onlytemp values (1);
rename table onlytemp to onlytemp2;
-- MO: ERROR 20102: alter table for temporary table is not yet implemented
-- MySQL: ERROR 1146 (42S02): Table 'loom13.onlytemp' doesn't exist
-- control: ALTER under the same shadow behaves identically in both engines
create table real3(p int);
insert into real3 values (33);
create temporary table real3(q int);
insert into real3 values (44);
alter table real3 add column z int default 0;
select * from real3 order by 1; -- both: temp 44 | 0 (ALTER resolves the temp, MySQL-compat)Found by Loom bug hunt (module: sql-compile; tests: unit, white-box, black-box, concurrency; severity: S1)
Activity
fix: ignore temporary aliases in standalone table rename (#31136)
XuPeng-SH commentedon Nov 1, 2026
QA 转测(2026-11-01,main)
修复 PR #31136 已于 2026-11-01 01:14:21 UTC 合入 main,merge SHA:
9c17596a185a5fd85b545be0dd1de602e0c81656。范围:独立
RENAME TABLE的源/目标查找及 PREPARE 依赖统一使用持久表命名空间,跳过会话临时别名;普通 SELECT/DML/ALTER 保持临时表优先,物理临时表所有权校验保持不变。已读取本 issue 全文及全部评论(交接前 0 条)、PR 修复范围和评审。旧评审中的跨会话替换源表导致 prepared rename 使用过期依赖的问题,已由后续修复及最新评审明确解决;未发现当前适用的已验证反例或未完成开发 follow-up。证据边界:PR 作者报告 focused planner/PREPARE、完整 plan 包、resolver 所有权/委托控制、真实 SQL 的
TestRenameTableIgnoresTemporaryAliases与TestRenameTableImplicitCommit通过;最新评审(5723675419,headd72d6170d8a1e473369230acdd987c4d28c28e67)报告四包 focused tests 共 51 个 test/subtest 通过,并确认旧评审问题解决。这些是远端作者/评审记录,不是本轮本地实测;旧 BVT 记录不能等同当前合并版本全量验收。请 QA 在包含上述 merge SHA 的构建复核:源表被临时表遮蔽、临时表独占源/目标名、持久目标冲突、多对/链式 rename 原子性、临时表数据及持久表 ID 保持、PREPARE 前后新增别名,以及跨会话将持久源替换为 view/创建持久目标后的正常失效与报错;同时确认 ALTER 和临时表隔离未回归。本轮未跑完整 BVT、多 CN、race 或性能测试,建议按环境补充。
本次仅交接待 QA 验证,不表示验收通过;不自动要求 backport。
Ariznawlll commentedon Nov 1, 2026
结论
测试通过。独立
RENAME TABLE对临时表遮蔽的源和目标按持久表命名空间处理,临时表与持久表数据保持正确。关键证据
main@9c17596a185a5fd85b545be0dd1de602e0c81656,修复 fix: ignore temporary aliases in standalone table rename #31136 合并提交即此 SHA;本地隔离 2 CN / 1 TN / 1 LogService。二进制构建信息vcs.revision与 SHA 一致、vcs.modified=false;本地直接构建未注入版本字符串,SQLgit_version()为unknown。rel_id不变;只有临时源时返回 1146,原临时行保留。ALTER TABLE正常控制仍操作临时表。MO_SECOND_CN_PORT时只用同 CN 的两条会话,不代表跨 CN 覆盖。待解决点