Oracle 5.0 Reference Manual page 701

Table of Contents

Advertisement

The conversion just described has its limitations. It is valid only if we ignore possible
is, the "pushdown" strategy works as long as both of these two conditions are true:
and
outer_expr
inner_expr
• You do not need to distinguish
[881]
or
[880]
OR
AND
When either or both of those conditions do not hold, optimization is more complex.
Suppose that
outer_expr
such that
outer_expr
• NULL, if the
SELECT
• FALSE, if the
SELECT
In this situation, the approach of looking for rows with
It is necessary to look for such rows, but if none are found, also look for rows where
NULL. Roughly speaking, the subquery can be converted to:
EXISTS (SELECT 1 FROM ... WHERE
(outer_expr=inner_expr
The need to evaluate the extra
[647]
access method:
ref_or_null
mysql>
EXPLAIN
->
SELECT outer_expr IN (SELECT t2.maybe_null_key
->
-> FROM t1;
*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: t1
...
*************************** 2. row ***************************
id: 2
select_type: DEPENDENT SUBQUERY
table: t2
type: ref_or_null
possible_keys: maybe_null_key
key: maybe_null_key
key_len: 5
ref: func
rows: 2
Extra: Using where; Using index
...
The
unique_subquery
have or-null variants. However, they are not visible in
followed by
EXTENDED
mysql>
EXPLAIN EXTENDED
->
SELECT outer_expr IN (SELECT maybe_null_key FROM t2) 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: maybe_null_key
key: maybe_null_key
key_len: 5
Optimizing
SELECT
cannot be NULL.
from
NULL
FALSE
expression in the
WHERE
is known to be a
non-NULL
= inner_expr. Then
produces any row where
produces only
non-NULL
subquery_where
OR
inner_expr
[877]
IS NULL
FROM t2, t3 WHERE ...)
[647]
and
index_subquery
(note the
SHOW WARNINGS
681
Statements
subquery results. (If the subquery is a part of an
clause, MySQL assumes that you don't care.)
value but the subquery does not produce a row
outer_expr IN (SELECT ...)
is
inner_expr
NULL
values or produces nothing
outer_expr = inner_expr
AND
IS NULL))
condition is why MySQL has the
[647]
subqery-specific access methods also
output, so you must use
EXPLAIN
checking NULL
values. That
NULL
evaluates as follows:
is no longer valid.
inner_expr
EXPLAIN
in the warning message):
is

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents