This optimization improves the efficiency of a direct comparison
between a nonindexed column and a constant. In such cases, the
condition is “pushed down” to the storage engine
for evaluation. In MySQL 5.4, this optimization can
be used only by the MyISAM
storage engine; it
may be implemented for additional storage engines in future
versions of MySQL.
Suppose that a table is defined as follows:
CREATE TABLE t1 ( a INT, b INT, KEY(a) ) ENGINE=MyISAM;
It is not necessary to use an explicit
ENGINE
option to create a
MyISAM
table if this is the default MySQL
storage engine type at the time the table is created;
condition pushdown can still be employed with such a
MyISAM
table.
Condition pushdown can be used with a query against this table such as the query shown here:
SELECT a,b FROM t1 WHERE b = 10;
This can be seen in the output of
EXPLAIN
SELECT
:
mysql> EXPLAIN SELECT a,b FROM t1 WHERE b = 10\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t1
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 10
Extra: Using where with pushed condition
However, condition pushdown cannot be used with either of these two queries:
SELECT a,b FROM t1 WHERE a = 10; SELECT a,b FROM t1 WHERE b + 1 = 10;
With regard to the first of these two queries, condition
pushdown is not applicable because an index exists on column
a
. (An index access method would be more
efficient and so would be chosen in preference to condition
pushdown.) In the case of the second query, condition pushdown
cannot be employed because the comparison involving the
nonindexed column b
is indirect. (However,
condition pushdown could be applied if you were to reduce
b + 1 = 10
to b = 9
in the
WHERE
clause.)
Condition pushdown may also be employed when an indexed column
is compared with a constant using a >
or
<
operator:
mysql> EXPLAIN SELECT a,b FROM t1 WHERE a<2\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t1
type: range
possible_keys: a
key: a
key_len: 5
ref: NULL
rows: 2
Extra: Using where with pushed condition
Other comparisons which are supported for condition pushdown include the following:
column
[NOT] LIKE
pattern
pattern
must be a string
literal containing the pattern to be matched; for syntax,
see Section 11.4.1, “String Comparison Functions”.
column
IS [NOT]
NULL
column
IN
(value_list
)
Each item in the value_list
must be a constant, literal value.
column
BETWEEN
constant1
AND
constant2
constant1
and
constant2
must each be a
constant, literal value.
In all of the cases in the preceding list, it is possible for the condition to be converted into the form of one or more direct comparisons between a column and a constant.
Condition pushdown capability is not used by default. To enable
it, you can start mysqld with the
--engine-condition-pushdown
option, or you can execute either of the following statements at
runtime:
SET engine_condition_pushdown=ON;
SET engine_condition_pushdown=1;
Limitations. Condition pushdown is subject to the following limitations:
In MySQL 5.4, condition pushdown is
supported by the MyISAM
storage
engine only.
Columns may be compared with constants only; however, this includes expressions which evaluate to constant values.
Columns used in comparisons cannot be of any of the
BLOB
or
TEXT
types.
A string value to be compared with a column must use the same collation as the column.
Joins are not directly supported; conditions involving
multiple tables are pushed separately where possible.
Use EXPLAIN
EXTENDED
to determine which conditions are
actually pushed down.
The NDBCLUSTER
storage engine
used by MySQL Cluster also supports condition pushdown;
however, this storage engine is currently not available in
MySQL 5.4. If you are interested in using MySQL
Cluster, see MySQL Cluster NDB 6.X/7.X, which
provides information about MySQL Cluster NDB 6.2 and 6.3,
which are based on MySQL 5.1 but contain the latest
improvements and fixes for
NDBCLUSTER
.
User Comments
Add your own comment.