Skip to content

Commit af650c7

Browse files
committed
MDEV-18460: Server crashed in strmake / tdc_create_key / THD::create_tmp_table_def_key
When there is a WITH clause we postpone check for tables without database for later stages when tables in WITH will be defined. But we should not try to open such tables as temporary tables because temporary tables always belong to a some database.
1 parent 425748f commit af650c7

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

mysql-test/r/cte_nonrecursive.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,3 +1673,21 @@ with columns as (select 1 as t) select * from columns;
16731673
t
16741674
1
16751675
use test;
1676+
#
1677+
# MDEV-18460: Server crashed in strmake / tdc_create_key /
1678+
# THD::create_tmp_table_def_key
1679+
#
1680+
connect con1,localhost,root,,;
1681+
CREATE TEMPORARY TABLE test.t (a INT);
1682+
WITH cte AS (SELECT 1) SELECT * FROM cte;
1683+
1
1684+
1
1685+
WITH t AS (SELECT 1) SELECT * FROM t;
1686+
1
1687+
1
1688+
WITH cte AS (SELECT 1) SELECT * FROM t;
1689+
ERROR 3D000: No database selected
1690+
DROP TABLE test.t;
1691+
connection default;
1692+
disconnect con1;
1693+
# End of 10.2 tests

mysql-test/t/cte_nonrecursive.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,3 +1182,23 @@ with t as (select 1 as t) select * from t;
11821182
with columns as (select 1 as t) select * from columns;
11831183

11841184
use test;
1185+
1186+
--echo #
1187+
--echo # MDEV-18460: Server crashed in strmake / tdc_create_key /
1188+
--echo # THD::create_tmp_table_def_key
1189+
--echo #
1190+
1191+
--connect con1,localhost,root,,
1192+
--change_user root,,
1193+
1194+
CREATE TEMPORARY TABLE test.t (a INT);
1195+
WITH cte AS (SELECT 1) SELECT * FROM cte;
1196+
WITH t AS (SELECT 1) SELECT * FROM t;
1197+
--error ER_NO_DB_ERROR
1198+
WITH cte AS (SELECT 1) SELECT * FROM t;
1199+
DROP TABLE test.t;
1200+
1201+
--connection default
1202+
--disconnect con1
1203+
1204+
--echo # End of 10.2 tests

sql/temporary_tables.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
338338
DBUG_RETURN(false);
339339
}
340340

341+
if (!tl->db)
342+
{
343+
DBUG_PRINT("info",
344+
("Table reference to a temporary table must have database set"));
345+
DBUG_RETURN(false);
346+
}
347+
341348
/*
342349
Temporary tables are not safe for parallel replication. They were
343350
designed to be visible to one thread only, so have no table locking.

0 commit comments

Comments
 (0)