Repository navigation
Open
Labels
kind/bugSomething isn't working
Description
Environment
- MatrixOne:
main@ commit b111224 (workspace build), macOS 15.7, arm64, standalonemo-service(ports offset by 20000); behavior cross-checked against the recorded mo-tester result file of the case.
Actual Behavior
The comment block of test/distributed/cases/git4data/clone/temporary_table_clone.sql (lines 54-57) reads:
-- Temporary aliases must follow the same statement and transaction lifecycle
-- as their physical relations. COMMIT keeps a clone; both CREATE and DROP keep
-- their definition change across ROLLBACK; IF NOT EXISTS never changes the
-- pre-transaction mapping.
"both CREATE and DROP keep their definition change across ROLLBACK" is wrong for the CREATE half on this file's own clone path. The approved .result of the very same file (and a live re-run on the current build) shows:
begin; create temporary table temp_txn_rollback clone src; rollback;-> the physical table row is GONE (select count(*) from mo_catalog.mo_tables ... like '__mo_tmp_%_clone_temp_target_temp_txn_rollback'returns 0 in the recorded result, line 77-78), the alias no longer resolves (select count(*) from temp_txn_rollback->SQL parser error: table "temp_txn_rollback" does not exist), andcreate temporary table temp_txn_rollback (id int primary key);succeeds right afterwards (recorded result shows the insert/value 21 working). I.e. a CLONE-created temporary table's definition ROLLS BACK, exactly the opposite of "keeps its definition change across ROLLBACK".- The DROP half of the sentence is correct:
begin; drop temporary table temp_txn_drop; rollback;-> the subsequentselect * from temp_txn_dropfails with 1146 in the recorded result, so the drop persisted.
Live verification on the current build (pymysql, standalone instance) reproduces both halves exactly as recorded.
Expected Behavior
The comment should document the actual, recorded contract of this test file:
CREATE TEMPORARY TABLE ... CLONEexecutes on the internal-executor transaction boundary: its definition change is transactional -- an uncommitted CREATE is removed by ROLLBACK (returning the alias to its pre-transaction state), and a failed CREATE leaves nothing behind.DROP TEMPORARY TABLEon a clone-created temporary table keeps its removal across ROLLBACK.
(COMMIT keeps a clone and the IF NOT EXISTS statement in the same comment are accurate and need no change.)
Steps to Reproduce
- Read
test/distributed/cases/git4data/clone/temporary_table_clone.sqllines 54-57 (comment) and lines 65-74 (thetemp_txn_rollbacksequence). - Read the same file's recorded result
temporary_table_clone.resultlines 68-84: afterbegin; create temporary table temp_txn_rollback clone src; select count(*) (2); rollback;the physical-table count is0andcreate temporary table temp_txn_rollback (id int primary key)succeeds with the insert of 21 visible. - Or run it live:
CREATE DATABASE loomclone; USE loomclone;
CREATE TABLE src(id INT PRIMARY KEY, v VARCHAR(10));
INSERT INTO src VALUES (1,'a'),(2,'b');
BEGIN;
CREATE TEMPORARY TABLE temp_txn_rollback CLONE src;
SELECT COUNT(*) FROM temp_txn_rollback; -- 2 (visible inside the txn)
ROLLBACK;
SELECT COUNT(*) FROM mo_catalog.mo_tables
WHERE reldatabase='loomclone'
AND relname LIKE '\_\_mo\_tmp\_%\_loomclone\_temp\_txn\_rollback'; -- 0 <-- definition rolled back
SELECT COUNT(*) FROM temp_txn_rollback;
-- ERROR 1146: table "temp_txn_rollback" does not exist
CREATE TEMPORARY TABLE temp_txn_rollback (id INT PRIMARY KEY); -- succeeds (no stale generation)
-- contrast, same session:
BEGIN; DROP TEMPORARY TABLE temp_txn_rollback; ROLLBACK;
SELECT COUNT(*) FROM temp_txn_rollback;
-- ERROR 1146 (drop persisted, matching the comment's DROP half)Additional information
- The confusion source is a documented-contract over-generalization:
docs/design/20260907-temporary-ddl-transaction-boundary.mdline 14 states "A successful temporary-table CREATE or DROP remains effective after rollback" -- but that contract covers the protocol 55 frontend DDL path only, while CLONE destinations go through the internal executor whose transaction ("The internal executor owns rollback/commit", design doc line 73) carries the definition change. My plain-path verification confirms the intended asymmetry: a frontendCREATE TEMPORARY TABLE t (...)inside a rolled-back transaction leaves the alias usable (definition survives), while the CLONE form in the identical sequence does not. - Impact: the comment sits directly above the assertions that prove the opposite; future maintainers grepping the file for the transaction contract (or porting the sequence to new cases) will encode the wrong semantics, and reviewers of a genuine behavioral regression (clone CREATE no longer rolling back) may treat the correct behavior as the bug.
- Recommended fix: reword lines 55-56 to e.g. "COMMIT keeps a clone; a CLONE-created definition rolls back with an uncommitted CREATE, while DROP keeps its removal across ROLLBACK; IF NOT EXISTS never changes the pre-transaction mapping", which matches the recorded .result, the design doc's split between the frontend and internal-executor paths, and current behavior. No data or behavior change is needed; the recorded result is the correct ground truth.
Full reproduction, exactly as Loom ran it
# 1) Diff the case comment vs its approved result:
grep -n "both CREATE and DROP keep" test/distributed/cases/git4data/clone/temporary_table_clone.sql
# 55:-- as their physical relations. COMMIT keeps a clone; both CREATE and DROP keep
sed -n 65,78p test/distributed/cases/git4data/clone/temporary_table_clone.result
# create temporary table temp_txn_rollback clone src; select count(*) -> 2; rollback;
# select count(*) from mo_catalog.mo_tables ... like '__mo_tmp_%_clone_temp_target_temp_txn_rollback'; -> 0
# 2) Live run (standalone mo-service, mysql client):
CREATE DATABASE loomclone; USE loomclone;
CREATE TABLE src(id INT PRIMARY KEY, v VARCHAR(10));
INSERT INTO src VALUES (1,'a'),(2,'b');
BEGIN;
CREATE TEMPORARY TABLE temp_txn_rollback CLONE src;
SELECT COUNT(*) FROM temp_txn_rollback; -- 2
ROLLBACK;
SELECT COUNT(*) FROM mo_catalog.mo_tables WHERE reldatabase='loomclone' AND relname LIKE '\_\_mo\_tmp\_%\_loomclone_temp_txn_rollback'; -- 0 (definition rolled back)
SELECT COUNT(*) FROM temp_txn_rollback; -- ERROR 1146
CREATE TEMPORARY TABLE temp_txn_rollback (id INT PRIMARY KEY); -- succeeds
BEGIN; DROP TEMPORARY TABLE temp_txn_rollback; ROLLBACK;
SELECT COUNT(*) FROM temp_txn_rollback; -- ERROR 1146 (drop persisted: comment half right)Found by Loom bug hunt (module: custom-5ec72c0c38; tests: unit, white-box, end-to-end)
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't working
Activity