All Products
Search
Document Center

PolarDB:Faster TRUNCATE/DROP TABLE

Last Updated:Sep 03, 2025

PolarDB addresses the slow performance of Data Definition Language (DDL) operations, such as TRUNCATE TABLE and DROP TABLE, in community edition MySQL by optimizing the data page cleanup mechanism in the buffer pool. This optimization avoids the performance bottleneck caused by full scans. On clusters with large memory or under high loads, this feature significantly reduces the running time of DDL operations and improves system performance and stability.

Limits

Your PolarDB for MySQL cluster must meet one of the following requirements:

  • MySQL 5.7, revision version 5.7.1.0.19 or later.

  • MySQL 8.0.1, revision version 8.0.1.1.50 or later.

  • MySQL 8.0.2, revision version 8.0.2.2.30.1 or later.

Note

To check the revision version of your cluster, see the Version Guide for PolarDB for MySQL.

Usage

You can enable the faster TRUNCATE/DROP TABLE feature by setting the loose_innodb_flush_pages_using_space_id parameter. For more information, see Set cluster parameters and node parameters. The following table describes the parameter.

Parameter

Level

Description

loose_innodb_flush_pages_using_space_id

Global

The switch for the faster TRUNCATE/DROP TABLE feature. Valid values:

  • ON: Enables the faster TRUNCATE/DROP TABLE feature.

  • OFF: Disables the faster TRUNCATE/DROP TABLE feature.

Performance testing

This test uses MySQL 5.7 to compare the performance of the TRUNCATE TABLE operation on clusters with different specifications, with the faster TRUNCATE/DROP TABLE feature enabled and disabled.

Test method

  1. Run the following commands to fill the buffer pools on clusters with different specifications. This step ensures that the buffer pool status does not affect the performance of the TRUNCATE TABLE operation.

    ip=<cluster_endpoint>
    user=<database_account>
    psw=<database_password>
    port=<database_port>
    MYSQL="mysql -h $ip -P $port -u$user -p$psw -vvv -e"
    $MYSQL "create database test;"
    $MYSQL "use test;create table if not exists t3 (a bigint,b char(250),c char(250),d char(250),e char(250)) charset=latin1;"
    $MYSQL "use test;insert into t3 values(1,repeat('x', 255),repeat('x', 255),repeat('x', 255),repeat('x', 255));"
    for ((i=1; i<=32; i+=1))
    do
       $MYSQL --host=$ip -p$psw --port=$port -u$user  -vvv -e "use test;insert into t3 select * from t3;"
    done
    $MYSQL  "use test; select count(*) from t3;"
  2. Create two tables, t1 and t2. Insert 8,192 rows of data into t1 and 2,097,152 rows of data into t2.

    # Create the t1 table and insert 8,192 rows of data.
    row_num=13
    ip=<cluster_endpoint>
    user=<database_account>
    psw=<database_password>
    port=<database_port>
    MYSQL="mysql -h $ip -P $port -u$user -p$psw -vvv -e"
    $MYSQL "use test;create table if not exists t1 (a bigint,b char(250),c char(250),d char(250),e char(250)) charset=latin1;"
    $MYSQL "use test;insert into t1 values(1,repeat('x', 255),repeat('x', 255),repeat('x', 255),repeat('x', 255));"
    for ((i=1; i<=$row_num; i+=1))
    do
       $MYSQL "use test;insert into t1 select * from t1;"
    done
    # Create the t2 table and insert 2,097,152 rows of data.
    row_num=21
    ip=<cluster_endpoint>
    user=<database_account>
    psw=<database_password>
    port=<database_port>
    MYSQL="mysql -h $ip -P $port -u$user -p$psw -vvv -e"
    $MYSQL "use test;create table if not exists t2 (a bigint,b char(250),c char(250),d char(250),e char(250)) charset=latin1;"
    $MYSQL "use test;insert into t2 values(1,repeat('x', 255),repeat('x', 255),repeat('x', 255),repeat('x', 255));"
    for ((i=1; i<=$row_num; i+=1))
    do
       $MYSQL "use test;insert into t2 select * from t2;"
    done
  3. On clusters with different specifications, run the TRUNCATE TABLE operation on tables t1 and t2 with the faster TRUNCATE/DROP TABLE feature enabled and disabled.

Test results

The running time of the TRUNCATE TABLE operation on tables t1 and t2 was recorded on clusters with different specifications, with the faster TRUNCATE/DROP TABLE feature enabled and disabled. The results are shown in the following table:

Cluster specifications

Buffer pool (GB)

t1

t2

ON (seconds)

OFF (seconds)

Improvement rate

ON (seconds)

OFF (seconds)

Improvement rate

64 cores, 512 GB

374

0.01

5.2

99.81%

0.11

9.48

98.84%

32 cores, 256 GB

192

0.02

2.45

99.18%

0.1

2.65

96.23%

16 cores, 128 GB

96

0.01

1.73

99.42%

0.12

1.86

93.55%

8 cores, 64 GB

42

0.01

0.73

98.63%

0.12

0.79

84.81%

4 cores, 32 GB

24

0.02

0.45

95.56%

0.13

0.53

75.47%

4 cores, 16 GB

12

0.03

0.23

86.96%

0.12

0.35

65.71%

The table shows that enabling the faster TRUNCATE/DROP TABLE feature significantly improves the performance of the TRUNCATE TABLE operation.

Contact us

If you have any questions about DDL operations, contact us.