Repository navigation
Description
Branch Name
main (worktree checked out at commit 57fb953085)
Commit ID
Other Environment Information
- Hardware parameters: Apple Silicon (arm64)
- OS type: macOS 15.5 (darwin)
- Others: single-node
mo-servicebuilt from this worktree withmake build. Launch configuration:etc/launchcopied to.loom-test/launch, every port shifted byLOOM_TEST_PORT_OFFSET=20200(CN port-base 38200, TN 39200, frontend 26201, status 27201, logservice 52200/52201/52202), data directories under.loom-test/mo-data,[hakeeper-client] service-addresses=["127.0.0.1:52201"]added to the cn/tn/log toml files; started with./mo-service -launch .loom-test/launch/launch.toml. Connections use userdump/ password111on frontend port 26201. MySQL 8.0 comparison: Homebrew[email protected]8.0.46,mysqld --initialize-insecuretemporary instance in.loom-test/mysql-dataon port 23506 (3306 + 20200).
Actual Behavior
Two connections as the same user (dump). Session B creates a temporary table in database wedge_db; while B stays connected, session A executes drop database wedge_db. Session B is then left in a self-contradictory state:
select ... from wedge_db.tx->ERROR 1049 (42000) Unknown database wedge_db(the physical root of B's temporary table was destroyed by the database cascade).create database if not exists wedge_db;succeeds.create temporary table tx (id int primary key, v varchar(20));->ERROR 1050 (42S01) table tx already exists- the session still claims the alias exists.insert into tx values (1,'recreated');->ERROR 1146 (42S02) no such table wedge_db.txselect id, v from tx;->ERROR 1146 (42S02) SQL parser error: table "tx" does not exist
So the alias simultaneously "already exists" (CREATE reports 1050) and does not exist (every read/write reports 1146). Session B can never use that temporary alias again - only reconnecting recovers (a fresh session creates wedge_db.tx and uses it normally; see the "fresh session C" section of the reproduction output).
Reproduced 3 times in a row with identical output (the consolidated script was run twice plus an initial manual two-session run).
MySQL 8.0 comparison - same two-session sequence on a temporary [email protected] 8.0.46 instance (see evidence):
- after A's
drop database, B'sselect id, v from p30m.txstill returns1 before(MySQL keeps a session TEMPORARY table alive across another session's DROP DATABASE); create temporary table txreturns 1050, but - unlike MatrixOne - the table really exists: the following insert fails only with a duplicate-key error andselectreturns the original row1 before.
MySQL therefore never enters the contradictory "exists but not exists" state: session B remains fully usable.
Expected Behavior
Once the physical relation backing a session temporary table is gone, the owner session must not keep a half-alive alias. After the database is recreated, CREATE TEMPORARY TABLE tx must succeed and produce a working empty table (reads of the dead alias correctly report "table does not exist" already). The state "CREATE says the table already exists (1050) while every SELECT/INSERT says it does not exist (1146)" must never occur.
Steps to Reproduce
- Build and start the single-node service from the worktree:
cp -r etc/launch .loom-test/launch
# In .loom-test/launch/*.toml: add LOOM_TEST_PORT_OFFSET=20200 to every port
# (cn port-base 38200, tn 39200, frontend 26201, status 27201,
# logservice 52200/52201/52202), point all data dirs to .loom-test/mo-data,
# and add to cn/tn/log toml: [hakeeper-client] service-addresses=["127.0.0.1:52201"]
make build
./mo-service -launch .loom-test/launch/launch.toml- Save the script below as
repro_dropdb_wedge.shand runzsh repro_dropdb_wedge.shagainst frontend port 26201:
#!/bin/zsh
# Minimal repro: session B's temporary table is wedged after another session
# DROPs the database that holds it.
set -u
DIR=$(mktemp -d)
B_SQL="$DIR/b.sql"
B_OUT="$DIR/b.out"
cat > "$B_SQL" <<'SQL'
drop database if exists wedge_db;
create database wedge_db;
create temporary table wedge_db.tx (id int primary key, v varchar(20));
insert into wedge_db.tx values (1,'before');
select 'B_ready' as s, id, v from wedge_db.tx;
select sleep(10);
select 'B_step1_select_after_db_drop' as s;
select id, v from wedge_db.tx;
select 'B_step2_recreate_db_and_temp' as s;
create database if not exists wedge_db;
use wedge_db;
create temporary table tx (id int primary key, v varchar(20));
select 'B_step3_create_temp_succeeded' as s;
insert into tx values (1,'recreated');
select id, v from tx;
drop table if exists tx;
drop database if exists wedge_db;
select 'B_done' as s;
SQL
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force < "$B_SQL" > "$B_OUT" 2>&1 &
BPID=$!
sleep 4
echo "--- session A: drop database wedge_db while B holds a temp table in it ---"
OUT=$(mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 -e "drop database wedge_db" 2>&1)
echo "A drop exit=$? output=[$OUT]"
wait $BPID
echo "--- session B output ---"
grep -v Warning "$B_OUT"
echo "--- fresh session C (reconnect workaround) ---"
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force 2>&1 <<'EOF' | grep -v Warning
create database if not exists wedge_db;
create temporary table wedge_db.tx (id int primary key, v varchar(20));
insert into wedge_db.tx values (1,'fresh-session');
select id, v from wedge_db.tx;
drop table wedge_db.tx;
drop database if exists wedge_db;
EOF
rm -rf "$DIR"- MySQL 8.0 comparison - same sequence against a temporary
[email protected]instance (session B's script identical except for the database namep30m; session A runsdrop database p30mduring B's sleep):
-- session B
drop database if exists p30m;
create database p30m;
create temporary table p30m.tx (id int primary key, v varchar(20));
insert into p30m.tx values (1,'before');
select 'B_ready' as s, id, v from p30m.tx;
select sleep(10);
select 'B_step1_select_after_db_drop' as s;
select id, v from p30m.tx;
select 'B_step2_recreate_db' as s;
create database if not exists p30m;
use p30m;
create temporary table tx (id int primary key, v varchar(20));
select 'B_step3_after_create_temp' as s;
insert into tx values (1,'recreated');
select id, v from tx;
drop table tx;
drop database if exists p30m;
-- session A (separate connection, during B's sleep)
drop database p30m;MySQL output: see evidence.
Additional information
Root cause:
pkg/sql/compile/ddl.go:470-477-dropDatabaseremoves temporary-table aliases only from the session that executesDROP DATABASE(session.RemoveTempTablesByDatabase(dbName)). Every other session keeps its(database, alias) -> physicalbinding, while the catalog cascade physically deletes that database's rows, including other sessions' temporary roots and their hidden index relations.pkg/sql/compile/temporary_ddl.go:99-103-createSessionTemporaryTabledecides existence purely fromc.proc.GetSession().GetTempTable(db, alias)and returnsNewTableAlreadyExistswithout checking whether the bound physical relation still exists (pkg/frontend/session.go:868GetTempTablejust reads the map).- Read/write resolution uses the same stale binding: alias -> physical name -> catalog lookup fails -> 1146 (or 1049 while the database itself is absent).
The migration RFC (docs/rfcs/20260826_proxy_temp_table_migration.md, "Protocol and lifecycle") already acknowledges that "another session can drop or recreate a database without mutating this session's local alias map" and treats BadDB/NoSuchTable as proof that the source mapping is stale - i.e. the stale mapping is expected to be discarded, yet the SQL layer keeps it and wedges the session.
Expected-behavior basis: MySQL 8.0 (verified locally, 8.0.46) keeps session B's TEMPORARY table and its rows alive across another session's DROP DATABASE, so the owner session always stays usable and never sees a contradictory state (full output in evidence).
Recommended fix: validate alias liveness when the stale binding is observed - when the physical relation behind a session alias no longer resolves, evict the alias from the session map (and its reverse entry) so that reads keep reporting "table does not exist" and a subsequent CREATE TEMPORARY TABLE succeeds once the database exists again. This keeps the current physical-storage design and existing data semantics unchanged (a dropped database still releases its tables, matching RemoveTempTablesByDatabase for the executing session) while removing the unrecoverable session state. Full MySQL parity (keeping the table and rows alive across DROP DATABASE) would require exempting other sessions' temporary roots from the database cascade and surviving a database-id change on recreation; that is a much larger design change and is not needed to remove the wedge.
Dedup: gh is not authenticated in this environment (gh auth login / GH_TOKEN unavailable), so gh issue list / gh pr list could not be run; duplicate check skipped.
Full reproduction, exactly as Loom ran it
# Run command (service must be running, frontend port 26201, user dump/111):
# zsh repro_dropdb_wedge.sh
#!/bin/zsh
# Minimal repro: session B's temporary table is wedged after another session
# DROPs the database that holds it.
# CREATE TEMPORARY TABLE tx -> ERROR 1050 table tx already exists
# SELECT/INSERT on tx -> ERROR 1146 no such table
# (MySQL 8.0: B's temporary table and its data survive another session's
# DROP DATABASE and keep working.)
# Requires a running single-node mo-service, frontend port 26201, user dump/111.
set -u
DIR=$(mktemp -d)
B_SQL="$DIR/b.sql"
B_OUT="$DIR/b.out"
cat > "$B_SQL" <<'SQL'
drop database if exists wedge_db;
create database wedge_db;
create temporary table wedge_db.tx (id int primary key, v varchar(20));
insert into wedge_db.tx values (1,'before');
select 'B_ready' as s, id, v from wedge_db.tx;
select sleep(10);
select 'B_step1_select_after_db_drop' as s;
select id, v from wedge_db.tx;
select 'B_step2_recreate_db_and_temp' as s;
create database if not exists wedge_db;
use wedge_db;
create temporary table tx (id int primary key, v varchar(20));
select 'B_step3_create_temp_succeeded' as s;
insert into tx values (1,'recreated');
select id, v from tx;
drop table if exists tx;
drop database if exists wedge_db;
select 'B_done' as s;
SQL
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force < "$B_SQL" > "$B_OUT" 2>&1 &
BPID=$!
sleep 4
echo "--- session A: drop database wedge_db while B holds a temp table in it ---"
OUT=$(mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 -e "drop database wedge_db" 2>&1)
echo "A drop exit=$? output=[$OUT]"
wait $BPID
echo "--- session B output ---"
grep -v Warning "$B_OUT"
echo "--- fresh session C (reconnect workaround) ---"
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force 2>&1 <<'EOF' | grep -v Warning
create database if not exists wedge_db;
create temporary table wedge_db.tx (id int primary key, v varchar(20));
insert into wedge_db.tx values (1,'fresh-session');
select id, v from wedge_db.tx;
drop table wedge_db.tx;
drop database if exists wedge_db;
EOF
rm -rf "$DIR"Found by Loom bug hunt (module: custom-5ec72c0c38; tests: unit, white-box, end-to-end)
Activity
XuPeng-SH commentedon Oct 22, 2026
This report is now tracked together with #30583. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.