This optimization improves the efficiency of direct comparisons between a nonindexed column and a constant. 这种优化提高了非索引列和常量之间直接比较的效率。In such cases, the condition is “pushed down” to the storage engine for evaluation. 在这种情况下,条件被“下推”到存储引擎进行评估。This optimization can be used only by the 此优化只能由NDB
storage engine.NDB
存储引擎使用。
For NDB Cluster, this optimization can eliminate the need to send nonmatching rows over the network between the cluster's data nodes and the MySQL server that issued the query, and can speed up queries where it is used by a factor of 5 to 10 times over cases where condition pushdown could be but is not used.对于NDB集群,这种优化可以消除在集群的数据节点和发出查询的MySQL服务器之间通过网络发送不匹配行的需要,并且可以在使用条件下推的情况下将查询速度提高5到10倍。
Suppose that an NDB Cluster table is defined as follows:假设NDB集群表定义如下:
CREATE TABLE t1 ( a INT, b INT, KEY(a) ) ENGINE=NDB;
Engine condition pushdown can be used with queries such as the one shown here, which includes a comparison between a nonindexed column and a constant:引擎条件下推可用于此处所示的查询,其中包括非索引列和常量之间的比较:
SELECT a, b FROM t1 WHERE b = 10;
The use of engine condition pushdown can be seen in the output of 引擎条件下推的使用可以在EXPLAIN
:EXPLAIN
的输出中看到:
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, engine condition pushdown cannot be used with the following query:但是,引擎条件下推不能用于以下查询:
SELECT a,b FROM t1 WHERE a = 10;
Engine condition pushdown is not applicable here because an index exists on column 引擎条件下推不适用于此处,因为a
. a
列上存在索引。(An index access method would be more efficient and so would be chosen in preference to condition pushdown.)(索引访问方法将更有效,因此将优先选择条件下推。)
Engine 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 supported comparisons for engine 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 12.8.1, “String Comparison Functions and Operators”.pattern
必须是包含要匹配的模式的字符串文字;有关语法,请参阅第12.8.1节,“字符串比较函数和运算符”。
column
IS [NOT] NULL
column
IN (value_list
)
Each item in the value_list
must be a constant, literal value.value_list
中的每个项都必须是常量、文字值。
column
BETWEEN constant1
AND constant2
constant1
and constant2
must each be a constant, literal value.constant1
和constant2
必须分别为常量和文字值。
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.在上述列表中的所有情况下,条件都可以转换为列和常量之间的一个或多个直接比较形式。
Engine condition pushdown is enabled by default. 默认情况下启用“引擎条件下推”。To disable it at server startup, set the 要在服务器启动时禁用它,请将optimizer_switch
system variable's engine_condition_pushdown
flag to off
. optimizer_switch
系统变量的engine_condition_pushdown
标志设置为off
。For example, in a 例如,在my.cnf
file, use these lines:my.cnf
文件中,使用这些行:
[mysqld] optimizer_switch=engine_condition_pushdown=off
At runtime, disable condition pushdown like this:在运行时,禁用条件下推,如下所示:
SET optimizer_switch='engine_condition_pushdown=off';
Limitations.局限性 Engine condition pushdown is subject to the following limitations:引擎条件下推受到以下限制:
Engine condition pushdown is supported only by the 引擎条件下推仅由NDB
storage engine.NDB
存储引擎支持。
Prior to NDB 8.0.18, columns could be compared with constants or expressions which evaluate to constant values only. 在NDB 8.0.18之前,可以将列与常量或仅计算为常量值的表达式进行比较。In NDB 8.0.18 and later, columns can be compared with one another as long as they are of exactly the same type, including the same signedness, length, character set, precision, and scale, where these are applicable.在NDB 8.0.18及更高版本中,只要列的类型完全相同,包括相同的符号、长度、字符集、精度和比例(如果适用),就可以相互比较。
Columns used in comparisons cannot be of any of the 比较中使用的列不能是任何BLOB
or TEXT
types. BLOB
或TEXT
类型。This exclusion extends to 这种排除也扩展到JSON
, BIT
, and ENUM
columns as well.JSON
、BIT
和ENUM
列。
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 extended 使用扩展的EXPLAIN
output to determine which conditions are actually pushed down. EXPLAIN
输出确定实际按下的条件。See Section 8.8.3, “Extended EXPLAIN Output Format”.请参阅第8.8.3节,“扩展的EXPLAIN输出格式”。
Previously, engine condition pushdown was limited to terms referring to column values from the same table to which the condition was being pushed. 以前,引擎条件下推仅限于引用条件下推到的同一表格中的列值的术语。Beginning with NDB 8.0.16, column values from tables earlier in the query plan can also be referred to from pushed conditions. 从NDB 8.0.16开始,查询计划中前面表中的列值也可以从推式条件中引用。This reduces the number of rows which must be handled by the SQL node during join processing. 这减少了SQL节点在连接处理期间必须处理的行数。Filtering can be also performed in parallel in the LDM threads, rather than in a single mysqld process. 过滤也可以在LDM线程中并行执行,而不是在单个mysqld进程中执行。This has the potential to improve performance of queries by a significant margin.这有可能大大提高查询的性能。
Beginning with NDB 8.0.20, an outer join using a scan can be pushed if there are no unpushable conditions on any table used in the same join nest, or on any table in join nmests above it on which it depends. 从NDB 8.0.20开始,如果在同一联接嵌套中使用的任何表上,或者在其依赖的联接nmests上的任何表上,没有不可推送的条件,则可以推送使用扫描的外部联接。This is also true for a semijoin, provided the optimization strategy employed is 如果采用的优化策略是firstMatch
(see Section 8.2.2.1, “Optimizing IN and EXISTS Subquery Predicates with Semijoin Transformations”).firstMatch
(请参阅第8.2.2.1节,“使用半联接转换优化IN和EXISTS子查询谓词”),则半联接也是如此。
Join algorithms cannot be combined with referring columns from previous tables in the following two situations:在以下两种情况下,联接算法不能与前面表中的引用列组合使用:
When any of the referred previous tables are in a join buffer. 当前面引用的任何表位于联接缓冲区中时。In this case, each row retrieved from the scan-filtered table is matched against every row in the buffer. 在这种情况下,从扫描筛选表检索到的每一行都与缓冲区中的每一行相匹配。This means that there is no single specific row from which column values can be fetched from when generating the scan filter.这意味着,在生成扫描筛选器时,不存在可从中获取列值的单个特定行。
When the column originates from a child operation in a pushed join. 当列源自推式联接中的子操作时。This is because rows referenced from ancestor operations in the join have not yet been retrieved when the scan filter is generated.这是因为在生成扫描筛选器时,尚未检索从联接中的祖先操作引用的行。