Shuo
Shuo I'm a DBA(Database Administrator), we can share and discuss MySQL, MongoDB, Redis and other databases here, also including learning Python, Shell, Golang together.

MySQL重复索引检查工具:pt-duplicate-key-checker


MySQL重复索引检查工具:pt-duplicate-key-checker

功能介绍:

在MySQL数据库表中找出重复的索引和外键,这个工具会将重复的索引和外键都列出来,并生成删除重复索引的语句。

用法介绍:

pt-duplicate-key-checker [OPTION…]

[DSN]包含比较多的选项,具体的可以通过命令pt-duplicate-key-checker –help来查看具体支持那些选项。

使用示例:

查看test数据库的重复索引和外键使用情况:

1
2
pt-duplicate-key-checker --host=localhost --user=root --password=aaa123 --databases=test

得到结果如下:

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
......

Key idx_Create_id ends with a prefix of the clustered index

Key definitions:
    KEY `idx_Create_id` (`CREATE`,`ID`)
    PRIMARY KEY (`ID`),

Column types:
    `create` timestamp not null default '0000-00-00 00:00:00'
     `id` bigint(20) not null auto_increment

To shorten this duplicate clustered index, execute:

     **ALTER TABLE `test`.`OUTPUT_STAT` DROP INDEX `idx_GmtCreate_id`, ADD INDEX `idx_GmtCreate_id` (`GMT_CREATE`);**

########################################################################

Summary of indexes                                                     

########################################################################

Size Duplicate Indexes  252

Total Duplicate Indexes  8

Total Indexes            149

根据日志可以看出:
1.发现了重复索引 idx_Create_id (CREATE,ID) ,可以使用以下语句进行优化:

ALTER TABLE test.OUTPUT_STAT DROP INDEX idx_GmtCreate_id, ADD INDEX idx_GmtCreate_id (GMT_CREATE);

2.索引情况的汇总信息

comments powered by Disqus