Description:
ddl_log.log file size should not increase when ddl execute serialized.
bug the ddl_log.log file size incorrectly increased when exchange partition.
How to repeat:
testcase:
------------------------------------------------------
--let $DATADIR= `SELECT @@datadir;`
CREATE TABLE `t1` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`pt` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
PRIMARY KEY (`id`,`pt`)
) ENGINE=InnoDB
PARTITION BY RANGE (to_days(pt))
(PARTITION p1 VALUES LESS THAN (738105) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (738106) ENGINE = InnoDB,
PARTITION p3 VALUES LESS THAN (738107) ENGINE = InnoDB);
CREATE TABLE `t1_tmp` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`pt` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
PRIMARY KEY (`id`,`pt`)
) ENGINE=InnoDB;
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp;
let FILE_TO_CHECK=$DATADIR/ddl_log.log;
echo the file size should be keep as 12288
--source include/show_file_size.inc
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp;
let FILE_TO_CHECK=$DATADIR/ddl_log.log;
--echo the file size should be keep as 12288
--source include/show_file_size.inc
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp;
let FILE_TO_CHECK=$DATADIR/ddl_log.log;
--echo the file size should be keep as 12288
--source include/show_file_size.inc
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp;
let FILE_TO_CHECK=$DATADIR/ddl_log.log;
--echo the file size should be keep as 12288
--source include/show_file_size.inc
drop table t1;
drop table t1_tmp;
result:
------------------------------------------------
CREATE TABLE `t1` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`pt` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
PRIMARY KEY (`id`,`pt`)
) ENGINE=InnoDB
PARTITION BY RANGE (to_days(pt))
(PARTITION p1 VALUES LESS THAN (738105) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (738106) ENGINE = InnoDB,
PARTITION p3 VALUES LESS THAN (738107) ENGINE = InnoDB);
CREATE TABLE `t1_tmp` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`pt` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
PRIMARY KEY (`id`,`pt`)
) ENGINE=InnoDB;
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp;
the file size should be keep as 12288
--source include/show_file_size.inc
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp
the file size should be keep as 12288
The size of file '/home/ayuanzhang/mysql-server/mysql-test/var/mysqld.1/data//ddl_log.log' is 12288 bytes.
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp;
the file size should be keep as 12288
The size of file '/home/ayuanzhang/mysql-server/mysql-test/var/mysqld.1/data//ddl_log.log' is 20480 bytes.
ALTER TABLE t1 exchange PARTITION p1 with table t1_tmp;
the file size should be keep as 12288
The size of file '/home/ayuanzhang/mysql-server/mysql-test/var/mysqld.1/data//ddl_log.log' is 28672 bytes.
drop table t1;
drop table t1_tmp;
Suggested fix:
diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc
index ff3a276daea..79d9ffc83de 100644
--- a/sql/sql_partition_admin.cc
+++ b/sql/sql_partition_admin.cc
@@ -421,6 +421,10 @@ static bool exchange_name_with_ddl_log(THD *thd,
DBUG_EXECUTE_IF("exchange_partition_abort_9", DBUG_SUICIDE(););
/* all OK */
error= FALSE;
+ mysql_mutex_lock(&LOCK_gdl);
+ release_ddl_log_memory_entry(exec_log_entry);
+ release_ddl_log_memory_entry(log_entry);
+ mysql_mutex_unlock(&LOCK_gdl);
delete file;
DBUG_RETURN(error);
err_rename: