MySQL查询优化概念辨析---Using where 和 Using index
2017-03-13 19:03
246 查看
MySQL的查询执行计划中,Extra列经常会出现“Using where; Using index”。
MySQL官方手册解释:
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 where
A WHERE clause is used to restrict which rows to match against the next table or send to the client. Unless you specifically intend to fetch or examine all rows from the table, you may have something wrong in your query if the Extra value is not Using where and the table join type is ALL or index.
这表明:
Using index不读数据文件,只从索引文件获取数据
Using where过滤元组和是否读取数据文件或索引文件没有关系
但MySQL手册在Using index处又说:
If the Extra column also says Using where, it means the index is being used to perform lookups of key values. Without Using where, the optimizer may be reading the index to avoid reading data rows but not using it for lookups. For example, if the index is a covering index for the query, the optimizer may scan it without using it for lookups.
所以有朋友如此理解:
1 没有Using where只有Using index:则不读数据文件,所有字段都可以从索引上获得(Without Using where, the optimizer may be reading the index to avoid reading data rows but not using it for lookups)
2 同时有Using where和Using index:因为“Without Using where...”这句上下文,则意味着同时有Using where和Using index则一定需要读取数据文件
其实不然。“Using where只是过滤元组,和是否读取数据文件或索引文件没有关系”。
.
MySQL官方手册解释:
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 where
A WHERE clause is used to restrict which rows to match against the next table or send to the client. Unless you specifically intend to fetch or examine all rows from the table, you may have something wrong in your query if the Extra value is not Using where and the table join type is ALL or index.
这表明:
Using index不读数据文件,只从索引文件获取数据
Using where过滤元组和是否读取数据文件或索引文件没有关系
但MySQL手册在Using index处又说:
If the Extra column also says Using where, it means the index is being used to perform lookups of key values. Without Using where, the optimizer may be reading the index to avoid reading data rows but not using it for lookups. For example, if the index is a covering index for the query, the optimizer may scan it without using it for lookups.
所以有朋友如此理解:
1 没有Using where只有Using index:则不读数据文件,所有字段都可以从索引上获得(Without Using where, the optimizer may be reading the index to avoid reading data rows but not using it for lookups)
2 同时有Using where和Using index:因为“Without Using where...”这句上下文,则意味着同时有Using where和Using index则一定需要读取数据文件
其实不然。“Using where只是过滤元组,和是否读取数据文件或索引文件没有关系”。
.
相关文章推荐
- MySQL物理查询优化技术---index dive辨析
- MySQL子查询---EXISTS优化策略辨析
- MySQL查询优化系列讲座之查询优化器
- 使用连接(JOIN)来代替子查询(Sub-Queries) mysql优化系列记录
- 优化 MySQL 查询的 Limit 参数
- MySQL查询优化技术讲座
- MySQL查询优化系列讲座之调度和锁定 选择自 arcow 的 Blog
- MySQL查询优化程序
- MySQL查询优化系列讲座之查询优化器
- MySQL查询优化系列讲座之调度和锁定
- MySQL查询的性能优化
- MySQL查询优化技术讲座
- MySQL查询优化技术系列讲座之使用索引
- MySQL查询优化讲座之管理员的优化措施
- 优化 MySQL 查询的 Limit 参数
- MySQL查询优化程序
- [转]MySQL查询优化技术讲座
- MySQL查询优化讲座之管理员的优化措施
- MySQL 查询中的分页思路的优化