Commit 519ad0f7 authored by Kristian Nielsen's avatar Kristian Nielsen

MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS

This was a regression from the patch for MDEV-7668.

A test was incorrect, so the slave would not properly handle re-using
temporary tables, which lead to replication failure in this case.
parent 87d54383
......@@ -39,7 +39,12 @@ sum(n)
show status like 'Slave_open_temp_tables';
Variable_name Value
Slave_open_temp_tables 0
*** MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ***
INSERT INTO t2 VALUES (2000), (2001);
CREATE FUNCTION f() RETURNS INTEGER RETURN 1;
CREATE TEMPORARY TABLE t3 AS SELECT f() AS col FROM t2;
drop table if exists t1,t2;
Warnings:
Note 1051 Unknown table 'test.t1'
drop function f;
include/rpl_end.inc
......@@ -57,12 +57,28 @@ select count(*) from t2;
select sum(n) from t2;
show status like 'Slave_open_temp_tables';
--echo *** MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ***
connect (master2,localhost,root,,);
INSERT INTO t2 VALUES (2000), (2001);
CREATE FUNCTION f() RETURNS INTEGER RETURN 1;
CREATE TEMPORARY TABLE t3 AS SELECT f() AS col FROM t2;
--let $gtid=`SELECT @@gtid_binlog_pos`
--disconnect master2
--connection default
# Wait for implicit DROP TEMPORARY TABLE tmp to be binlogged.
--let $wait_condition= SELECT @@gtid_binlog_pos != '$gtid'
--source include/wait_condition.inc
--sync_slave_with_master
#
# Clean up
#
connect (master2,localhost,root,,);
connection master2;
drop table if exists t1,t2;
drop function f;
sync_slave_with_master;
......
......@@ -653,6 +653,7 @@ bool close_cached_connection_tables(THD *thd, LEX_STRING *connection)
static void mark_temp_tables_as_free_for_reuse(THD *thd)
{
rpl_group_info *rgi_slave;
DBUG_ENTER("mark_temp_tables_as_free_for_reuse");
if (thd->query_id == 0)
......@@ -661,7 +662,9 @@ static void mark_temp_tables_as_free_for_reuse(THD *thd)
DBUG_VOID_RETURN;
}
if (thd->temporary_tables)
rgi_slave=thd->rgi_slave;
if ((!rgi_slave && thd->temporary_tables) ||
(rgi_slave && unlikely(rgi_slave->rli->save_temporary_tables)))
{
thd->lock_temporary_tables();
for (TABLE *table= thd->temporary_tables ; table ; table= table->next)
......@@ -670,7 +673,7 @@ static void mark_temp_tables_as_free_for_reuse(THD *thd)
mark_tmp_table_for_reuse(table);
}
thd->unlock_temporary_tables();
if (thd->rgi_slave)
if (rgi_slave)
{
/*
Temporary tables are shared with other by sql execution threads.
......
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