Commit 6e7dd94e authored by unknown's avatar unknown

BUG#6883: Added implicit commit for CREATE TABLE, TRUNCATE TABLE and DROP/CREATE DATABASE


mysql-test/r/innodb.result:
  Truncate table now work even if there is open trx
mysql-test/r/innodb_cache.result:
  One query in cache
mysql-test/t/innodb.test:
  Truncate table now succeed even if there is an open transaction
sql/sql_parse.cc:
  Added implicit commit for temp table CREATE TABLE, TRUNCATE TABLE, CREATE/DROP DATABASE.
parent 605f7061
# include/rpl_stmt_seq.inc
#
# Please be very careful when editing this routine, because the handling of
# the $variables is extreme sensitive.
#
######## The typical test sequence
# 1. INSERT without commit
# check table content of master and slave
# 2. EXECUTE the statement
# check table content of master and slave
# 3. ROLLBACK
# check table content of master and slave
# 4. flush the logs
let $VERSION=`select version()`;
--disable_query_log
# SELECT '######## new test sequence ########' as "";
eval SELECT CONCAT('######## ','$my_stmt',' ########') as "";
--enable_query_log
### Predict the number of the current log
# Disable the logging of the log number computation.
--disable_query_log
# $_log_num_n should contain the number of the current binlog in numeric style.
# If this routine is called for the first time, $_log_num will not initialized
# and contain the value '' instead of '1'. So we will correct it here.
#
eval set @aux= IF('$_log_num_n' = '', '1', '$_log_num_n');
let $_log_num_n= `SELECT @aux`;
eval set @aux= LPAD('$_log_num_n',6,'0');
# SELECT @aux AS "@aux is";
#
# $_log_num_s should contain the number of the current binlog in string style.
let $_log_num_s= `select @aux`;
# eval SELECT '$log_num' ;
--enable_query_log
# INSERT + command to be tested + ROLLBACK
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
# Maybe it would be smarter to use a table with autoincrement column.
let $MAX= `SELECT MAX(f1) FROM t1` ;
eval INSERT INTO t1 SET f1= $MAX + 1;
# results before DDL(to be tested)
SELECT MAX(f1) FROM t1;
--replace_result $VERSION VERSION
eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
sync_slave_with_master;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
# results before DDL(to be tested)
SELECT MAX(f1) FROM t1;
--replace_result $VERSION VERSION
eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
eval $my_stmt;
# Devaluate $my_stmt, to detect script bugs
let $my_stmt= ERROR: YOU FORGOT TO FILL IN THE STATEMENT;
# results after DDL(to be tested)
SELECT MAX(f1) FROM t1;
--replace_result $VERSION VERSION
eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
sync_slave_with_master;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
# results after DDL(to be tested)
SELECT MAX(f1) FROM t1;
--replace_result $VERSION VERSION
eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
ROLLBACK;
# results after final ROLLBACK
SELECT MAX(f1) FROM t1;
# Try to detect if the DDL command caused that the INSERT is committed
# $MAX holds the highest/last value just before the insert of MAX + 1
--disable_query_log
eval SELECT CONCAT('TEST-INFO: MASTER: The INSERT is ',
IF(MAX(f1) = $MAX + 1, 'committed', 'not committed')) AS ""
FROM d1.t1;
--enable_query_log
--replace_result $VERSION VERSION
eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
sync_slave_with_master;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
# results after final ROLLBACK
SELECT MAX(f1) FROM t1;
--disable_query_log
eval SELECT CONCAT('TEST-INFO: SLAVE: The INSERT is ',
IF(MAX(f1) = $MAX + 1, 'committed', 'not committed')) AS ""
FROM d1.t1;
--enable_query_log
--replace_result $VERSION VERSION
eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
#let $manipulate= 0;
let $manipulate= 1;
while ($manipulate)
{
#### Manipulate the binary logs,
# so that the output of SHOW BINLOG EVENTS IN <current log>
# contains only commands of the current test sequence.
# - flush the master and the slave log
# ---> both start to write into new logs with incremented number
# - increment $_log_num_n
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
flush logs;
# sleep 1;
# eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
sync_slave_with_master;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
# the final content of the binary log
flush logs;
# The next sleep is urgent needed.
# Without this sleep the slaves crashes often, when the SHOW BINLOG
# is executed. :-(
# sleep 1;
# eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
inc $_log_num_n;
let $manipulate= 0;
}
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
......@@ -875,7 +875,6 @@ set autocommit=0;
create table t1 (a int not null) engine= innodb;
insert into t1 values(1),(2);
truncate table t1;
ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
commit;
truncate table t1;
truncate table t1;
......@@ -1598,14 +1597,14 @@ t2 CREATE TABLE `t2` (
drop table t2, t1;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 24
Binlog_cache_use 25
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
create table t1 (a int) engine=innodb;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 25
Binlog_cache_use 26
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
......@@ -1614,7 +1613,7 @@ delete from t1;
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 26
Binlog_cache_use 27
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
......
......@@ -24,7 +24,7 @@ a
3
show status like "Qcache_queries_in_cache";
Variable_name Value
Qcache_queries_in_cache 0
Qcache_queries_in_cache 1
drop table t1;
commit;
create table t1 (a int not null) engine=innodb;
......
This diff is collapsed.
......@@ -570,7 +570,6 @@ show tables from mysqltest;
set autocommit=0;
create table t1 (a int not null) engine= innodb;
insert into t1 values(1),(2);
--error 1192
truncate table t1;
commit;
truncate table t1;
......
######################## rpl-ddl.test ########################
# #
# DDL statements (sometimes with implicit COMMIT) executed #
# by the master and it's propagation into the slave #
# #
##############################################################
#
# NOTE, PLEASE BE CAREFUL, WHEN MODIFYING THE TESTS !!
#
# 1. !All! objects to be dropped, renamed, altered ... must be created
# in AUTOCOMMIT= 1 mode before AUTOCOMMIT is set to 0 and the test
# sequences start.
#
# 2. Never use a test object, which was direct or indirect affected by a
# preceeding test sequence again.
# Except table d1.t1 where ONLY DML is allowed.
#
# If one preceeding test sequence hits a (sometimes not good visible,
# because the sql error code of the statement might be 0) bug
# and these rules are ignored, a following test sequence might earn ugly
# effects like failing 'sync_slave_with_master', crashes of the slave or
# abort of the test case etc..
#
# 3. The assignment of the DDL command to be tested to $my_stmt can
# be a bit difficult. "'" must be avoided, because the test
# routine "include/rpl_stmt_seq.inc" performs a
# eval SELECT CONCAT('######## ','$my_stmt',' ########') as "";
#
######## tested DDL commands
#
# let $my_stmt= COMMIT;
# let $my_stmt= ROLLBACK;
# let $my_stmt= SET AUTOCOMMIT=1;
# let $my_stmt= START TRANSACTION;
# let $my_stmt= BEGIN;
# let $my_stmt= DROP TABLE d1.t2;
# let $my_stmt= RENAME TABLE d1.t3 to d1.t20; <- wrong syntax !!
# let $my_stmt= ALTER TABLE d1.t4 ADD column f2 BIGINT;
# let $my_stmt= CREATE TABLE d1.t21 (f1 BIGINT) ENGINE= "InnoDB";
# let $my_stmt= TRUNCATE TABLE d1.t7;
# let $my_stmt= LOCK TABLES d1.t1 WRITE, d1.t8 READ;
# let $my_stmt= UNLOCK TABLES;
# let $my_stmt= DROP INDEX my_idx6 ON d1.t6;
# let $my_stmt= CREATE INDEX my_idx5 ON d1.t5(f1);
# let $my_stmt= DROP DATABASE d2;
# let $my_stmt= CREATE DATABASE d3;
#
# FIXME: @code{LOAD MASTER DATA} is not tested
#
#############################################
--source include/have_innodb.inc
source include/master-slave.inc;
######## some preparations
#
SET AUTOCOMMIT = 1;
#
# 1. DROP all objects, which probably already exist, but must be created here
#
--disable_warnings
DROP DATABASE IF EXISTS d1;
DROP DATABASE IF EXISTS d2;
DROP DATABASE IF EXISTS d3;
--enable_warnings
#
# 2. CREATE all objects needed
# working database is d1
# working (transactional!) is d1.t1
#
CREATE DATABASE d1;
CREATE DATABASE d2;
CREATE TABLE d1.t1 (f1 BIGINT) ENGINE= "InnoDB";
INSERT INTO d1.t1 SET f1= 0;
CREATE TABLE d1.t2 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t3 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t4 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t5 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t6 (f1 BIGINT) ENGINE= "InnoDB";
CREATE INDEX my_idx6 ON d1.t6(f1);
CREATE TABLE d1.t7 (f1 BIGINT) ENGINE= "InnoDB";
INSERT INTO d1.t7 SET f1= 0;
CREATE TABLE d1.t8 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t9 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t10 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t11 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t12 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t13 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t14 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t15 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t16 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t17 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t18 (f1 BIGINT) ENGINE= "InnoDB";
CREATE TABLE d1.t19 (f1 BIGINT) ENGINE= "InnoDB";
#
COMMIT; # Just to be sure
#
# 3. master sessions: never do AUTOCOMMIT
# slave sessions: do AUTOCOMMIT, because we want to see fresh values
# every time
# default database is d1
SET AUTOCOMMIT = 0;
use d1;
sync_slave_with_master;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SET AUTOCOMMIT = 1;
use d1;
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
# We don't want to abort the whole test if one statement sent
# to the server gets an error, because the following test
# sequences are nearly independend of the previous statements.
--disable_abort_on_error
###### banal case: (explicit) COMMIT and ROLLBACK
# just for checking if the test sequence is usable
let $my_stmt= COMMIT;
--source include/rpl_stmt_seq.inc
let $my_stmt= ROLLBACK;
--source include/rpl_stmt_seq.inc
###### cases with commands very similar to COMMIT
let $my_stmt= SET AUTOCOMMIT=1;
--source include/rpl_stmt_seq.inc
SET AUTOCOMMIT=0;
#
let $my_stmt= START TRANSACTION;
--source include/rpl_stmt_seq.inc
#
let $my_stmt= BEGIN;
--source include/rpl_stmt_seq.inc
###### cases with commands, which create or drop objects
#### (BASE) TABLES and (UPDATABLE) VIEWs
let $my_stmt= DROP TABLE d1.t2;
--source include/rpl_stmt_seq.inc
SHOW TABLES LIKE 't2';
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SHOW TABLES LIKE 't2';
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
#
let $my_stmt= RENAME TABLE d1.t3 to d1.t20;
--source include/rpl_stmt_seq.inc
SHOW TABLES LIKE 't20';
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SHOW TABLES LIKE 't20';
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
#
let $my_stmt= ALTER TABLE d1.t4 ADD column f2 BIGINT;
--source include/rpl_stmt_seq.inc
describe d1.t4;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
describe d1.t4;
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
#
let $my_stmt= CREATE TABLE d1.t21 (f1 BIGINT) ENGINE= "InnoDB";
--source include/rpl_stmt_seq.inc
#
let $my_stmt= TRUNCATE TABLE d1.t7;
--source include/rpl_stmt_seq.inc
SELECT * FROM d1.t7;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SELECT * FROM d1.t7;
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
#
# MySQL insists in locking d1.t1, because rpl_stmt_seq performs an INSERT into
# this table.
let $my_stmt= LOCK TABLES d1.t1 WRITE, d1.t8 READ;
--source include/rpl_stmt_seq.inc
UNLOCK TABLES;
#
LOCK TABLES d1.t1 WRITE, d1.t8 READ;
let $my_stmt= UNLOCK TABLES;
--source include/rpl_stmt_seq.inc
#
#### INDEXES
let $my_stmt= DROP INDEX my_idx6 ON d1.t6;
--source include/rpl_stmt_seq.inc
SHOW INDEX FROM d1.t6;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SHOW INDEX FROM d1.t6;
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
#
let $my_stmt= CREATE INDEX my_idx5 ON d1.t5(f1);
--source include/rpl_stmt_seq.inc
SHOW INDEX FROM d1.t5;
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SHOW INDEX FROM d1.t5;
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
#### DATABASES
let $my_stmt= DROP DATABASE d2;
--source include/rpl_stmt_seq.inc
SHOW DATABASES LIKE "d2";
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SHOW DATABASES LIKE "d2";
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
#
let $my_stmt= CREATE DATABASE d3;
--source include/rpl_stmt_seq.inc
SHOW DATABASES LIKE "d3";
connection slave;
--disable_query_log
SELECT '-------- switch to slave --------' as "";
--enable_query_log
SHOW DATABASES LIKE "d3";
connection master;
--disable_query_log
SELECT '-------- switch to master -------' as "";
--enable_query_log
--disable_warnings
DROP DATABASE IF EXISTS d1;
DROP DATABASE IF EXISTS d2;
DROP DATABASE IF EXISTS d3;
--enable_warnings
......@@ -2409,6 +2409,11 @@ mysql_execute_command(THD *thd)
case SQLCOM_CREATE_TABLE:
{
/* If CREATE TABLE of non-temporary table, do implicit commit */
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) &&
end_active_trans(thd))
res= -1;
/* Skip first table, which is the table we are creating */
TABLE_LIST *create_table, *create_table_local;
tables= lex->unlink_first_table(tables, &create_table,
......@@ -2855,6 +2860,11 @@ unsent_create_error:
break;
}
case SQLCOM_TRUNCATE:
if (end_active_trans(thd))
{
res= -1;
break;
}
if (check_one_table_access(thd, DELETE_ACL, tables))
goto error;
/*
......@@ -3213,6 +3223,11 @@ purposes internal to the MySQL server", MYF(0));
break;
case SQLCOM_CREATE_DB:
{
if (end_active_trans(thd))
{
res= -1;
break;
}
char *alias;
if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name))
{
......@@ -3243,6 +3258,11 @@ purposes internal to the MySQL server", MYF(0));
}
case SQLCOM_DROP_DB:
{
if (end_active_trans(thd))
{
res= -1;
break;
}
char *alias;
if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name))
{
......
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