索引条件下推优化,先附上MySQL 官网解释:
Index Condition Pushdown (ICP) is an optimization for the case where MySQL retrieves rows from a table using an index. Without ICP, the storage engine traverses the index to locate rows in the base table and returns them to the MySQL server which evaluates the WHERE
condition for the rows. With ICP enabled, and if parts of the WHERE
condition can be evaluated by using only fields from the index, the MySQL server pushes this part of the WHERE
condition down to the storage engine. The storage engine then evaluates the pushed index condition by using the index entry and only if this is satisfied is the row read from the table. ICP can reduce the number of times the storage engine must access the base table and the number of times the MySQL server must access the storage engine.
Index Condition Pushdown optimization is used for the range
, ref
, eq_ref
, and ref_or_null
access methods when there is a need to access full table rows. This strategy can be used for InnoDB
and MyISAM
tables. (Note that index condition pushdown is not supported with partitioned tables in MySQL 5.6; this issue is resolved in MySQL 5.7.) For InnoDB
tables, however, ICP is used only for secondary indexes. The goal of ICP is to reduce the number of full-record reads and thereby reduce IO operations. For InnoDB
clustered indexes, the complete record is already read into the InnoDB
buffer. Using ICP in this case does not reduce IO.
简单理解是:开启icp优化功能,可以通过索引定位数据,不需要扫描整个表,返回最终结果给MySQL server再到用户;关闭icp优化功能,通过索引定位数据并扫面整个表,返回结果给MySQL server 然后通过where 条件过滤结果,返回最终结果给用户.
可参考一片图文并茂的文章:http://lihx8.lofter.com/post/1cc9bc99_7da03fe