Index Condition pushdown (ICP) is a optimization for the case where MySQL retrieves rowsFrom a table using a index(ICP is an optimization for MySQL to get data from a table using an index). Without ICP, the storage enginetraverses the index to locate rows in the base tableand returns them to the MySQL server which evaluates theWHERE Condition for the rows (if there is no ICP, the storage engine layer will navigate through the index to locate rows from the base table and return the results to the server layer, and the MySQL server layer will determine which results are qualified and returned to the client based on the Where condition). With ICP enabled, and if parts of theWHERECondition can evaluated by using the-from the index, the MySQL server pushes theWHERECondition down to the storage engine (if an ICP is used, the server layer pushes the where condition to the storage engine layer if it can be obtained according to the field in the index). The storage engine then evaluates the pushed index condition by using the index entry and only if this is the Row read from the table (then storage engine layer). 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 (ICP) reduces the number of times that the storage engine layer must access the base table and the number of times that the server tier must access the storage engine tier.
Index Condition pushdown optimization is used for therange,ref,eq_ref, andref_or_nullAccess methods when there are a need to access full table rows (the ICP is optimized for the need to use the Range,ref,eq_ref and Ref_or_null methods to access the data for all tables). This strategy can is used forInnoDBandMyISAMTables. (Note that the index condition Pushdown isNot supported with partitioned tables in MySQL 5.6; This issue was resolved in MySQL 5.7.) For InnoDB tables, however, ICP is used only for secondary indexes(for InnoDB tables, however, the ICP applies only to level two indexes.)The goal of ICP is to reduce the number of Full-record reads and thereby reduce IO operations(The objective of the ICP is to reduce the number of full-table scans and reduce IO operations). ForInnoDBClustered indexes, the complete record was already read into theInnoDBBuffer. Using ICP In the case does not reduce IO (for InnoDB clustered index, all records are already in buffer pool, so using the ICP in this case does not reduce IO).
Optimization works, consider first how a index scan proceeds when index Condition pushdown are not used:
-
Get the next row, first by reading the index tuple, and then by using the-the index tuple to locate and read the full table ro W.
-
Test the part of the WHERE condition, applies to this table. Accept or reject the row based on the test result.
When Index Condition pushdown was 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 where condition Applies to this table and can is checked using only index columns. If the condition is not a satisfied, proceed to the index of the 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 where condition That's applies to the This table. Accept or reject the row based on the test result.
When Index Condition pushdown was used, the Extra column in EXPLAIN output shows Using index condition . It won't show because that does isn't apply when the full Index only table rows must is read.
Suppose that we had a table containing information about people and their addresses and that the table had an index Defin Ed as INDEX (zipcode, lastname, firstname) . If we know a person's zipcode value but is not sure on the last name, we can search like this:
SELECT * from people WHERE zipcode= ' 95054 ' and LastName like ' %etrunia% ' and address like '%main street% ';
MySQL can use the "Index to scan" through people with zipcode=‘95054‘ . The second part ( lastname LIKE ‘%etrunia%‘ ) cannot is used to limit the number of rows that must is scanned, so without Index Condition Pushdo WN, this query must retrieve full table rows for all the people zipcode=‘95054‘ .
With Index Condition pushdown, MySQL would check the part lastname LIKE ‘%etrunia%‘ before reading the full table row. This avoids reading full rows corresponding to all index tuples, that does not match the lastname condition.
Index Condition pushdown is enabled by default; It can controlled with the optimizer_switch system variable by setting the index_condition_pushdown flag. See section 8.9.2, "Controlling switchable optimizations".
Index Condition pushdown optimization