Database - Index Tuning - analysis of the implementation plan

  1. The most basic sql analysis --- select * from itdragon_order_list where transaction_id = "81X97310V32236260E";
mysql> select * from itdragon_order_list where transaction_id = "81X97310V32236260E";
+-------+--------------------+-------+------+----------+--------------+----------+------------------+-------------+-------------+------------+---------------------+
| id    | transaction_id     | gross | net  | stock_id | order_status | descript | finance_descript | create_type | order_level | input_user | input_date          |
+-------+--------------------+-------+------+----------+--------------+----------+------------------+-------------+-------------+------------+---------------------+
| 10000 | 81X97310V32236260E |   6.6 | 6.13 |        1 |           10 | ok       | ok               | auto        |           1 | itdragon   | 2017-08-18 17:01:49 |
+-------+--------------------+-------+------+----------+--------------+----------+------------------+-------------+-------------+------------+---------------------+

mysql> explain select * from itdragon_order_list where transaction_id = "81X97310V32236260E";
+----+-------------+---------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table               | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+---------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | itdragon_order_list | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    3 |    33.33 | Using where |
+----+-------------+---------------------+------------+------+---------------+------+---------+------+------+----------+-------------+

Several important parameters

  • select_type: type of query is a simple query, simple select statement and no union sub-queries.
  • type: the type of connection, all by way of showing a full table scan.

type-- This is a very important parameter, connection type, common are: all, index, range, ref, eq_ref, const, system, null eight levels. The performance of the worst sort from best to: system> const> eq_ref> ref> range> index> all.

  • possible_keys: use the index may be null.
  • key: actually used index is null.
  • key_len: index length of course null.
  • ref: no columns or parameters and key are used together.
  • Extra: Use of where the query.
  1. To index transaction_id

mysql> create unique index idx_order_transaID on itdragon_order_list (transaction_id);
mysql> explain select * from itdragon_order_list where transaction_id = "81X97310V32236260E";
+----+-------------+---------------------+------------+-------+--------------------+--------------------+---------+-------+------+----------+-------+
| id | select_type | table               | partitions | type  | possible_keys      | key                | key_len | ref   | rows | filtered | Extra |
+----+-------------+---------------------+------------+-------+--------------------+--------------------+---------+-------+------+----------+-------+
|  1 | SIMPLE      | itdragon_order_list | NULL       | const | idx_order_transaID | idx_order_transaID | 453     | const |    1 |      100 | NULL  |
+----+-------------+---------------------+------------+-------+--------------------+--------------------+---------+-------+------+----------+-------+
  • type print a unique index value is const. Representation can be found through the index once. That ended a scan to find the value of return query results.
  • Type value general index print is ref. It represents a non-unique index scan. Find the value will continue to scan, index file is scanned until the last.
    Obviously constx better performance than ref

Reproduced in: https: //www.jianshu.com/p/2dc9052e9189

Guess you like

Origin blog.csdn.net/weixin_34259159/article/details/91079277