Oracle 5.0 Reference Manual page 691

Table of Contents

Advertisement

Note that for the query with inner joins, the optimizer could choose a different order of nested loops,
such as this one:
FOR each row t3 in T3 {
FOR each row t2 in T2 such that P2(t2,t3) {
FOR each row t1 in T1 such that P1(t1,t2) {
IF P(t1,t2,t3) {
t:=t1||t2||t3; OUTPUT t;
}
}
}
}
For the queries with outer joins, the optimizer can choose only such an order where loops for outer
tables precede loops for inner tables. Thus, for our query with outer joins, only one nesting order is
possible. For the following query, the optimizer will evaluate two different nestings:
SELECT * T1 LEFT JOIN (T2,T3) ON P1(T1,T2) AND P2(T1,T3)
WHERE P(T1,T2,T3)
The nestings are these:
FOR each row t1 in T1 {
BOOL f1:=FALSE;
FOR each row t2 in T2 such that P1(t1,t2) {
FOR each row t3 in T3 such that P2(t1,t3) {
IF P(t1,t2,t3) {
t:=t1||t2||t3; OUTPUT t;
}
f1:=TRUE
}
}
IF (!f1) {
IF P(t1,NULL,NULL) {
t:=t1||NULL||NULL; OUTPUT t;
}
}
}
and:
FOR each row t1 in T1 {
BOOL f1:=FALSE;
FOR each row t3 in T3 such that P2(t1,t3) {
FOR each row t2 in T2 such that P1(t1,t2) {
IF P(t1,t2,t3) {
t:=t1||t2||t3; OUTPUT t;
}
f1:=TRUE
}
}
IF (!f1) {
IF P(t1,NULL,NULL) {
t:=t1||NULL||NULL; OUTPUT t;
}
}
}
In both nestings,
must be processed in the outer loop because it is used in an outer join.
T1
are used in an inner join, so that join must be processed in the inner loop. However, because the join is
an inner join,
and
T2
T3
When discussing the nested-loop algorithm for inner joins, we omitted some details whose impact
on the performance of query execution may be huge. We did not mention so-called "pushed-down"
conditions. Suppose that our
formula:
P(T1,T2,T2) = C1(T1) AND C2(T2) AND C3(T3).
Optimizing
SELECT
can be processed in either order.
condition
WHERE
P(T1,T2,T3)
671
Statements
can be represented by a conjunctive
and
T2
T3

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents