Index Condition Pushdown is an optimization that is applied for access methods that access table data through indexes: range, ref, eq_ref, ref_or_null, and .
The idea is to check part of the WHERE condition that refers to index fields (we call it Pushed Index Condition) as soon as we've accessed the index. If the Pushed Index Condition is not satisfied, we won't need to read the whole table record.
Index Condition Pushdown is on by default. To disable it, set its optimizer_switch flag like so:
When Index Condition Pushdown is used, EXPLAIN will show "Using index condition":
In disk-based storage engines, making an index lookup is done in two steps, like shown on the picture:
Index Condition Pushdown optimization tries to cut down the number of full record reads by checking whether index records satisfy part of the WHERE condition that can be checked for them:
How much speed will be gained depends on
How many records will be filtered out
How expensive it was to read them
The former depends on the query and the dataset. The latter is generally bigger when table records are on disk and/or are big, especially when they have .
I used DBT-3 benchmark data, with scale factor=1. Since the benchmark defines very few indexes, we've added a multi-column index (index condition pushdown is usually useful with multi-column indexes: the first component(s) is what index access is done for, the subsequent have columns that we read and check conditions on).
The query was to find big (l_quantity > 40) orders that were made in January 1993 that took more than 25 days to ship:
EXPLAIN without Index Condition Pushdown:
with Index Condition Pushdown:
The speedup was:
Cold buffer pool: from 5 min down to 1 min
Hot buffer pool: from 0.19 sec down to 0.07 sec
There are two server status variables:
That way, the value Handler_icp_attempts - Handler_icp_match shows the number records that the server did not have to read because of Index Condition Pushdown.
Currently, virtual column indexes can't be used for index condition pushdown. Instead, a generated column can be made declared STORED. Then, index condition pushdown will be possible.
Index Condition Pushdown can't be used with backward-ordered index scan. When the optimizer needs to execute an ORDER BY ... DESC query which can be handled by using a backward-ordered index scan, it will disable Index Condition Pushdown.
Index condition pushdown support for was added in .
This page is licensed: CC BY-SA / Gnu FDL
SET optimizer_switch='index_condition_pushdown=off'MariaDB [test]> EXPLAIN SELECT * FROM tbl WHERE key_col1 BETWEEN 10 AND 11 AND key_col2 LIKE '%foo%';
+----+-------------+-------+-------+---------------+----------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-----------------------+
| 1 | SIMPLE | tbl | range | key_col1 | key_col1 | 5 | NULL | 2 | Using index condition |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-----------------------+Number of times pushed index condition was checked.
Number of times the condition was matched.


ALTER TABLE lineitem ADD INDEX s_r (l_shipdate, l_receiptdate);SELECT COUNT(*) FROM lineitem
WHERE
l_shipdate BETWEEN '1993-01-01' AND '1993-02-01' AND
datediff(l_receiptdate,l_shipdate) > 25 AND
l_quantity > 40;-+----------+-------+----------------------+-----+---------+------+--------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
-+----------+-------+----------------------+-----+---------+------+--------+-------------+
| lineitem | range | s_r | s_r | 4 | NULL | 152064 | Using where |
-+----------+-------+----------------------+-----+---------+------+--------+-------------+-+-----------+-------+---------------+-----+---------+------+--------+------------------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
-+-----------+-------+---------------+-----+---------+------+--------+------------------------------------+
| lineitem | range | s_r | s_r | 4 | NULL | 152064 | Using index condition; Using where |
-+-----------+-------+---------------+-----+---------+------+--------+------------------------------------+