Skip to content
Permalink
Browse files
Clean up replication check in open_temporary_table()
  • Loading branch information
montywi committed Jun 30, 2017
1 parent e16425b commit 9f484b6
Showing 1 changed file with 16 additions and 30 deletions.
@@ -320,16 +320,6 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
TMP_TABLE_SHARE *share;
TABLE *table= NULL;

/*
Since temporary tables are not safe for parallel replication, lets
wait for the prior commits in case the table is found to be in use.
*/
if (rgi_slave &&
rgi_slave->is_parallel_exec &&
find_temporary_table(tl) &&
wait_for_prior_commit())
DBUG_RETURN(true);

/*
Code in open_table() assumes that TABLE_LIST::table can be non-zero only
for pre-opened temporary tables.
@@ -350,6 +340,22 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
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.
Thus there is no protection against two conflicting transactions
committing in parallel and things like that.
So for now, anything that uses temporary tables will be serialised
with anything before it, when using parallel replication.
*/

if (rgi_slave &&
rgi_slave->is_parallel_exec &&
find_temporary_table(tl) &&
wait_for_prior_commit())
DBUG_RETURN(true);

/*
First check if there is a reusable open table available in the
open table list.
@@ -378,26 +384,6 @@ bool THD::open_temporary_table(TABLE_LIST *tl)
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.
Thus there is no protection against two conflicting transactions
committing in parallel and things like that.
So for now, anything that uses temporary tables will be serialised
with anything before it, when using parallel replication.
TODO: We might be able to introduce a reference count or something
on temp tables, and have slave worker threads wait for it to reach
zero before being allowed to use the temp table. Might not be worth
it though, as statement-based replication using temporary tables is
in any case rather fragile.
*/
if (rgi_slave &&
rgi_slave->is_parallel_exec &&
wait_for_prior_commit())
DBUG_RETURN(true);

#ifdef WITH_PARTITION_STORAGE_ENGINE
if (tl->partition_names)
{

0 comments on commit 9f484b6

Please sign in to comment.