percona-toolkit之pt-index-usage和pt-duplicate-key-checker详解

1>

pt-index-usage:从慢查询日志中读取查询并分析它们如何使用索引。  (用来查找不常使用索引)

./pt-index-usage --help

 

打印报告

复制代码
复制代码
 1 ./pt-index-usage  /mysqldata/mysqlslowlog/slowquery.log -h192.168.226.131 -uroot -p6yhn^YHN -decology
 2 
 3  
 5 [mysql@mysql bin]$ ./pt-index-usage  /mysqldata/mysqlslowlog/slowquery.log -h192.168.226.131 -uroot -p6yhn^YHN 
 7 DBD::mysql::db selectall_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/' at line 1 [for Statement "EXPLAIN SELECT IFNULL(SUM(INDEX_LENGTH),0) from information_schema.TABLES where ENGINE='InnoDB' */"] at ./pt-index-usage line 4598, <> line 1.
 9 DBD::mysql::db selectall_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/' at line 1 [for Statement "EXPLAIN SELECT IFNULL(SUM(DATA_LENGTH),0) from information_schema.TABLES where ENGINE='InnoDB' */"] at ./pt-index-usage line 4598, <> line 2.
11 DBD::mysql::db selectall_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/' at line 1 [for Statement "EXPLAIN SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' */"] at ./pt-index-usage line 4598, <> line 4.
12 
15 ALTER TABLE `test1`.`user` DROP KEY `idx_1`; -- type:non-unique
16
复制代码
复制代码

 

2>  pt-duplicate-key-checker检查数据库的重复索引

索引会更查询带来好处,但是过量的索引反而可能会使数据库的性能降低

1 ./pt-duplicate-key-checker --help

 

1> 表结构

复制代码
复制代码
 1 [root@localhost][test1]> show index from user;
 2 
 3 +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
 4 
 5 | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
 6 
 7 +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
 8 
 9 | user  |          0 | PRIMARY  |            1 | id          | A         |     1042305 |     NULL | NULL   |      | BTREE      |         |               |
10 
11 | user  |          1 | idx_1    |            1 | id          | A         |     1042305 |     NULL | NULL   |      | BTREE      |         |               |
12 
13 +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
14 
15  
复制代码
复制代码

 

字段id有两个索引,

复制代码
复制代码
 1 [mysql@mysql bin]$ ./pt-duplicate-key-checker -uroot -p6yhn^YHN
 2 
 3 # ########################################################################
 4 
 5 # test1.user                                                              
 6 
 7 # ########################################################################
 8 
 9  
10 
11 # idx_1 is a duplicate of PRIMARY
12 
13 # Key definitions:
14 
15 #   KEY `idx_1` (`id`)
16 
17 #   PRIMARY KEY (`id`),
18 
19 # Column types:
20 
21 #         `id` int(11) not null auto_increment
22 
23 # To remove this duplicate index, execute:
24 
25 ALTER TABLE `test1`.`user` DROP INDEX `idx_1`;
26 
27  
28 
29 # ########################################################################
30 
31 # Summary of indexes                                                      
32 
33 # ########################################################################
34 
35  
36 
37 # Size Duplicate Indexes   4169220
38 
39 # Total Duplicate Indexes  1
40 
41 # Total Indexes            34
42 
43  
复制代码
复制代码

posted on   数据与人文  阅读(331)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示