Commit 9827c5e1 authored by Sachin's avatar Sachin Committed by sachin

MDEV-16192 Table 't' is specified twice, both as a target for 'CREATE' and...

as a separate source for data

Actually MDEV-15867 and MDEV-16192 are same, Slave adds "or replace" to create
table stmt. So create table t1 is create or replace on slave. So this bug
is not because of replication, We can get this bug on general server if we
manually add or replace to create query.

Problem:- So if we try to create table t1 (same name as of temp table t1 ) via
   CREATE or replace TABLE t AS SELECT * FROM t;
Since in this query we are creating table from select * from t1 , we call
unique_table function to see whether if source and destination table are same.
But there is one issue unique_table does not account if source table is tmp table
in this case source and destination table can be same.

Solution:- We will change find_dup_table to not to look for temp table if
CHECK_DUP_SKIP_TEMP_TABLE flag is on.
parent 1cc1d042
CREATE TEMPORARY TABLE t (i INT);
CREATE or replace TABLE t AS SELECT * FROM t;
DROP TEMPORARY TABLE t;
DROP TABLE t;
include/master-slave.inc
[connection master]
CREATE TEMPORARY TABLE t (i INT);
CREATE TABLE t AS SELECT * FROM t;
connection slave;
connection master;
DROP TEMPORARY TABLE t;
DROP TABLE t;
include/rpl_end.inc
--source include/master-slave.inc
CREATE TEMPORARY TABLE t (i INT);
CREATE TABLE t AS SELECT * FROM t;
--sync_slave_with_master
# Cleanup
--connection master
DROP TEMPORARY TABLE t;
DROP TABLE t;
--source include/rpl_end.inc
CREATE TEMPORARY TABLE t (i INT);
CREATE or replace TABLE t AS SELECT * FROM t;
DROP TEMPORARY TABLE t;
DROP TABLE t;
......@@ -1031,6 +1031,12 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
if (res->table && (res->table == table->table))
continue;
/* Skip if table is tmp table */
if (check_flag & CHECK_DUP_SKIP_TEMP_TABLE &&
res->table && res->table->s->tmp_table != NO_TMP_TABLE)
{
continue;
}
if (check_flag & CHECK_DUP_FOR_CREATE)
DBUG_RETURN(res);
......
......@@ -64,6 +64,7 @@ enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
/* Flag bits for unique_table() */
#define CHECK_DUP_ALLOW_DIFFERENT_ALIAS 1
#define CHECK_DUP_FOR_CREATE 2
#define CHECK_DUP_SKIP_TEMP_TABLE 4
uint get_table_def_key(const TABLE_LIST *table_list, const char **key);
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
......
......@@ -3910,8 +3910,8 @@ mysql_execute_command(THD *thd)
{
TABLE_LIST *duplicate;
if ((duplicate= unique_table(thd, lex->query_tables,
lex->query_tables->next_global,
CHECK_DUP_FOR_CREATE)))
lex->query_tables->next_global,
CHECK_DUP_FOR_CREATE | CHECK_DUP_SKIP_TEMP_TABLE)))
{
update_non_unique_table_error(lex->query_tables, "CREATE",
duplicate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment