Optimizing
SELECT
Statements
683
and converts it to this expression:
EXISTS (SELECT 1 FROM ... WHERE
subquery_where
AND trigcond(
oe_1
=
ie_1
)
AND ...
AND trigcond(
oe_N
=
ie_N
)
)
Each
trigcond(X)
is a special function that evaluates to the following values:
•
X
when the “linked” outer expression
oe_i
is not
NULL
•
TRUE
when the “linked” outer expression
oe_i
is
NULL
Note that trigger functions are not triggers of the kind that you create with
CREATE TRIGGER
.
Equalities that are wrapped into
trigcond()
functions are not first class predicates for the query
optimizer. Most optimizations cannot deal with predicates that may be turned on and off at query
execution time, so they assume any
trigcond(X)
to be an unknown function and ignore it. At the
moment, triggered equalities can be used by those optimizations:
• Reference optimizations:
trigcond(X=Y [OR Y IS NULL])
can be used to construct
ref
[646]
,
eq_ref
[646]
, or
ref_or_null
[647]
table accesses.
• Index lookup-based subquery execution engines:
trigcond(X=Y)
can be used to construct
unique_subquery
[647]
or
index_subquery
[647]
accesses.
• Table-condition generator: If the subquery is a join of several tables, the triggered condition will be
checked as soon as possible.
When the optimizer uses a triggered condition to create some kind of index lookup-based access
(as for the first two items of the preceding list), it must have a fallback strategy for the case when the
condition is turned off. This fallback strategy is always the same: Do a full table scan. In
EXPLAIN
output, the fallback shows up as
Full scan on NULL key
in the
Extra
column:
mysql>
EXPLAIN SELECT t1.col1,
->
t1.col1 IN (SELECT t2.key1 FROM t2 WHERE t2.col2=t1.col2) FROM t1\G
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: t1
...
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: t2
type: index_subquery
possible_keys: key1
key: key1
key_len: 5
ref: func
rows: 2
Extra: Using where; Full scan on NULL key
If you run
EXPLAIN EXTENDED
followed by
SHOW WARNINGS
, you can see the triggered condition:
*************************** 1. row ***************************
Level: Note
Code: 1003
Message: select `test`.`t1`.`col1` AS `col1`,
<in_optimizer>(`test`.`t1`.`col1`,
<exists>(<index_lookup>(<cache>(`test`.`t1`.`col1`) in t2
on key1 checking NULL
where (`test`.`t2`.`col2` = `test`.`t1`.`col2`) having
trigcond(<is_not_null_test>(`test`.`t2`.`key1`))))) AS
`t1.col1 IN (select t2.key1 from t2 where t2.col2=t1.col2)`
from `test`.`t1`
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...