Pt-duplicate-key-checker Check the database for duplicate indexes

Source: Internet
Author: User
Pt-duplicate-key-checker is also a very useful tool in Percona-toolkit to help you detect duplicate indexes or primary keys in a table. We know that indexes can be more useful than queries, but too much indexing can degrade the performance of the database, and this tool can help us find duplicate indexes and give you suggestions for deleting duplicate indexes.

First look at the index structure of my table
Mysql> show indexes from Curs;
[SQL]  View Plain  copy +-------+------------+----------+--------------+-------------+-----------+----------- --+----------+--------+------+------------+---------+---------------+   | table | non_ unique | key_name | seq_in_index | column_name | collation |  Cardinality | Sub_part | Packed | Null | Index_type |  comment | index_comment |   +-------+------------+----------+--------------+---------- ---+-----------+-------------+----------+--------+------+------------+---------+---------------+   |  curs  |          0 | PRIMARY   |            1 | id           | A          |           1 |     null |  null   |      | btree      |          |                |   | curs  |           1 | name     |             1 | name        | a          |            1 |     NULL | NULL   |       | BTREE      |          |               |   | curs   |          1 | age       |            1 | age          | A          |           1 |      NULL | NULL   |      | BTREE       |         |                |   | curs  |           1 | name_age |             1 | name        | a          |           1  |     null | null   |      |  BTREE      |         |                |   | curs   |          1 | name_age |             2 | age          | A         |            1 |     NULL |  Null   |      | btree      |          |                |   | curs  |          1  | age_name |            1 |  age         | A          |           1 |      null | null   |      | btree       |         |                |   | curs  |           1 | age_name |             2 | name        | A          |           1  |     NULL | NULL   |       | btree      |         |                |   |  curs  |          1 | name_1    |            1 | name         | A         |            1 |     null | null    |      | BTREE      |          |                |   | curs  |           1 | age_1    |             1 | age         | A          |           1  |     null | null   |      |  BTREE      |         |                |   +-------+------------+------ ----+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+- --------------+  
There are a lot of duplicate indexes, such as name and Name_age repetition, and Name_1 Repeat, these 3 indexes are the same index. See below how to use/usr/local/bin/pt-duplicate-key-checker to check for duplicate indexes.

[Root@localhost ~]#/usr/local/bin/pt-duplicate-key-checker--host=192.168.1.106--user= ' mysql '--password= ' 123456 ' --databases=test--tables=curs
[SQL]  View Plain  copy # ########################################################################    # test.curs                                                                     # ############# ###########################################################      # name is a  left-prefix of name_age   # key definitions:   #    key  ' name '   (' name '),   #   key  ' name_age '   (' name ', ' age '),    # column types:   #          ' name '   varchar (1)  not null default  '    #          ' Age '  smallint (3)  unsigned not null default  ' 0 '    # 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.