mysql> explain extended select * from film where rating > 9\G *** 1. row *** id: 1 select_type: SIMPLE table: film type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1024 filtered: 100.00 Extra: Using where 1 row in set, 1 warning (0.00 sec) type = ind...
对于一条查询sql来说,不同的查询类型虽然结果可能是一样的,但是其性能却可能天差地别。不同类型性能从强到差:system > const > eq_ref > ref > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > all。建议大家在平时书写sql时,多用explain进行分析,尝试去优化代码,...
mysql> explain select b.*, a.* from payment a ,customer b where a.customer_id = b.customer_id\G *** 1. row *** id: 1 select_type: SIMPLE table: b type: ALL possible_keys: PRIMARY key: NULL key_len: NULL ref: NULL rows: 541 Extra: *** 2. row *** id: 1 select_type...
Explain被称为执行计划,在语句之前增加 explain 关键字,MySQL会在查询上设置一个标记,模拟MySQL优化器来执行SQL语句,执行查询时,会返回执行计划的信息,并不执行这条SQL。(注意,如果 from 中包含子查询,仍会执行该子查询,将结果放入临时表中)。 Explain可以用来分析SQL语句和表结构的性能瓶颈。通过explain的结果,可以...
2、explain每列信息 2.1 id id表示sql语句的执行顺序,id相等时,按照顺序执行,当id不同时,id越大,sql越先执行 2.2select_type (1)SIMPLE:简单查询 查询不包含子查询和union。 (2)PRIMARY:复制的查询中最外层的select查询 (3)SUBQUERY: 包含在select中的子查询(不在from子句)。
MySQL explain type详解 type类型从快到慢:system > const > eq_ref > ref > range > index > ALL system 表中只有一行记录(系统表)。是const类型的一个特殊情况。(目前InnoDB已经没有,在MyISAM可以) const 表中最多只有一行匹配的记录。一般用在主键索引或者唯一键索引上的等值查询(如果是多字段索引,则...
Explain命令中的type列,显示MySQL查询所使用的关联类型(Join Types)或者访问类型,它表明MySQL决定如何查找表中符合条件的行。 常见访问类型性能由最差到最优依次为: ALL < index < range <index_subquery< unique_subquery < index_merge < ref_or_null < fulltext < ref < eq_ref < const < system。
EXPLAIN 结果中的type)字段 Tips:常见的扫描方式 system:系统表,少量数据,往往不需要进行磁盘IO const:常量连接 eq_ref:主键索引(primary key)或者非空唯一索引(unique not null)等值扫描 ref:非主键非唯一索引等值扫描 range:范围扫描 index:索引树扫描
ref: NULL rows: 1024 Extra: Using index 1 row in set (0.00 sec) type = range ,索引范围扫描,常见于<、<=、>、>=、between等操作符(因为customer_id是索引,所以只要查找索引的某个范围即可,通过索引找到具体的数据) mysql> explain select * from payment where customer_id > 300 and customer_id ...