summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2019-12-07 22:15:38 +0100
committerOleksandr Byelkin <sanja@mariadb.com>2019-12-10 07:37:18 +0100
commitaf650c76a63838047b268d8106cd229438f6db92 (patch)
tree2e1a0d0c539c7e3cbb5db86f0b11a273f26376bb
parent425748f1b5890a4bb3c7dcadf8f81f567f9a26fe (diff)
downloadmariadb-git-af650c76a63838047b268d8106cd229438f6db92.tar.gz
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.
-rw-r--r--mysql-test/r/cte_nonrecursive.result18
-rw-r--r--mysql-test/t/cte_nonrecursive.test20
-rw-r--r--sql/temporary_tables.cc7
3 files changed, 45 insertions, 0 deletions
diff --git a/mysql-test/r/cte_nonrecursive.result b/mysql-test/r/cte_nonrecursive.result
index 8ad3818b453..746fcbcf051 100644
--- a/mysql-test/r/cte_nonrecursive.result
+++ b/mysql-test/r/cte_nonrecursive.result
@@ -1673,3 +1673,21 @@ with columns as (select 1 as t) select * from columns;
t
1
use test;
+#
+# MDEV-18460: Server crashed in strmake / tdc_create_key /
+# THD::create_tmp_table_def_key
+#
+connect con1,localhost,root,,;
+CREATE TEMPORARY TABLE test.t (a INT);
+WITH cte AS (SELECT 1) SELECT * FROM cte;
+1
+1
+WITH t AS (SELECT 1) SELECT * FROM t;
+1
+1
+WITH cte AS (SELECT 1) SELECT * FROM t;
+ERROR 3D000: No database selected
+DROP TABLE test.t;
+connection default;
+disconnect con1;
+# End of 10.2 tests
diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test
index bd8af55071a..41a5b815bc7 100644
--- a/mysql-test/t/cte_nonrecursive.test
+++ b/mysql-test/t/cte_nonrecursive.test
@@ -1182,3 +1182,23 @@ with t as (select 1 as t) select * from t;
with columns as (select 1 as t) select * from columns;
use test;
+
+--echo #
+--echo # MDEV-18460: Server crashed in strmake / tdc_create_key /
+--echo # THD::create_tmp_table_def_key
+--echo #
+
+--connect con1,localhost,root,,
+--change_user root,,
+
+CREATE TEMPORARY TABLE test.t (a INT);
+WITH cte AS (SELECT 1) SELECT * FROM cte;
+WITH t AS (SELECT 1) SELECT * FROM t;
+--error ER_NO_DB_ERROR
+WITH cte AS (SELECT 1) SELECT * FROM t;
+DROP TABLE test.t;
+
+--connection default
+--disconnect con1
+
+--echo # End of 10.2 tests
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc
index b97e0334f0d..e2179a71625 100644
--- a/sql/temporary_tables.cc
+++ b/sql/temporary_tables.cc
@@ -338,6 +338,13 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
DBUG_RETURN(false);
}
+ if (!tl->db)
+ {
+ DBUG_PRINT("info",
+ ("Table reference to a temporary table must have database set"));
+ DBUG_RETURN(false);
+ }
+
/*
Temporary tables are not safe for parallel replication. They were
designed to be visible to one thread only, so have no table locking.