Home > Database > Mysql Tutorial > body text

MySQL 冗余和重复索引

WBOY
Release: 2016-06-07 17:39:47
Original
1398 people have browsed it

冗余和重复索引冗余和重复索引的概念:MySQL允许在相同列上创建多个索引,无论是有..

                                       冗余和重复索引

冗余和重复索引的概念:

MySQL允许在相同列上创建多个索引,无论是有意的还是无意的。MySQL需要单独维护重复的索引,香港虚拟主机,并且优化器在优化查询的时候也需要逐个地进行考虑,香港虚拟主机,这会影响性能。

重复索引:是指在相同的列上按照相同的顺序创建的相同类型的索引。应该避免这样创建重复索引,发现后也应该立即移除。

eg:有时会在不经意间创建了重复索引

CREATE TABLE test ( id INT NOT NULL PRIMARY KEY, a INT NOT NULL, INDEX(ID) )ENGINE=InnoDB;

pt-duplicate-key-checker -udbuser -pdbpaswd --charset=gbk \ --database=dbname

执行过后将会统计出有关dbname数据库的重复和冗余的索引,内容如下:

# ######################################################################## # dbname.test1 # ######################################################################## # vkey is a left-prefix of keydesc_index # Key definitions: # KEY `vkey` (`VehicleKey`), # KEY `keydesc_index` (`VehicleKey`,`Description`) # Column types: # `vehiclekey` char(8) not null default '' # `description` char(255) not null default '' # To remove this duplicate index, execute: ALTER TABLE `dbname`.`test1` DROP INDEX `vkey`; # ######################################################################## # dbname.test2 # ######################################################################## # vkey is a duplicate of PRIMARY # Key definitions: # KEY `vkey` (`VehicleKey`), # PRIMARY KEY (`VehicleKey`), # Column types: # `vehiclekey` varchar(8) not null default '0' # To remove this duplicate index, execute: ALTER TABLE `dbname`.`test2` DROP INDEX `vkey`;

它会统计出所有出现的重复,冗余的索引,服务器空间,还将要执行的SQL语句也提供了,是不是很方便。

想了解其工具所有参数或其用法的请参考:pt-duplicate-key-checker

本文出自 “Focus on the database” 博客,请务必保留此出处

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!