Percona-Tookit工具包之pt-duplicate-key-checker
pt-duplicate-key-checker [OPTIONS] [DSN]
--clustered //Treats the columns of pripary key to be redundent like secondary key does.(default "yes")
--key-types //Specify the type of index to check.(default "fk" means both of f&k,f=foreign keys,k=ordinary keys)
--database //Specify the database you want to check.
--tables //Specify the tables you want to check.
--ignore-databases //Specify the ignoring database.
--ignore-tables //Specify the ignoring tables.
--ignore-order //Treats the key(a,b) to be duplicated when it is compared with the key(b,a)
--sql //Generate dropping index sql statment for those duplicated indexes.
(zlm@192.168.1.101 )[sysbench]>show tables;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest1 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
+--------------------+
rows in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>show create table sbtest4\G
*************************** . row ***************************
Table: sbtest4
Create Table: CREATE TABLE `sbtest4` (
`id` int() NOT NULL AUTO_INCREMENT,
`k` int() NOT NULL DEFAULT '',
`c` char() NOT NULL DEFAULT '',
`pad` char() NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `k_4` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT= DEFAULT CHARSET=utf8
row in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>show index from sbtest4;
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| sbtest4 | | PRIMARY | | id | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | k_4 | | k | A | | NULL | NULL | | BTREE | | |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
rows in set (0.00 sec) (zlm@192.168.1.101 )[sysbench]>
(zlm@192.168.1.101 )[sysbench]>alter table sbtest4 add index idx_id_k1(id,k);
Query OK, rows affected (0.11 sec)
Records: Duplicates: Warnings: (zlm@192.168.1.101 )[sysbench]>show index from sbtest4;
+---------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| sbtest4 | | PRIMARY | | id | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | k_4 | | k | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | idx_id_k1 | | id | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | idx_id_k1 | | k | A | | NULL | NULL | | BTREE | | |
+---------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
[root@zlm2 :: ~]
#pt-duplicate-key-checker -d=sysbench -t=sbtest4
# ########################################################################
# Summary of indexes
# ######################################################################## # Total Indexes //No duplicated indexes were found. [root@zlm2 :: ~]
#pt-duplicate-key-checker -dsysbench -tsbtest4
# ########################################################################
# Summary of indexes
# ######################################################################## # Total Indexes
[root@zlm2 :: ~]
#pt-duplicate-key-checker -dsysbench -tsbtest4 -h192.168.1. -P3306 -uzlm -pzlmzlm --no-clustered
# ########################################################################
# sysbench.sbtest4
# ######################################################################## # k_4 is a left-prefix of idx_id_k2
# Key definitions:
# KEY `k_4` (`k`),
# KEY `idx_id_k2` (`k`,`id`) //The index "idx_id_k2" contains the column in index "k_4" and in the same order.Therefore,"k_4" is indicated redundant.
# Column types:
# `k` int() not null default ''
# `id` int() not null auto_increment
# To remove this duplicate index, execute:
ALTER TABLE `sysbench`.`sbtest4` DROP INDEX `k_4`; # ########################################################################
# Summary of indexes
# ######################################################################## # Size Duplicate Indexes
# Total Duplicate Indexes
# Total Indexes
[root@zlm2 :: ~]
#pt-duplicate-key-checker -dsysbench -tsbtest4 -h192.168.1. -P3306 -uzlm -pzlmzlm
# ########################################################################
# sysbench.sbtest4
# ######################################################################## # k_4 is a left-prefix of idx_id_k2
# Key definitions:
# KEY `k_4` (`k`),
# KEY `idx_id_k2` (`k`,`id`)
# Column types:
# `k` int() not null default ''
# `id` int() not null auto_increment
# To remove this duplicate index, execute:
ALTER TABLE `sysbench`.`sbtest4` DROP INDEX `k_4`; # Key idx_id_k2 ends with a prefix of the clustered index
# Key definitions:
# KEY `idx_id_k2` (`k`,`id`)
# PRIMARY KEY (`id`),
# Column types:
# `k` int() not null default ''
# `id` int() not null auto_increment
# To shorten this duplicate clustered index, execute:
ALTER TABLE `sysbench`.`sbtest4` DROP INDEX `idx_id_k2`, ADD INDEX `idx_id_k2` (`k`); //The tool suggests to change the union index to a single column key. # ########################################################################
# Summary of indexes
# ######################################################################## # Size Duplicate Indexes
# Total Duplicate Indexes
# Total Indexes
(zlm@192.168.1.101 )[sysbench]>alter table sbtest4 add index idx_id_k2(k,id);
Query OK, rows affected (0.04 sec)
Records: Duplicates: Warnings: (zlm@192.168.1.101 )[sysbench]>show index from sbtest4;
+---------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| sbtest4 | | PRIMARY | | id | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | k_4 | | k | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | idx_id_k1 | | id | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | idx_id_k1 | | k | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | idx_id_k2 | | k | A | | NULL | NULL | | BTREE | | |
| sbtest4 | | idx_id_k2 | | id | A | | NULL | NULL | | BTREE | | |
+---------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
rows in set (0.00 sec)
[root@zlm2 :: ~]
#pt-duplicate-key-checker -dsysbench -tsbtest4 -h192.168.1. -P3306 -uzlm -pzlmzlm
# ########################################################################
# sysbench.sbtest4
# ######################################################################## # k_4 is a left-prefix of idx_id_k2
# Key definitions:
# KEY `k_4` (`k`),
# KEY `idx_id_k2` (`k`,`id`)
# Column types:
# `k` int() not null default ''
# `id` int() not null auto_increment
# To remove this duplicate index, execute:
ALTER TABLE `sysbench`.`sbtest4` DROP INDEX `k_4`; # Key idx_id_k2 ends with a prefix of the clustered index
# Key definitions:
# KEY `idx_id_k2` (`k`,`id`)
# PRIMARY KEY (`id`),
# Column types:
# `k` int() not null default ''
# `id` int() not null auto_increment
# To shorten this duplicate clustered index, execute:
ALTER TABLE `sysbench`.`sbtest4` DROP INDEX `idx_id_k2`, ADD INDEX `idx_id_k2` (`k`); # ########################################################################
# Summary of indexes
# ######################################################################## # Size Duplicate Indexes
# Total Duplicate Indexes
# Total Indexes
[root@zlm2 :: ~]
#pt-duplicate-key-checker --databases=sysbench --tables=sbtest4 --ignore-order -h192.168.1. -P3306 -uzlm -pzlmzlm
# ########################################################################
# sysbench.sbtest4
# ######################################################################## # idx_id_k2 is a duplicate of idx_id_k1
# Key definitions:
# KEY `idx_id_k2` (`k`,`id`)
# KEY `idx_id_k1` (`id`,`k`),
# Column types:
# `k` int() not null default ''
# `id` int() not null auto_increment
# To remove this duplicate index, execute:
ALTER TABLE `sysbench`.`sbtest4` DROP INDEX `idx_id_k2`; //Why no dropping "idx_id_k1"?Beacause "idx_id_k2" is also a duplicate of "k_4" as we can see above. # ########################################################################
# Summary of indexes
# ######################################################################## # Size Duplicate Indexes
# Total Duplicate Indexes
# Total Indexes
- Notice the difference between long option and short option,do not mix them up.
- pt-duplicate-key-checker is quit convenient to generate a summay report of rudundant indexes in specific databases.
- We can execute it with script in a certain interval of time and collect the information in a flat logfile for future analysis.
- It also provides us the pertinent SQL statement to adjust the indexes in target tables.
- Further more,we'd better compare the result of the tool with the data in sys.schema_redundant_indexes(5.7 or above).
Percona-Tookit工具包之pt-duplicate-key-checker的更多相关文章
- ON DUPLICATE KEY UPDATE重复插入时更新
mysql当插入重复时更新的方法: 第一种方法: 示例一:插入多条记录 假设有一个主键为 client_id 的 clients 表,可以使用下面的语句: INSERT INTO clients (c ...
- 【转】MySQL的Replace into 与Insert into on duplicate key update真正的不同之处
原文链接:http://www.jb51.net/article/47090.htm 今天听同事介绍oracle到mysql的数据migration,他用了Insert into ..... on ...
- ON DUPLICATE KEY UPDATE
如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则在出现重复值的行执行UPDATE: 如果 ...
- 深入mysql "on duplicate key update" 语法的分析
如果在INSERT语句末尾指定了on duplicate key update,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则在出现重复值的行执行UPDATE:如果不 ...
- [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: ...
- INSERT INTO .. ON DUPLICATE KEY更新多行记录
现在问题来了,如果INSERT多行记录, ON DUPLICATE KEY UPDATE后面字段的值怎么指定?要知道一条INSERT语句中只能有一个ON DUPLICATE KEY UPDATE,到底 ...
- 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 ...
- MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
ON DUPLICATE KEY UPDATE 博客 http://blog.csdn.net/jbboy/article/details/46828917
- mysql:on duplicate key update与replace into
在往表里面插入数据的时候,经常需要:a.先判断数据是否存在于库里面:b.不存在则插入:c.存在则更新 一.replace into 前提:数据库里面必须有主键或唯一索引,不然replace into ...
- mysql 插入重复值 INSERT ... ON DUPLICATE KEY UPDATE
向数据库插入记录时,有时会有这种需求,当符合某种条件的数据存在时,去修改它,不存在时,则新增,也就是saveOrUpdate操作.这种控制可以放在业务层,也可以放在数据库层,大多数数据库都支持这种需求 ...
随机推荐
- Python-Django框架学习笔记——第二课:Django的搭建
Django 环境搭建 一. 版本选择 Django 1.5.x 支持 Python 2.6.5 Python 2.7, Python 3.2 和 3.3. Django 1.6.x 支持 Pytho ...
- Android 中间白色渐变到看不见的线的Drawable
用gradient <gradient android:startColor="#00ffffff" android:centerColor="#ffffff&qu ...
- EF 连接数据库 Mysql (database first ) 一个表对应一个模型
准备工作 1.下载vs2015 2.下载mysql2017 3.安装 1.创建数据库 2. 将数据库映射成模型 3创建aspx 文件. 写下窗体内容的代码 hello_worldEntities en ...
- 【转】Spring 整合 Quartz 实现动态定时任务
http://blog.csdn.net/u014723529/article/details/51291289 最近项目中需要用到定时任务的功能,虽然spring 也自带了一个轻量级的定时任务实现, ...
- Spring 注解中@Resource 和 @Authwired 的区别
@Resource的作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入罢了.@Resource有两个属性是比较重要的,分 ...
- 前端jQuery之动画操作及相关演示
1.显示动画 1.1无参数,直接让指定的元素显示出来 $("div").show(); 1.2通过控制宽高,透明度,display属性逐渐显示,指定时间现实完毕 $('div'). ...
- 初探12C碰到的那些“坑”
一个昏天黑地的早上,刚搭建的系统忽然遭遇严重数据库问题.于是,主要人物闪亮登场了,他们分别是友商人员小灰和DBA小Y. 事情的开始,小Y接到小灰紧急救助电话... 小灰:小Y,我是友商的小灰,刚搭建的 ...
- CSS之美化页面
CSS之美化页面 <span></span> 标签 <span>行内定义一个区域 就是说一行可以被<span>划分多个小区域,从而实现某种特定效果.&l ...
- js中document的用法小结
document常用属性: document.title//设置文档标题,与HTNL中的title标签等价 document.bgColor//设置页面背景颜色 document.fgColor//设 ...
- matlab2018a安装后帮助文档打不开解决方法
安装matlab2018a破解版后,帮助文档提示需要许可证问题(破解版没有可用许可证): 解决方法是把文档设置为离线即可(预设---->帮助---->安装在本地---->小窗口)