编程笔记

lifelong learning & practice makes perfect

MySQL8 explain

explain

output

Table 8.1 EXPLAIN Output Columns

Column JSON Name Meaning
id select_id The SELECT identifier
select_type None The SELECT type
table table_name The table for the output row
partitions partitions The matching partitions
type access_type The join type
possible_keys possible_keys The possible indexes to choose
key key The index actually chosen
key_len key_length The length of the chosen key
ref ref The columns compared to the index
rows rows Estimate of rows to be examined
filtered filtered Percentage of rows filtered by table condition
Extra None Additional information

EXPLAIN FORMAT=TREE

显示查询计划和成本估算

1
2
3
4
5
6
7
8
9
explain  format=tree
SELECT *
FROM `order`
WHERE shop_id = xxx and (corp_id = xxx)
ORDER BY create_time DESC
LIMIT 10
--- 输出
-> Limit: 10 row(s) (cost=9379.88 rows=10)
-> Index range scan on order using idx_shopid_corpid_createtime, with index condition: ((`order`.corp_id = xxx) and (`order`.shop_id = xxxx)) (cost=9379.88 rows=13070)

explain analyze

EXPLAIN ANALYZE 是一个用于查询的分析工具,向用户显示 MySQL 在查询上花费的时间以及原因。
它将产生查询计划,并对其进行检测和执行,同时计算行数并度量执行计划中不同点上花费的时间。执行完成后,EXPLAIN ANALYZE 将输出计划和度量结果,而不是查询结果。

reference

欢迎关注我的其它发布渠道