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. WinScp结合Putty在Windows与UNIX之间进行文件传输

    1. 关于传输协议: SSH Secure Shell安全外壳协议 SFTP Secure File Transfer Protocal安全文件传送协议 2. WinScp与Putty的作用: Put ...

  2. Python处理文件和查漏

    import os,re def change_filename(root): ''' 批量修改excel文件名 ''' for root_,_, fs in os.walk(root): for f ...

  3. UGUI优化总结

    1.动静分离 canvas下元素变化时,会使整个canvas重新绘制.因此将ui经常改变和不怎么改变的部分分离,分别使用不同的canvas. 2.图集优化 不同界面的ui,可以打包成不同的图集,一些公 ...

  4. kafka java API的使用

    Kafka包含四种核心的API: 1.Producer API支持应用将数据流发送到Kafka集群的主题 2.Consumer API支持应用从Kafka集群的主题中读取数据流 3.Streams A ...

  5. ACS蚁群算法求解对称TSP旅行商问题的JavaScript实现

    本来以为在了解蚁群算法的基础上实现这道奇怪的算法题并不难,结果实际上大相径庭啊.做了近三天时间,才改成现在这能勉强拿的出手的模样.由于公式都是图片,暂且以截图代替那部分内容吧,mark一记. 1 蚁群 ...

  6. FocusBI:SSAS体系结构(原创)

    关注微信公众号:FocusBI 查看更多文章:加QQ群:808774277   获取学习资料和一起探讨问题. SSAS是微软BI组件系列中最核心的组件,商业智能的心脏所有的数据都从这里统一输出,它能把 ...

  7. NPOI excel导出快速构建

    直接上代码,这个是一个在webFrom中的例子,要请求的页面是ashx public void ExportVisaFeeAll(HttpContext context) { try { string ...

  8. Firebird 列可空非空修改

    2018-12-04 至少到Firebird 3.0.4 已经添加了设置可空 和 非空的语法:如 -- 删除非空(设置为可空) ALTER TABLE TECH ALTER label drop NO ...

  9. pom resource配置

    maven pom配置资源resource, make时可自动发布到release目录的 \WEB-INF\classes 下. 解决使用idea时, 每次都需要配置资源文件的手动配置. 具体: &l ...

  10. 提示"No 'Access-Control-Allow-Origin' header"及Spring 中解决跨域问题

    问题描述 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://12 ...