GreatSQL删除分区慢的跟踪背景某业务零碎,每天凌晨会删除分区表的一个分区(按天分区),耗时较久,从最开始的30秒,缓缓变为1分钟+,影响到交易业务的失常进行。 在测试环境进行了模仿,复现了删除分区慢的状况,本次基于GreatSQL8.0.25-17进行测试,官网mysql版本也存在雷同问题。
测试环境$ mysql -h127.0.0.1 -P8025 -uroot -pmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 10Server version: 8.0.25-17 GreatSQL, Release 17, Revision 4733775f703Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.greatsql> select version();+-----------+| version() |+-----------+| 8.0.25-17 |+-----------+1 row in set (0.00 sec)greatsql> show variables like 'autocommit' ;+---------------+-------+| Variable_name | Value |+---------------+-------+| autocommit | ON |+---------------+-------+1 row in set (0.01 sec)greatsql> show variables like 'innodb_buffer_pool_size';+-------------------------+------------+| Variable_name | Value |+-------------------------+------------+| innodb_buffer_pool_size | 4294967296 |+-------------------------+------------+1 row in set (0.01 sec)greatsql> show variables like 'innodb_flush_log_at_trx_commit';+--------------------------------+-------+| Variable_name | Value |+--------------------------------+-------+| innodb_flush_log_at_trx_commit | 1 |+--------------------------------+-------+1 row in set (0.00 sec)greatsql> show variables like 'sync_binlog';+---------------+-------+| Variable_name | Value |+---------------+-------+| sync_binlog | 1 |+---------------+-------+1 row in set (0.00 sec)建表CREATE TABLE `t_partition` ( `id` bigint NOT NULL AUTO_INCREMENT, `ua` varchar(100) DEFAULT NULL, `start_time` datetime NOT NULL, PRIMARY KEY (`id`,`start_time`)) PARTITION BY RANGE (to_days(`start_time`))(PARTITION P20230129 VALUES LESS THAN (738915) ENGINE = InnoDB, PARTITION P20230130 VALUES LESS THAN (738916) ENGINE = InnoDB, PARTITION P20230131 VALUES LESS THAN (738917) ENGINE = InnoDB, PARTITION P20230201 VALUES LESS THAN (738918) ENGINE = InnoDB, PARTITION P20230202 VALUES LESS THAN (738919) ENGINE = InnoDB, PARTITION P20230203 VALUES LESS THAN (738920) ENGINE = InnoDB, PARTITION P20230204 VALUES LESS THAN (738921) ENGINE = InnoDB, PARTITION P20230302 VALUES LESS THAN (738947) ENGINE = InnoDB, PARTITION P20230303 VALUES LESS THAN (738948) ENGINE = InnoDB, PARTITION P20230304 VALUES LESS THAN (738949) ENGINE = InnoDB, PARTITION P20230305 VALUES LESS THAN (738950) ENGINE = InnoDB, PARTITION P20230306 VALUES LESS THAN (738951) ENGINE = InnoDB, PARTITION P20230307 VALUES LESS THAN (738952) ENGINE = InnoDB, PARTITION P20230308 VALUES LESS THAN (738953) ENGINE = InnoDB, PARTITION P20230309 VALUES LESS THAN (738954) ENGINE = InnoDB, PARTITION P20230310 VALUES LESS THAN (738955) ENGINE = InnoDB, PARTITION P20230311 VALUES LESS THAN (738956) ENGINE = InnoDB, PARTITION P20230312 VALUES LESS THAN (738957) ENGINE = InnoDB, PARTITION P20230313 VALUES LESS THAN (738958) ENGINE = InnoDB, PARTITION P20230314 VALUES LESS THAN (738959) ENGINE = InnoDB, PARTITION P20230315 VALUES LESS THAN (738960) ENGINE = InnoDB, PARTITION P20230316 VALUES LESS THAN (738961) ENGINE = InnoDB, PARTITION P20230317 VALUES LESS THAN (738962) ENGINE = InnoDB, PARTITION P20230318 VALUES LESS THAN (738963) ENGINE = InnoDB, PARTITION P20230319 VALUES LESS THAN (738964) ENGINE = InnoDB, PARTITION P20230320 VALUES LESS THAN (738965) ENGINE = InnoDB, PARTITION P20230321 VALUES LESS THAN (738966) ENGINE = InnoDB, PARTITION P20230322 VALUES LESS THAN (738967) ENGINE = InnoDB, PARTITION P20230323 VALUES LESS THAN (738968) ENGINE = InnoDB, PARTITION P20230324 VALUES LESS THAN (738969) ENGINE = InnoDB, PARTITION P20230325 VALUES LESS THAN (738970) ENGINE = InnoDB, PARTITION P20230326 VALUES LESS THAN (738971) ENGINE = InnoDB, PARTITION P20230327 VALUES LESS THAN (738972) ENGINE = InnoDB, PARTITION P20230328 VALUES LESS THAN (738973) ENGINE = InnoDB, PARTITION p20230329 VALUES LESS THAN (738974) ENGINE = InnoDB, PARTITION p20230330 VALUES LESS THAN (738975) ENGINE = InnoDB, PARTITION p20230331 VALUES LESS THAN (738976) ENGINE = InnoDB, PARTITION p20230401 VALUES LESS THAN (738977) ENGINE = InnoDB, PARTITION p20230402 VALUES LESS THAN (738978) ENGINE = InnoDB, PARTITION p20230403 VALUES LESS THAN (738979) ENGINE = InnoDB);插入数据greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-10' ;Query OK, 1 row affected (0.01 sec)Records: 1 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-10' ;Query OK, 1 row affected (0.00 sec)Records: 1 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-10' ;Query OK, 1 row affected (0.01 sec)Records: 1 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),start_time from t_partition; Query OK, 3 rows affected (0.01 sec)Records: 3 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),start_time from t_partition; Query OK, 6 rows affected (0.00 sec)Records: 6 Duplicates: 0 Warnings: 0............... greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),start_time from t_partition; Query OK, 3145728 rows affected (35.68 sec)Records: 3145728 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),start_time from t_partition; Query OK, 6291456 rows affected (1 min 11.51 sec)Records: 6291456 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),start_time from t_partition; Query OK, 12582912 rows affected (2 min 26.74 sec)Records: 12582912 Duplicates: 0 Warnings: 0greatsql> select count(*) from t_partition; +----------+| count(*) |+----------+| 25165824 |+----------+1 row in set (0.50 sec)greatsql> select count(*) from t_partition partition(P20230310); +----------+| count(*) |+----------+| 25165824 |+----------+ 向分区插入数据insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-11' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-12' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-13' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-14' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-15' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-16' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-17' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-18' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-19' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-20' from t_partition partition(P20230310); insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-21' from t_partition partition(P20230310); 。。。。。。。。。。。greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-19' from t_partition partition(P20230310); Query OK, 25165824 rows affected (5 min 17.92 sec)Records: 25165824 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-20' from t_partition partition(P20230310); Query OK, 25165824 rows affected (5 min 19.56 sec)Records: 25165824 Duplicates: 0 Warnings: 0greatsql> insert into t_partition(ua,start_time) select substring(md5(rand()),1,20),'2023-03-21' from t_partition partition(P20230310); Query OK, 25165824 rows affected (5 min 27.27 sec)Records: 25165824 Duplicates: 0 Warnings: 0 更新数据greatsql> Update t_partition set ua=concat(ua,'abc') where start_time='2023-03-19';Query OK, 25165824 rows affected (12 min 55.53 sec)Rows matched: 25165824 Changed: 25165824 Warnings: 0删除分区sgreatsql> alter table t_partition drop partition P20230311;Query OK, 0 rows affected (13.68 sec)Records: 0 Duplicates: 0 Warnings: 0greatsql> alter table t_partition drop partition P20230312;Query OK, 0 rows affected (0.07 sec)Records: 0 Duplicates: 0 Warnings: 0两个分区数据量是一样,但删除第一个分区耗时较长。
...