pt-duplicate-key-checker工具可以检测表中重复的索引,对于一些业务量很大的表,而且开发不规范的情况下有用。基本用法:
看一下我们的测试表:
mysql> desc new_orders;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| no_o_id | int() | NO | PRI | NULL | |
| no_d_id | tinyint() | NO | PRI | NULL | |
| no_w_id | smallint() | NO | PRI | NULL | |
+---------+-------------+------+-----+---------+-------+
rows in set (0.00 sec)
mysql> create index idx1 on new_orders(no_o_id);
Query OK, rows affected (0.92 sec)
Records: Duplicates: Warnings:
mysql> create index idx2 on new_orders(no_o_id);
Query OK, rows affected, warning (0.93 sec)
Records: Duplicates: Warnings:
mysql> create index idx3 on new_orders(no_o_id);
Query OK, rows affected, warning (0.87 sec)
Records: Duplicates: Warnings:
mysql> create index idx3 on new_orders(no_o_id,no_d_id);
ERROR (): Duplicate key name 'idx3'
mysql> create index idx4 on new_orders(no_o_id,no_d_id);
Query OK, rows affected (1.07 sec)
Records: Duplicates: Warnings:
mysql> create index idx5 on new_orders(no_o_id,no_d_id,no_w_id);
Query OK, rows affected (1.04 sec)
Records: Duplicates: Warnings:
mysql> create index idx6 on new_orders(no_o_id,no_d_id,no_w_id);
Query OK, rows affected, warning (1.58 sec)
Records: Duplicates: Warnings:
下面开始进行检测:
[root@mxqmongodb2 bin]# ./pt-duplicate-key-checker --host=172.16.16.35 --port= --user=root --password= --database=test --tables=new_orders;
# ########################################################################
# test.new_orders
# ######################################################################## # idx6 is a duplicate of idx5
# Key definitions:
# KEY `idx6` (`no_o_id`,`no_d_id`,`no_w_id`)
# KEY `idx5` (`no_o_id`,`no_d_id`,`no_w_id`),
# Column types:
# `no_o_id` int() not null
# `no_d_id` tinyint() not null
# `no_w_id` smallint() not null
# To remove this duplicate index, execute:
ALTER TABLE `test`.`new_orders` DROP INDEX `idx6`; # idx4 is a left-prefix of idx5
# Key definitions:
# KEY `idx4` (`no_o_id`,`no_d_id`),
# KEY `idx5` (`no_o_id`,`no_d_id`,`no_w_id`),
# Column types:
# `no_o_id` int() not null
# `no_d_id` tinyint() not null
# `no_w_id` smallint() not null
# To remove this duplicate index, execute:
ALTER TABLE `test`.`new_orders` DROP INDEX `idx4`; # idx1 is a left-prefix of idx5
# Key definitions:
# KEY `idx1` (`no_o_id`),
# KEY `idx5` (`no_o_id`,`no_d_id`,`no_w_id`),
# Column types:
# `no_o_id` int() not null
# `no_d_id` tinyint() not null
# `no_w_id` smallint() not null
# To remove this duplicate index, execute:
ALTER TABLE `test`.`new_orders` DROP INDEX `idx1`; # idx2 is a left-prefix of idx5
# Key definitions:
# KEY `idx2` (`no_o_id`),
# KEY `idx5` (`no_o_id`,`no_d_id`,`no_w_id`),
# Column types:
# `no_o_id` int() not null
# `no_d_id` tinyint() not null
# `no_w_id` smallint() not null
# To remove this duplicate index, execute:
ALTER TABLE `test`.`new_orders` DROP INDEX `idx2`; # idx3 is a left-prefix of idx5
# Key definitions:
# KEY `idx3` (`no_o_id`),
# KEY `idx5` (`no_o_id`,`no_d_id`,`no_w_id`),
# Column types:
# `no_o_id` int() not null
# `no_d_id` tinyint() not null
# `no_w_id` smallint() not null
# To remove this duplicate index, execute:
ALTER TABLE `test`.`new_orders` DROP INDEX `idx3`; # ########################################################################
# Summary of indexes
# ######################################################################## # Size Duplicate Indexes
# Total Duplicate Indexes
# Total Indexes
我们看到,除了主键以外,其他的索引按说都是不成功的,但是pt-duplicate-key-checker只检查到了五个重复索引,这个重复不是我们理解的完全一样,而是包含索引。`idx5` (`no_o_id`,`no_d_id`,`no_w_id`),包含了刚才创建的1-4的索引,而且和6的索引是一样的。而主键的排序和idx5是不一样的所以说两者不同,也是满足了最左匹配的原则。

最新文章

  1. mac下安装tomcat
  2. Yii rules常用规则
  3. 手把手教你在ubuntu上安装apache和mysql和php
  4. JavaScript的9个陷阱及评点
  5. 万能写入sql语句,并且防注入
  6. Qt---在QLabel上实现系统时间
  7. sping注解原理
  8. 浅谈Spring(三)
  9. sql server 查看表的行数
  10. js如何获取样式?
  11. javascript数据类型之Array类型
  12. 高并发系统保护~ing
  13. MongoDB启动报错 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability. 【转】
  14. 清北学堂学习总结day2
  15. 【转载】Hadoop官方文档翻译——HDFS Architecture 2.7.3
  16. node.js中使用zlib模块进行数据压缩和解压
  17. 20170821xlVBA跨表公式套用
  18. 尚硅谷redis学习10-复制
  19. Codeforces Beta Round #46 (Div. 2)
  20. form表单序列化为json格式数据

热门文章

  1. es第十篇:Elasticsearch for Apache Hadoop
  2. springboot pom.xml文件
  3. Java - 自定义异常(尚学堂第六章异常机制作业计算平均数)
  4. 详解exif.js,应用于canvas照片倒转(海报H5)
  5. day2-模块初识之路径问题
  6. Apache-jmeter3.3安装
  7. Flyway-使用步骤
  8. RESTful简单介绍
  9. 微服务~Consul服务注册与发现
  10. Linux下安装jdk1.6