Continue the part of execution plan that was not completed last time
6. The possible indexes used by possible keys. This understanding indicates the possible indexes used in query. It may be used, but not necessarily. If it is empty, there must be no relevant index. But if there is value, it may not be used.
7. Index actually used by key.
Let's look at the following examples:
mysql> explain select * from `order` where seller_id = 19; +----+-------------+-------+------------+------+------------------+------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+------------------+------+---------+------+------+----------+-------------+ | 1 | SIMPLE | order | NULL | ALL | business,seller_id | NULL | NULL | NULL | 2197 | 100.00 | Using where | +----+-------------+-------+------------+------+------------------+------+---------+------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec) mysql> explain select * from `order` where customer_id = 55029; +----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-------+ | 1 | SIMPLE | order | NULL | ref | customer_id | customer_id | 8 | const | 10 | 100.00 | NULL | +----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-------+ 1 row in set, 1 warning (0.00 sec)
For the first sql, the result of the possible key here is that it is possible to walk the index on the seller's ID, but the actual key is NULL. As mentioned before, because there is only one seller, although there is an index, Innodb selects full table scanning, which is the result of CBO based selection. Let's delete the index on the seller'id now to see how it works.
mysql> explain select * from `order` where seller_id = 19; +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+ | 1 | SIMPLE | order | NULL | ALL | business | NULL | NULL | NULL | 2197 | 100.00 | Using where | +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec)
It can be seen that the whole table has been scanned.
The second is that the result of the possible keys in sql is the seller's ID, which means that the index is effective.
8. Length of index field used by key
Note: key [len] is defined to indicate the maximum possible length of index field, not the actual length used.
Once stepped on a pit, because the index length was not actively defined when the index was created, the index length of the field with the result length of 20 was only 4. Then the index doesn't work, causing the database to avalanche. So it's best to form a habit of adding length when defining index.
9.ref shows which field or constant is used with key
If the constant equivalent query is used, const will be displayed here
If it is a connection query, the execution plan of the driven table will display the associated fields of the driven table
If the condition uses an expression or function, or the condition column is implicitly converted internally, it may be displayed as func
If no index is used, NULL will be displayed here
10. Number of rows scanned by row
This number indicates how much data mysql needs to traverse to find. It is based on statistics and may not be very accurate
11.filtered percentage
An estimate of the percentage of records for the condition (here is a pessimistic estimate, the maximum), which is the percentage of rows that mysql will filter.
12.Extra information
Using index: indicates to overwrite the index. Only querying the index value can meet the requirements of sql.
mysql> explain select customer_id from `order` where customer_id = 55029; +----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-------------+ | 1 | SIMPLE | order | NULL | ref | customer_id | customer_id | 8 | const | 10 | 100.00 | Using index | +----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec)
Using where: indicates a conditional query, that is, a simple index cannot satisfy all the required columns.
Write down these simple understandings for the time being. If there is anything wrong, please correct it.