MySQL索引下推技术
2016-03-10 15:19
579 查看
索引下推整个思路如下:
To see how this optimization works, consider first how an index scan proceeds when Index Condition Pushdown is not used:
Get the next row, first by reading the index tuple, and then by using the index tuple to locate and read the full table row.
Test the part of the
When Index Condition Pushdown is used, the scan proceeds like this instead:
Get the next row's index tuple (but not the full table row).
Test the part of the
If the condition is satisfied, use the index tuple to locate and read the full table row.
Test the remaining part of the
举例如下:
Suppose that we have a table containing information about people and their addresses and that the table has an index defined as
people表中(zipcode,lastname,firstname)构成一个索引。
如果没有使用索引下推技术,则MySQL会通过zipcode='95054'从存储引擎中查询对应的元祖,返回到MySQL服务端,然后MySQL服务端基于lastname LIKE '%etrunia%'和
address LIKE '%Main Street%'来判断元祖是否符合条件。
如果使用了索引下推技术,则MYSQL首先会返回符合zipcode='95054'的索引,然后根据lastname LIKE '%etrunia%'和address LIKE '%Main Street%'来判断索引是否符合
条件。如果符合条件,则根据该索引来定位对应的元祖,如果不符合,则直接reject掉。
To see how this optimization works, consider first how an index scan proceeds when Index Condition Pushdown is not used:
Get the next row, first by reading the index tuple, and then by using the index tuple to locate and read the full table row.
Test the part of the
WHEREcondition that applies to this table. Accept or reject the row based on the test result.
When Index Condition Pushdown is used, the scan proceeds like this instead:
Get the next row's index tuple (but not the full table row).
Test the part of the
WHEREcondition that applies to this table and can be checked using only index columns. If the condition is not satisfied, proceed to the index tuple for the next row.
If the condition is satisfied, use the index tuple to locate and read the full table row.
Test the remaining part of the
WHEREcondition that applies to this table. Accept or reject the row based on the test result.
举例如下:
Suppose that we have a table containing information about people and their addresses and that the table has an index defined as
INDEX (zipcode, lastname, firstname). If we know a person's
zipcodevalue but are not sure about the last name, we can search like this:
SELECT * FROM people WHERE zipcode='95054' AND lastname LIKE '%etrunia%' AND address LIKE '%Main Street%';
people表中(zipcode,lastname,firstname)构成一个索引。
如果没有使用索引下推技术,则MySQL会通过zipcode='95054'从存储引擎中查询对应的元祖,返回到MySQL服务端,然后MySQL服务端基于lastname LIKE '%etrunia%'和
address LIKE '%Main Street%'来判断元祖是否符合条件。
如果使用了索引下推技术,则MYSQL首先会返回符合zipcode='95054'的索引,然后根据lastname LIKE '%etrunia%'和address LIKE '%Main Street%'来判断索引是否符合
条件。如果符合条件,则根据该索引来定位对应的元祖,如果不符合,则直接reject掉。
相关文章推荐
- MySQL参数
- MyCAT实现MySQL的读写分离
- MySQL的分页优化
- 利用Shell脚本将MySQL表中的数据转化为json格式
- 恢复MySQL主从数据一致性的总结
- 基于表的数据字典构造MySQL建表语句
- MySQL存储过程及触发器
- MySQL分区总结
- MySQL基于时间字段进行分区的方案总结
- MySQL中有关TIMESTAMP和DATETIME的总结
- MySQL复合分区
- MySQL分区表的管理~2
- MySQL分区表的管理~1
- mysql开启慢查询
- MySQL表中数据的迁移
- mysql启动服务时提示"服务名无效"
- MySQL 5.7 for Windows 解压缩版配置安装
- Mysql分表和分区的区别
- 解决MySQL忘记密码问题的方法
- MySql查询优化 百万级记录查询优化 limit分页查询