I'm currently studying DB index
. In the MySQL classicmodels db
, I don't know why does this query use full index scan.
select salesRepEmployeeNumber, count(*)
from customers
where creditLimit > 100000
group by salesRepEmployeeNumber;
The customers table has clustered index on customerNumber and Non-clustered index on salesRepEmployeeNumber . From what I learned, there is a <key, key of clustered index>
in the data entry of the non-clustered tree. Isn't the creditLimit column
that exists in the WHERE
clause information that can only be known by accessing the data record? If so, shouldn't MySQL query optimizer use full table scan
not full index scan
? B tree clustered index B tree Non-clustered index Query Execution Plan
如果您在(credit limit, salesRepEmployeeNumber)
上定义了索引,则可以仅从索引完成此查询,而无需触及数据页面。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.