Chinaunix首页 | 论坛 | 博客
  • 博客访问: 763282
  • 博文数量: 99
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1163
  • 用 户 组: 普通用户
  • 注册时间: 2016-09-22 09:50
个人简介

一个守望数据库的老菜鸟

文章分类

全部博文(99)

文章存档

2019年(21)

2018年(17)

2017年(37)

2016年(24)

我的朋友

分类: Mysql/postgreSQL

2017-06-11 17:32:13


博客文章除注明转载外,均为原创。转载请注明出处。
本文链接地址:http://blog.chinaunix.net/uid-31396856-id-5766123.html

pt-duplicate-key-checker工具主要实现的功能为是mysql表中找出重复的索引和外键。索引会更查询带来好处,但是过量的索引反而可能会使数据库的性能降低,
pt-duplicate-key-checker会将重复的索引和外键都列出来,并生成了删除重复索引的语句,非常使用。
部分参数介绍
--ask-pass 输入密码询问
--all-structs  比较索引不同的结构(B树, HASH,T树等)
--charset -A 指定字符集
--databases -d   检查的数据库名称
--defaults-file  指定配置文件
--engines  要检查相关存储引擎的表
--tables -t 指定检查的表
--ignore-tables  忽略检查的表
更详细的使用方法请见--help

[root@hhrpp76_sn_che ~]# pt-duplicate-key-checker --host=localhost --user=root --password=*********  --databases=hhrppdb
# ########################################################################
# hhrdb.matc_loan                                                           
# ########################################################################


# source_type is a duplicate of idx_source_type_ml
# Key definitions:
#   KEY `source_type` (`source_type`) USING BTREE,
#   KEY `idx_source_type_ml` (`source_type`),
# Column types:
#  `source_type` tinyint(4) not null comment '************'
# To remove this duplicate index, execute:
ALTER TABLE `hhr`.`matc_loan` DROP INDEX `source_type`;      //处理重复索引的sql语句也提供了,非常方便
# ########################################################################
# Summary of indexes   --概要                                                   
# ########################################################################

# Size Duplicate Indexes   11726
# Total Duplicate Indexes  1
# Total Indexes            176

再比如冗余索引示例:
# ########################################################################
# hhrdb.account_message_info                                               
# ########################################################################

# idx_topieces_id_cmi is a left-prefix of idx_intopieces_account_camd
# Key definitions:
#   KEY `idx_topieces_id_cmi` (`topieces_id`) USING BTREE,
#   UNIQUE KEY `idx_intopieces_account_cmi` (`topieces_id`,`account_number`),
# Column types:
#  `topieces_id` int(11) not null comment '******'
#  `account_number` char(20) not null comment '*************'
# To remove this duplicate index, execute:
ALTER TABLE `hhrdb`.`account_message_info` DROP INDEX `idx_topieces_id_cmi`;


# idx_submit_time_cms is a left-prefix of idx_st_at_as_camd
# Key definitions:
#   KEY `idx_submit_time_cmi` (`submit_time`),
#   KEY `idx_st_at_as_cmi` (`submit_time`,`account_type`,`account_static`),
# Column types:
#  `submit_time` int(11) not null comment '*****'
#  `account_type` tinyint(1) not null default '1' comment '1-**** 2-****** 3-*****'
#  `account_static` int(11) not null comment '****'
# To remove this duplicate index, execute:
ALTER TABLE `hhrdb`.`account_message_info` DROP INDEX `idx_submit_time_cmi`;


工具输出的结果也很简单清晰。
---The end
阅读(1781) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~