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
Dotted identifiers are legal: create database \x.y`andcreate temporary table x.`y.t`both succeed, and in a session with no temporary tablesselect ... from `x.y`.t returns the permanent rows (99 permanent_in_x.y` - control run).
But the session temporary-table alias map is keyed by the plain concatenation dbName + "." + alias, so the pair (x, y.t) and the pair (x.y, t) collide on the same key x.y.t. In one session:
Sequence A (temporary table x.\y.t`` created first):
select id, v from \x.y`.t(unrelated permanent table) ->ERROR 1146 (42S02) SQL parser error: table "t" does not exist` - even though the control run in a fresh session reads the same table fine.select id, v from x.\y.t`-> returns its own row1 temp_in_x_dotted` (this alias works).create temporary table \x.y`.t (id int primary key, v varchar(20));->ERROR 1050 (42S01) table t already exists- wrongly: no temporary table exists inx.y`, and MySQL accepts this statement.
So after creating one dotted temporary alias, every reference to x.y.t in that session is broken: reads report the table does not exist and creating a temporary table there is rejected as duplicate.
Sequence B (temporary table x.y.t created first):
create temporary table x.\y.t`->ERROR 1050 (42S01) table y.t already exists` (wrongly rejected, symmetric collision).select id, v from x.\y.t`->ERROR 1146 table "y.t" does not exist` (it was never created).
Sequence A reproduced 3 times, sequence B once, all identical.
MySQL 8.0 comparison - the same two sequences on a temporary [email protected] 8.0.46 instance (see evidence): every statement succeeds and each namespace keeps its own rows - x.y.t (permanent) returns 99, x.\y.t`returns1, create temporary table `x.y`.tsucceeds and returns100, and in sequence B both temporary tables coexist (100and1`). No interference.
Expected Behavior
(database, alias) pairs are distinct namespaces even when the identifiers contain dots: creating session temporary table x.\y.t`must have no effect onx.y.t- reading the permanentx.y.tkeeps returning its own rows, andcreate temporary table `x.y`.t` must succeed with both tables readable afterwards (MySQL 8.0 behavior, verified locally).
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- Control - a fresh connection, permanent table only (reads fine):
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force <<'EOF'
drop database if exists `x.y`;
drop database if exists x;
create database `x.y`;
create database x;
use `x.y`;
create table t (id int primary key, v varchar(20));
insert into t values (99,'permanent_in_x.y');
select id, v from t order by id;
EOF- Sequence A - one connection, whole script:
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force <<'EOF'
use `x.y`;
select id, v from t order by id; -- control inside same connection: 99
use x;
create temporary table `y.t` (id int primary key, v varchar(20));
insert into `y.t` values (1,'temp_in_x_dotted');
select id, v from `x.y`.t order by id; -- ACTUAL: ERROR 1146 table "t" does not exist
create temporary table `x.y`.t (id int primary key, v varchar(20)); -- ACTUAL: ERROR 1050 table t already exists
select id, v from x.`y.t` order by id; -- only this alias works: 1 temp_in_x_dotted
EOF- Sequence B - another fresh connection:
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force <<'EOF'
use `x.y`;
create temporary table t (id int primary key, v varchar(20));
insert into t values (100,'temp_in_x.y');
use x;
create temporary table `y.t` (id int primary key, v varchar(20)); -- ACTUAL: ERROR 1050 table y.t already exists
select id, v from x.`y.t` order by id; -- ACTUAL: ERROR 1146 table "y.t" does not exist
EOF- MySQL 8.0 comparison - run the identical sequences against a temporary
[email protected]instance (same SQL, port 23506, user root): all statements succeed and each table returns its own rows (full output inevidence).
Additional information
Root cause: the session alias map uses an ambiguous string key:
pkg/frontend/session.go:871GetTempTablereadsses.tempTables[dbName+"."+alias].pkg/frontend/temporary_ddl.go:59PublishTemporaryTablewrites the samekey := db + "." + alias(andtempTablesRev/tempTableIdentitiesshare it).
(x, y.t) -> x.y.t and (x.y, t) -> x.y.t are the same key, so the second pair's lookup returns the first pair's physical relation. At read time the aliased physical name is then resolved in the query's database context (x.y), where it does not exist, so the permanent x.y.t surfaces as 1146; at create time the existence check (pkg/sql/compile/temporary_ddl.go:99, which trusts GetTempTable) reports a false 1050. tempTableIdentityLocked (pkg/frontend/session.go:819) has the same ambiguity - its fallback strings.Cut(key, ".") splits at the first dot, so it cannot round-trip dotted identifiers either.
Recommended fix: store the mapping under an unambiguous key - e.g. keep a struct/{db, alias} pair as the map key, or encode the two components with length prefixing/escaping before joining. tempTableIdentities already holds the exact (dbName, alias) pair, so GetTempTable can look up by the structured pair without changing any on-disk format; identifiers without dots keep byte-identical behavior, so existing sessions and tests are unaffected.
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 against a running single-node mo-service (frontend port 26201, user dump/111).
#!/bin/zsh
set -u
DIR=$(mktemp -d)
cat > "$DIR/seq_a.sql" <<'SQL'
drop database if exists `x.y`;
drop database if exists x;
create database `x.y`;
create database x;
use `x.y`;
create table t (id int primary key, v varchar(20));
insert into t values (99,'permanent_in_x.y');
use `x.y`;
select id, v from t order by id;
use x;
create temporary table `y.t` (id int primary key, v varchar(20));
insert into `y.t` values (1,'temp_in_x_dotted');
select id, v from `x.y`.t order by id;
create temporary table `x.y`.t (id int primary key, v varchar(20));
select id, v from x.`y.t` order by id;
SQL
cat > "$DIR/seq_b.sql" <<'SQL'
use `x.y`;
create temporary table t (id int primary key, v varchar(20));
insert into t values (100,'temp_in_x.y');
use x;
create temporary table `y.t` (id int primary key, v varchar(20));
select id, v from x.`y.t` order by id;
SQL
echo "=== control + sequence A (one connection) ==="
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force < "$DIR/seq_a.sql"
echo "=== sequence B (fresh connection) ==="
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 --force < "$DIR/seq_b.sql"
echo "=== cleanup ==="
mysql -h 127.0.0.1 -P 26201 -udump -p111 --default-character-set=utf8mb4 -e 'drop database if exists `x.y`; drop database if exists x'
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.