MySQL Performance Tuning (ii) the Index Tuning

First, select the appropriate column index

1. where clause, group by clause, order by clause, on columns (select) clause appears in the
2 index fields as small as possible (page table data will be more, IO will be more efficient)
3. Discrete degree into the joint index column in front of
the SELECT * from Payment staff_id = 2 and the WHERE CUSTOMER_ID = 584;
index (staff_id, CUSTOMER_ID) good? Or index (customer_id, staff_id) good?
Due to the greater dispersion of customer_id (repetition rate is small, more optional), so it should be index (customer_id, staff_id)

 

Second, index maintenance

Redundant indexes refer to the same prefix plurality of column index, or primary key index contains the index in the joint. As follows: key (name, id) is a redundant index
Create Table Test (
ID int Not null Primary Key,
name VARCHAR (10) Not null,
Key (name, ID)
) = Engine InnoDB;
// can remove redundant indexes , to achieve optimal results.

Use pt-duplicate-key-checker to check for duplicate and redundant indexes tool
pt-duplicate-key-checker \
-uroot-\
-p '' \
-H 127.0.0.1

 

Remove unused indexes

Currently mysql has not recorded use of the index, but in PerconMySQL and MariaDB can not use the index to see which table by INDEX_STATISTICS,

But in mysql can only be carried out with the index usage analysis tools pt-index-usage through a slow check log.
Usage-index-Pt \
-uroot--p '' \
MySQL-slow.log

Guess you like

Origin www.cnblogs.com/lovechengyu/p/11490825.html