一、Explain 使用 EXPLAIN + SQL语句 EXPLAIN SELECT * FROM mk_***_ad_day_main WHERE `ad_id` = '1694**26445' and `stat_datetime` = '2021-08-13 00:00:00'; 二、参数解释 1、id 优先级和先后顺序 id越大的优先级高,优先级高的先执行 id相同,执行顺序由上到下 2、select_type 查询的类型 普通查询:simple 子查询: primary:存在子查询时,最外层查询select subquery:子查询中第一个select dependent subquery:子查询中第一个select,依赖于外部子查询 联表: union:union中的第二个或后面的select dependent union: union中的第二个或后面的select,依赖于外部子查询 派生表:derived 3、table 查询引用的表名 4、type 联接类型 all:全表扫描 ref:匹配索引值 eq_ref:是唯一索引匹配 const:最多有一个匹配行 range:检索给定范围 index:只扫描索引树,比ALL略快 index_merge:使用了索引合并优化方法 index_subquery:索引子查询 unique_subquery:唯一索引子查询 5、possible_keys "可能"使用的索引 6、key 实际使用索引 7、key_len 使用索引长度 8、ref 使用的字段或者常量 9、rows 实际扫描行数 10、extra 详细描述 Distinct:匹配到第一行后停止 Not exists:匹配第一个LEFT JOIN查询后停止 range checked for each record (index map: #):没有找到合适的索引 using filesort:额外的排序 Using index:使用索引树查询 Using index condition:先条件过滤索引,再匹配查询过滤 Using where:使用了where Using temporary:使用了临时表