Description
pt-duplicate-key-checker
is a tool by Percona that can find redundant database indexes. A blog about this tool is available.
It reduced the size of our database with about 10%, and it speeds up writing. Most of those optimizations seem to apply to any OpenMage installation, but some of them are from 3rd party modules.
Some of the duplicates apply to InnoDB only, because InnoDB always includes the PRIMARY
column in any B-tree index, it is therefore not necessary to add the PRIMARY column to any other index.
Another common occurence is that there is an index (A), as well as an index (A,B). In that case, (A) is not necessary, (A,B) satisfies it*.
* But, not (B, A). The sequence matters, hence the term "left-prefix of"
Sample output from pt-duplicate-key-checker
:
# IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_ENTITY_ID is a left-prefix of UNQ_CAT_PRD_ENTT_DEC_ENTT_ID_ATTR_ID_STORE_ID
# Key definitions:
# KEY `IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_ENTITY_ID` (`entity_id`),
# UNIQUE KEY `UNQ_CAT_PRD_ENTT_DEC_ENTT_ID_ATTR_ID_STORE_ID` (`entity_id`,`attribute_id`,`store_id`),
# Column types:
# `entity_id` int(10) unsigned not null default 0 comment 'entity id'
# `attribute_id` smallint(5) unsigned not null default 0 comment 'attribute id'
# `store_id` smallint(5) unsigned not null default 0 comment 'store id'
# To remove this duplicate index, execute:
ALTER TABLE `catalog_product_entity_decimal` DROP INDEX `IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_ENTITY_ID`;
There are dozens of these recommendations. One discussion point is that most apply to InnoDB and not MyISAM.