Przyjrzyjmy się tabeli test:
mysql (root@test)> show create table test \G *************************** 1. row *************************** Table: test Create Table: CREATE TABLE `test` ( `c1` int(11) NOT NULL, `c2` varchar(255) DEFAULT NULL, `c3` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`c1`), KEY `idx_c2` (`c2`), KEY `idx_c2_c3` (`c2`,`c3`), KEY `idx_c3_c2` (`c3`,`c2`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec)Przedstawiona tabela ma 'zduplikowany' index idx_c2, bo działa on tak samo jak index idx_c2_c3.
Oprócz podsumowania, skrypt generuje informacje,
- które index-y są do siebie podobne
- o kolumnach na których działają indexy
- zapytanie do usunięcia indexu
Wynik działania skryptu:
∴ bin/pt-duplicate-key-checker -h127.0.0.1 -uroot -proot -P3307 -d test -t test # ######################################################################## # test.test # ######################################################################## # idx_c2 is a left-prefix of idx_c2_c3 # Key definitions: # KEY `idx_c2` (`c2`), # KEY `idx_c2_c3` (`c2`,`c3`), # Column types: # `c2` varchar(255) default null # `c3` timestamp not null default current_timestamp on update current_timestamp # To remove this duplicate index, execute: ALTER TABLE `test`.`test` DROP INDEX `idx_c2`; # ######################################################################## # Summary of indexes # ######################################################################## # Size Duplicate Indexes 3072 # Total Duplicate Indexes 1 # Total Indexes 4
Brak komentarzy:
Prześlij komentarz