Mysql – When dropping a partition on InnoDB table does thesql flush pages in the whole table or only in a partition to be dropped


When issuing ALTER TABLE .. DROP PARTITION p1 mysql have to flush pages to disk. My question is: does mysql flush pages in the whole table (in each partition) or only in a partition to be dropped? MySQL server 5.7

table partition exp. is: PARTITION BY RANGE (UNIX_TIMESTAMP(dt))

Best Answer

According to the MySQL 5.7 Documentation under the subheading Affected DDL statements, here is what says about Locking for DDL on Partitioned Tables:

CREATE VIEW does not cause any locks.

ALTER TABLE ... EXCHANGE PARTITION prunes locks; only the exchanged table and the exchanged partition are locked.

ALTER TABLE ... TRUNCATE PARTITION prunes locks; only the partitions to be emptied are locked.

In addition, ALTER TABLE statements take metadata locks on the table level.

As far as I can see in that page, it locks the table's metadata. There is nothing here suggesting that all the .ibd files of the other partitions need to be flushed. It would affect only those files involved.

In your case, it would involve the following steps:

  • Acquire metadata lock on the .par file of the partitioned table
  • Update list of partitions in the .par file
  • Remove locks of .ibd you are going to drop
  • Unlock the .par file

NOTE : Dropping a partition is DDL not DML.


Only partition to be dropped