View execution time
1 show profiles;
2 show variables; check whether profiling is on;
3 if it is off, set profiling = 1;
4 execute your own sql statement;
5 show profiles; you can check the execution time of the sql statement;
See how many rows have been manipulated
Just add explain in front of the sql statement;
explain select * from event;
+—-+————-+——-+——+—————+——+———+——+——+——-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+——-+——+—————+——+———+——+——+——-+
| 1 | SIMPLE | event | ALL | NULL | NULL | NULL | NULL | 13 | |
+—-+————-+——-+——+—————+——+———+——+——+——-+
1 row in set (0.00 sec)
The meaning of each attribute
id
the serial number of the select query
select_type
The type of select query mainly distinguishes between ordinary queries and complex queries such as union queries and sub-queries.
table
The table referenced by the output row.
type
The type used by the union query.
type shows the access type, which is a more important indicator. The result values from good to bad are:
system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL
Generally speaking, it is necessary to ensure that the query reaches at least the range level, preferably ref.
possible_keys
Indicates which index MySQL can use to find rows in this table. If empty, there is no associated index. To improve performance at this time, you can check the WHERE clause to see if some fields are referenced, or check that the fields are not suitable for indexing.
key
Displays the key that MySQL actually decided to use. If no index is selected, the key is NULL.
key_len
Displays the key length that MySQL decided to use. If the key is NULL, the length is NULL. The documentation suggests paying special attention to this value to figure out which part of a multiple primary key is actually used by MySQL.
ref
Shows which field or constant is used with key.
rows
This number indicates how much data mysql has to traverse to find it, which is inaccurate on innodb.
Extra
In the case of an only index, this means that information is retrieved using only the information in the index tree, which is faster than scanning the entire table.
If it is where used, it is using where restrictions.
If it is impossible where, it means that there is no need for where, and generally nothing is found.