Oracle 5.0 Reference Manual page 685

Table of Contents

Advertisement

OR (t1.a=t2.a AND t2.a IS NULL AND ...);
ref_or_null
rows with a
NULL
Note that the optimization can handle only one
uses key lookups only on the expression
the key part on b:
SELECT * FROM t1, t2
WHERE (t1.a=t2.a AND t2.a IS NULL)
OR (t1.b=t2.b AND t2.b IS NULL);
8.3.1.7.
LEFT JOIN
MySQL implements an
• Table
is set to depend on table
B
• Table
is set to depend on all tables (except B) that are used in the
A
• The
LEFT JOIN
condition in the
• All standard join optimizations are performed, with the exception that a table is always read after all
tables on which it depends. If there is a circular dependence, MySQL issues an error.
• All standard
• If there is a row in
condition, an extra
• If you use
col_name IS NULL
NULL, MySQL stops searching for more rows (for a particular key combination) after it has found one
row that matches the
The implementation of
reversed.
The join optimizer calculates the order in which tables should be joined. The table read order forced by
LEFT JOIN
are fewer table permutations to check. Note that this means that if you do a query of the following type,
MySQL does a full scan on
SELECT *
FROM a JOIN b LEFT JOIN c ON (c.key=a.key) LEFT JOIN d ON (d.key=a.key)
WHERE b.key=d.key;
The fix in this case is reverse the order in which
SELECT *
FROM b JOIN a LEFT JOIN c ON (c.key=a.key) LEFT JOIN d ON (d.key=a.key)
WHERE b.key=d.key;
For a
LEFT
is changed to a normal join. For example, the
t2.column1
SELECT * FROM t1 LEFT JOIN t2 ON (column1) WHERE t2.column2=5;
Therefore, it is safe to convert the query to a normal join:
Optimizing
[647]
works by first doing a read on the reference key, and then a separate search for
key value.
and
RIGHT JOIN
A LEFT JOIN B join_condition
condition is used to decide how to retrieve rows from table B. (In other words, any
clause is not used.)
WHERE
optimizations are performed.
WHERE
that matches the
A
row is generated with all columns set to NULL.
B
to find rows that do not exist in some table and you have the following test:
LEFT JOIN
in the
WHERE
LEFT JOIN
RIGHT JOIN
or
helps the join optimizer do its work much more quickly, because there
STRAIGHT_JOIN
because the
b
JOIN, if the
condition is always false for the generated
WHERE
were NULL:
Statements
SELECT
[877]
IS NULL
(t1.a=t2.a AND t2.a IS NULL)
Optimization
and all tables on which
A
clause, but there is no row in
WHERE
part, where
col_name
condition.
is analogous to that of
forces it to be read before d:
LEFT JOIN
and
are listed in the
a
b
clause would be false in the following query if
WHERE
665
level. In the following query, MySQL
and is not able to use
as follows:
depends.
A
LEFT JOIN
that matches the
B
is a column that is declared as
with the roles of the tables
LEFT JOIN
clause:
FROM
row, the
NULL
condition.
ON
NOT
LEFT JOIN

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents