Bug #101787 ddl_log.log file size increased when exchange partition
Submitted: 28 Nov 2020 6:04 Modified: 30 Nov 2020 6:45
Reporter: simon zhang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S2 (Serious)
Version:5.7, 5.7.32 OS:Any
Assigned to: CPU Architecture:Any

[28 Nov 2020 6:04] simon zhang
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:
[28 Nov 2020 6:05] simon zhang
change affect version to 5.7
[30 Nov 2020 6:45] MySQL Verification Team
Hello simon zhang,

Thank you for the report and feedback.

regards,
Umesh
[30 Nov 2020 7:20] zhang simon
ddl log patch

Attachment: ddl_log.patch (application/octet-stream, text), 554 bytes.

[30 Nov 2020 7:20] zhang simon
ddl log patch

Attachment: ddl_log.patch (application/octet-stream, text), 554 bytes.

[30 Nov 2020 7:29] MySQL Verification Team
Please note that in order to submit contributions you must first sign the Oracle Contribution Agreement (OCA). More details are described in "Contributions" tab, Please ensure to re-send the patch via that tab. Otherwise we would not be able to accept it.