Oracle 5.0 Reference Manual page 692

Table of Contents

Advertisement

In this case, MySQL actually uses the following nested-loop schema for the execution of the query with
inner joins:
FOR each row t1 in T1 such that C1(t1) {
FOR each row t2 in T2 such that P1(t1,t2) AND C2(t2)
FOR each row t3 in T3 such that P2(t2,t3) AND C3(t3) {
IF P(t1,t2,t3) {
t:=t1||t2||t3; OUTPUT t;
}
}
}
}
You see that each of the conjuncts C1(T1), C2(T2),
the most outer loop where it can be evaluated. If
pushdown may greatly reduce the number of rows from table
the execution time for the query may improve immensely.
For a query with outer joins, the
the current row from the outer table has a match in the inner tables. Thus, the optimization of pushing
conditions out of the inner nested loops cannot be applied directly to queries with outer joins. Here we
have to introduce conditional pushed-down predicates guarded by the flags that are turned on when a
match has been encountered.
For our example with outer joins with:
P(T1,T2,T3)=C1(T1) AND C(T2) AND C3(T3)
the nested-loop schema using guarded pushed-down conditions looks like this:
FOR each row t1 in T1 such that C1(t1) {
BOOL f1:=FALSE;
FOR each row t2 in T2
such that P1(t1,t2) AND (f1?C2(t2):TRUE) {
BOOL f2:=FALSE;
FOR each row t3 in T3
such that P2(t2,t3) AND (f1&&f2?C3(t3):TRUE) {
IF (f1&&f2?TRUE:(C2(t2) AND C3(t3))) {
t:=t1||t2||t3; OUTPUT t;
}
f2=TRUE;
f1=TRUE;
}
IF (!f2) {
IF (f1?TRUE:C2(t2) && P(t1,t2,NULL)) {
t:=t1||t2||NULL; OUTPUT t;
}
f1=TRUE;
}
}
IF (!f1 && P(t1,NULL,NULL)) {
t:=t1||NULL||NULL; OUTPUT t;
}
}
In general, pushed-down predicates can be extracted from join conditions such as
P(T2,T3). In this case, a pushed-down predicate is guarded also by a flag that prevents checking the
predicate for the NULL-complemented row generated by the corresponding outer join operation.
Note that access by key from one inner table to another in the same nested join is prohibited if it is
induced by a predicate from the
but this technique is not employed yet in MySQL 5.0.)
8.3.1.10. Outer Join Simplification
Table expressions in the
Optimizing
SELECT
condition is to be checked only after it has been found that
WHERE
condition. (We could use conditional key access in this case,
WHERE
clause of a query are simplified in many cases.
FROM
672
Statements
{
are pushed out of the most inner loop to
C3(T3)
is a very restrictive condition, this condition
C1(T1)
passed to the inner loops. As a result,
T1
and
P1(T1,T2)

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents