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是不一样的所以说两者不同,也是满足了最左匹配的原则。

pt-duplicate-key-checker使用的更多相关文章

  1. ON DUPLICATE KEY UPDATE重复插入时更新

    mysql当插入重复时更新的方法: 第一种方法: 示例一:插入多条记录 假设有一个主键为 client_id 的 clients 表,可以使用下面的语句: INSERT INTO clients (c ...

  2. 【转】MySQL的Replace into 与Insert into on duplicate key update真正的不同之处

    原文链接:http://www.jb51.net/article/47090.htm   今天听同事介绍oracle到mysql的数据migration,他用了Insert into ..... on ...

  3. ON DUPLICATE KEY UPDATE

    如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则在出现重复值的行执行UPDATE: 如果 ...

  4. 深入mysql "on duplicate key update" 语法的分析

    如果在INSERT语句末尾指定了on duplicate key update,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则在出现重复值的行执行UPDATE:如果不 ...

  5. [BTS]The join order has been enforced because a local join hint is used.;Duplicate key was ignored.".

    在一个客户的BizTalk Server 2013 R2环境中会报如下的ERROR,查找相关资料后,先试试停掉所有Trace. Log Name:      ApplicationSource:    ...

  6. INSERT INTO .. ON DUPLICATE KEY更新多行记录

    现在问题来了,如果INSERT多行记录, ON DUPLICATE KEY UPDATE后面字段的值怎么指定?要知道一条INSERT语句中只能有一个ON DUPLICATE KEY UPDATE,到底 ...

  7. insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a=10001

    insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a ...

  8. MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)

    ON DUPLICATE KEY UPDATE  博客 http://blog.csdn.net/jbboy/article/details/46828917

  9. mysql:on duplicate key update与replace into

    在往表里面插入数据的时候,经常需要:a.先判断数据是否存在于库里面:b.不存在则插入:c.存在则更新 一.replace into 前提:数据库里面必须有主键或唯一索引,不然replace into ...

  10. mysql 插入重复值 INSERT ... ON DUPLICATE KEY UPDATE

    向数据库插入记录时,有时会有这种需求,当符合某种条件的数据存在时,去修改它,不存在时,则新增,也就是saveOrUpdate操作.这种控制可以放在业务层,也可以放在数据库层,大多数数据库都支持这种需求 ...

随机推荐

  1. Celery 分布式任务队列快速入门 以及在Django中动态添加定时任务

    Celery 分布式任务队列快速入门 以及在Django中动态添加定时任务 转自 金角大王 http://www.cnblogs.com/alex3714/articles/6351797.html ...

  2. c# 短链接生成

    public static string GetShortUrl(string url) { //可以自定义生成MD5加密字符传前的混合KEY string key = DateTime.Now.To ...

  3. django notes 二:URL dispatcher

    一般在 settings.py 中会有一个  ROOT_URLCONF ,请求到来时 django 会从 ROOT_URLCONF 指向的文件中查找  urlpatterns 变量配置的路由. url ...

  4. 分布式集群HBase启动后某节点的HRegionServer自动消失问题

    详细问题   我这里是,我的这个slave1的HRegionServer 进程启动后,不久自动消失.           去查看日志,排查问题: 发现问题: 解决办法 [hadoop@master h ...

  5. Hibernate 多对多拆分 两个多对一

  6. BNU 33693——Problemsetting——————【枚举+最大流】

    Problemsetting Time Limit: 5000ms Memory Limit: 131072KB 64-bit integer IO format: %lld      Java cl ...

  7. chmod修改文件的权限/chown修改文件和目录的所有者(转)

    ll指令的显示的信息为(当前目录下只有nameservice1一个目录): drwxr-xr-x 3 hdfs hdfs 4096 4月 14 16:19 nameservice1 上述信息分别表示: ...

  8. Expression Blend实例中文教程(5) - 布局控件快速入门StackPanel,ScrollViewer和Border

    上一篇,介绍了Canvas布局控件在Blend中的使用.本篇继续介绍布局控件StackPanel,ScrollViewer和Border. 相对于Grid和Canvas来说,StackPanel,Sc ...

  9. JavaMail 邮件发送

    jar包部署 /** * 通过SMTP进行邮件集成 */ public class CmpSendMail { // 邮件发送服务器主机 private final static String HOS ...

  10. java.lang.RuntimeException: Canvas: trying to draw too large(107331840bytes) bitmap.

    环境: Android 8.0.1 MIUI 真机测试闪退 gradle 4.1 compileSdkVersion 26 buildToolsVersion '26.0.2' minSdkVersi ...