[英]Why optimizer use 'ALL' type instead of 'index' type?
I'm currently learning execution plan
in MySql
. 我目前正在学习
MySql
execution plan
。
And I use dump data from here. 我从这里使用转储数据。
https://dev.mysql.com/doc/employee/en/sakila-structure.html
https://dev.mysql.com/doc/employee/zh/sakila-structure.html
I added new index to from_date
field of dept_emp
table, named ix_fromdate
. 我向
dept_emp
表的from_date
字段添加了新索引,名为ix_fromdate
。
And I typed like below 我输入如下
EXPLAIN
SELECT *
FROM dept_emp
WHERE from_date>='1985-01-01'
Execution plain result like below 执行普通结果如下
I understand that rows
value is closer amount of this table rows amount and optimizer didn't use range
index. 我知道
rows
值是该表中行数的更接近值,并且优化器未使用range
索引。
And.. I think, type
should be index
, but ALL
. 我认为
type
应该是index
,但是ALL
。
Why they did table full scan
? 他们为什么要进行
table full scan
?
There's index for ix_fromdate
, why they didn't use it though? 有
ix_fromdate
的索引,为什么他们没有使用它?
I know index full scan
is better than table full scan
... 我知道
index full scan
比table full scan
更好...
Do I know it wrong? 我知道错吗?
INDEX(from_date)
? INDEX(from_date)
? WHERE from_date>='1985-01-01'
? WHERE from_date>='1985-01-01'
吗? Then the Optimizer decides that it is probably faster to simply scan through the data, filtering as it goes. 然后,优化器决定仅扫描数据并进行过滤就可能更快。 The alternative (using the index) could be costly because of bouncing between the index BTree and the data BTree.
替代方法(使用索引)可能会很昂贵,因为索引BTree和数据BTree之间会发生反弹。
Use a newer date; 使用较新的日期; the Optimizer may change its mind and use the index.
优化器可能会改变主意并使用索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.