commit db5f31f070c8b7db69176f731f1e4edd4834eb24
Date: Wed May 16 16:28:28 2018 +0530
MDEV-15867 Slave SQL: Error 'Table 't' is specified twice...
(ER_UPDATE_TABLE_USED) upon CREATE TABLE .. SELECT
Commit message Pending.. , Will be added after review
diff --git a/mysql-test/suite/rpl/r/rpl_mdev_15867.result b/mysql-test/suite/rpl/r/rpl_mdev_15867.result
new file mode 100644
index 00000000000..011193f4b83
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_mdev_15867.result
@@ -0,0 +1,13 @@
+include/master-slave.inc
+[connection master]
+CREATE TEMPORARY TABLE t (i INT);
+#This will be executed as CREATE OR REPLACE on slave
+CREATE TABLE t AS SELECT * FROM t;
+connection slave;
+connection master;
+#Slave also have 2 table t , t (temp)
+DROP TABLE t;
+DROP TABLE t;
+DROP TABLE t;
+ERROR 42S02: Unknown table 'test.t'
+include/rpl_end.inc
diff --git a/mysql-test/suite/rpl/t/rpl_mdev_15867.test b/mysql-test/suite/rpl/t/rpl_mdev_15867.test
new file mode 100644
index 00000000000..0cb2155bcc2
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_mdev_15867.test
@@ -0,0 +1,15 @@
+--source include/master-slave.inc
+CREATE TEMPORARY TABLE t (i INT);
+--echo #This will be executed as CREATE OR REPLACE on slave
+CREATE TABLE t AS SELECT * FROM t;
+
+--sync_slave_with_master
+
+# Cleanup
+--connection master
+--echo #Slave also have 2 table t , t (temp)
+DROP TABLE t;
+DROP TABLE t;
+--error ER_BAD_TABLE_ERROR
+DROP TABLE t;
+--source include/rpl_end.inc
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 52aa6bf9381..d550aad09c9 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3913,7 +3913,8 @@ mysql_execute_command(THD *thd)
TABLE_LIST *duplicate;
if ((duplicate= unique_table(thd, lex->query_tables,
lex->query_tables->next_global,
- 0)))
+ 0)) && duplicate->table->s->tmp_table
+ == NO_TMP_TABLE)
{
update_non_unique_table_error(lex->query_tables, "CREATE",
duplicate);