MySQL 5.4 documentation, on Optimizing Queries with EXPLAIN ,关于这些额外的评论是这样说的:
- Using index
The column information is retrieved from the table using only information in the index tree without having to do an additional seek to read the actual row. This strategy can be used when the query uses only columns that are part of a single index.
[...]
- Using index condition
Tables are read by accessing index tuples and testing them first to determine whether to read full table rows. In this way, index information is used to defer (“push down”) reading full table rows unless it is necessary.
我是否遗漏了什么,或者这两个意思是一样的(即“没有读取行,索引就足够了”)?
最佳答案
举个例子最能说明问题:
SELECT Year, Make --- possibly more fields and/or from extra tables
FROM myUsedCarInventory
WHERE Make = 'Toyota' AND Year > '2006'
Assuming the Available indexes are:
CarId
VIN
Make
Make and Year
此查询将解释为“使用索引”,因为它根本不需要“命中”myUsedCarInventory 表本身,因为“制造和年份”索引“覆盖”了它的需要关于 WHERE 子句中与该表相关的元素。
现在,想象一下,我们保持查询不变,只是在颜色上添加了一个条件
...
WHERE Make = 'Toyota' AND Year > '2006' AND Color = 'Red'
这个查询可能会用“使用索引条件”来解释(“可能”,这里是针对 Toyota + year 估计不够有选择性的情况,优化器可能决定只扫描表)。这意味着 MySQL FIRST 将使用索引来解析 Make + Year,并且它还必须在表中查找相应的行,仅用于 满足 Make + Year 条件的行。这就是有时被称为“push down optimization”的内容。
关于MySQL 解释 : "Using index" vs. "Using index condition",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1687548/