Commit f8f2362b authored by 's avatar

BUG #46572 DROP TEMPORARY table IF EXISTS does not have a consistent behavior in ROW mode

      
In RBR, 'DROP TEMPORARY TABLE IF EXISTS...' statement is binlogged when the table
does not exist.
      
In fact, 'DROP TEMPORARY TABLE ...' statement should never be binlogged in RBR
no matter if the table exists or not. 
This patch addresses this by checking whether we are dropping a
temporary table or not, when building the custom drop statement.
parent 80f96fae
--disable_warnings
drop database if exists `drop-temp+table-test`;
DROP DATABASE IF EXISTS `drop-temp+table-test`;
--enable_warnings
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con1;
reset master;
create database `drop-temp+table-test`;
use `drop-temp+table-test`;
create temporary table shortn1 (a int);
create temporary table `table:name` (a int);
create temporary table shortn2 (a int);
select get_lock("a",10);
RESET MASTER;
CREATE DATABASE `drop-temp+table-test`;
USE `drop-temp+table-test`;
CREATE TEMPORARY TABLE shortn1 (a INT);
CREATE TEMPORARY TABLE `table:name` (a INT);
CREATE TEMPORARY TABLE shortn2 (a INT);
##############################################################################
# BUG#46572 DROP TEMPORARY table IF EXISTS does not have a consistent behavior
# in ROW mode
#
# In RBR, 'DROP TEMPORARY TABLE ...' statement should never be binlogged no
# matter if the tables exist or not. In contrast, both in SBR and MBR, the
# statement should be always binlogged no matter if the tables exist or not.
##############################################################################
CREATE TEMPORARY TABLE tmp(c1 int);
CREATE TEMPORARY TABLE tmp1(c1 int);
CREATE TEMPORARY TABLE tmp2(c1 int);
CREATE TEMPORARY TABLE tmp3(c1 int);
CREATE TABLE t(c1 int);
DROP TEMPORARY TABLE IF EXISTS tmp;
--disable_warnings
# Before fixing BUG#46572, 'DROP TEMPORARY TABLE IF EXISTS...' statement was
# binlogged when the table did not exist in RBR.
DROP TEMPORARY TABLE IF EXISTS tmp;
# In RBR, 'DROP TEMPORARY TABLE ...' statement is never binlogged no matter if
# the tables exist or not.
DROP TEMPORARY TABLE IF EXISTS tmp, tmp1;
DROP TEMPORARY TABLE tmp3;
#In RBR, tmp2 will NOT be binlogged, because it is a temporary table.
DROP TABLE IF EXISTS tmp2, t;
#In RBR, tmp2 will be binlogged, because it does not exist and master do not know
# whether it is a temporary table or not.
DROP TABLE IF EXISTS tmp2, t;
--enable_warnings
SELECT GET_LOCK("a",10);
disconnect con1;
connection con2;
# We want to SHOW BINLOG EVENTS, to know what was logged. But there is no
# guarantee that logging of the terminated con1 has been done yet.
# To be sure that logging has been done, we use a user lock.
select get_lock("a",10);
let $VERSION=`select version()`;
SELECT GET_LOCK("a",10);
let $VERSION=`SELECT VERSION()`;
source include/show_binlog_events.inc;
drop database `drop-temp+table-test`;
DROP DATABASE `drop-temp+table-test`;
# End of 4.1 tests
drop database if exists `drop-temp+table-test`;
reset master;
create database `drop-temp+table-test`;
use `drop-temp+table-test`;
create temporary table shortn1 (a int);
create temporary table `table:name` (a int);
create temporary table shortn2 (a int);
select get_lock("a",10);
get_lock("a",10)
DROP DATABASE IF EXISTS `drop-temp+table-test`;
RESET MASTER;
CREATE DATABASE `drop-temp+table-test`;
USE `drop-temp+table-test`;
CREATE TEMPORARY TABLE shortn1 (a INT);
CREATE TEMPORARY TABLE `table:name` (a INT);
CREATE TEMPORARY TABLE shortn2 (a INT);
CREATE TEMPORARY TABLE tmp(c1 int);
CREATE TEMPORARY TABLE tmp1(c1 int);
CREATE TEMPORARY TABLE tmp2(c1 int);
CREATE TEMPORARY TABLE tmp3(c1 int);
CREATE TABLE t(c1 int);
DROP TEMPORARY TABLE IF EXISTS tmp;
DROP TEMPORARY TABLE IF EXISTS tmp;
DROP TEMPORARY TABLE IF EXISTS tmp, tmp1;
DROP TEMPORARY TABLE tmp3;
DROP TABLE IF EXISTS tmp2, t;
DROP TABLE IF EXISTS tmp2, t;
SELECT GET_LOCK("a",10);
GET_LOCK("a",10)
1
select get_lock("a",10);
get_lock("a",10)
SELECT GET_LOCK("a",10);
GET_LOCK("a",10)
1
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # create database `drop-temp+table-test`
drop database `drop-temp+table-test`;
master-bin.000001 # Query # # CREATE DATABASE `drop-temp+table-test`
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TABLE t(c1 int)
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TABLE IF EXISTS `t` /* generated by server */
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TABLE IF EXISTS tmp2, t
DROP DATABASE `drop-temp+table-test`;
drop database if exists `drop-temp+table-test`;
reset master;
create database `drop-temp+table-test`;
use `drop-temp+table-test`;
create temporary table shortn1 (a int);
create temporary table `table:name` (a int);
create temporary table shortn2 (a int);
select get_lock("a",10);
get_lock("a",10)
DROP DATABASE IF EXISTS `drop-temp+table-test`;
RESET MASTER;
CREATE DATABASE `drop-temp+table-test`;
USE `drop-temp+table-test`;
CREATE TEMPORARY TABLE shortn1 (a INT);
CREATE TEMPORARY TABLE `table:name` (a INT);
CREATE TEMPORARY TABLE shortn2 (a INT);
CREATE TEMPORARY TABLE tmp(c1 int);
CREATE TEMPORARY TABLE tmp1(c1 int);
CREATE TEMPORARY TABLE tmp2(c1 int);
CREATE TEMPORARY TABLE tmp3(c1 int);
CREATE TABLE t(c1 int);
DROP TEMPORARY TABLE IF EXISTS tmp;
DROP TEMPORARY TABLE IF EXISTS tmp;
DROP TEMPORARY TABLE IF EXISTS tmp, tmp1;
DROP TEMPORARY TABLE tmp3;
DROP TABLE IF EXISTS tmp2, t;
DROP TABLE IF EXISTS tmp2, t;
SELECT GET_LOCK("a",10);
GET_LOCK("a",10)
1
select get_lock("a",10);
get_lock("a",10)
SELECT GET_LOCK("a",10);
GET_LOCK("a",10)
1
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # create database `drop-temp+table-test`
master-bin.000001 # Query # # use `drop-temp+table-test`; create temporary table shortn1 (a int)
master-bin.000001 # Query # # use `drop-temp+table-test`; create temporary table `table:name` (a int)
master-bin.000001 # Query # # use `drop-temp+table-test`; create temporary table shortn2 (a int)
master-bin.000001 # Query # # CREATE DATABASE `drop-temp+table-test`
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TEMPORARY TABLE shortn1 (a INT)
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TEMPORARY TABLE `table:name` (a INT)
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TEMPORARY TABLE shortn2 (a INT)
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TEMPORARY TABLE tmp(c1 int)
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TEMPORARY TABLE tmp1(c1 int)
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TEMPORARY TABLE tmp2(c1 int)
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TEMPORARY TABLE tmp3(c1 int)
master-bin.000001 # Query # # use `drop-temp+table-test`; CREATE TABLE t(c1 int)
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TEMPORARY TABLE IF EXISTS tmp
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TEMPORARY TABLE IF EXISTS tmp
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TEMPORARY TABLE IF EXISTS tmp, tmp1
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TEMPORARY TABLE tmp3
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TABLE IF EXISTS tmp2, t
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP TABLE IF EXISTS tmp2, t
master-bin.000001 # Query # # use `drop-temp+table-test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `shortn2`,`table:name`,`shortn1`
drop database `drop-temp+table-test`;
DROP DATABASE `drop-temp+table-test`;
......@@ -1949,7 +1949,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
being built. The string always end in a comma and the comma
will be chopped off before being written to the binary log.
*/
if (thd->current_stmt_binlog_row_based && !dont_log_query)
if (!drop_temporary && thd->current_stmt_binlog_row_based && !dont_log_query)
{
non_temp_tables_count++;
/*
......
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