Oracle 5.0 Reference Manual page 689

Table of Contents

Advertisement

|
2 | NULL | NULL |
+------+------+------+------+
Therefore, if we omit parentheses in a join expression with outer join operators, we might change the
result set for the original expression.
More exactly, we cannot ignore parentheses in the right operand of the left outer join operation and in
the left operand of a right join operation. In other words, we cannot ignore parentheses for the inner
table expressions of outer join operations. Parentheses for the other operand (operand for the outer
table) can be ignored.
The following expression:
(t1,t2) LEFT JOIN t3 ON P(t2.b,t3.b)
is equivalent to this expression:
t1, t2 LEFT JOIN t3 ON P(t2.b,t3.b)
for any tables
t1,t2,t3
Whenever the order of execution of the join operations in a join expression (join_table) is not from
left to right, we talk about nested joins. Consider the following queries:
SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.b=t3.b) ON t1.a=t2.a
WHERE t1.a > 1
SELECT * FROM t1 LEFT JOIN (t2, t3) ON t1.a=t2.a
WHERE (t2.b=t3.b OR t2.b IS NULL) AND t1.a > 1
Those queries are considered to contain these nested joins:
t2 LEFT JOIN t3 ON t2.b=t3.b
t2, t3
The nested join is formed in the first query with a left join operation, whereas in the second query it is
formed with an inner join operation.
In the first query, the parentheses can be omitted: The grammatical structure of the join expression will
dictate the same order of execution for join operations. For the second query, the parentheses cannot
be omitted, although the join expression here can be interpreted unambiguously without them. (In our
extended syntax the parentheses in
the query could be parsed without them: We still would have unambiguous syntactical structure for the
query because
LEFT JOIN
(t2,t3).)
The preceding examples demonstrate these points:
• For join expressions involving only inner joins (and not outer joins), parentheses can be removed.
You can remove parentheses and evaluate left to right (or, in fact, you can evaluate the tables in any
order).
• The same is not true, in general, for outer joins or for outer joins mixed with inner joins. Removal of
parentheses may change the result.
Queries with nested outer joins are executed in the same pipeline manner as queries with inner joins.
More exactly, a variation of the nested-loop join algorithm is exploited. Recall by what algorithmic
schema the nested-loop join executes a query. Suppose that we have a join query over 3 tables
of the form:
T1,T2,T3
SELECT * FROM T1 INNER JOIN T2 ON P1(T1,T2)
INNER JOIN T3 ON P2(T2,T3)
Optimizing
SELECT
101 |
and any condition
over attributes
P
of the second query are required, although theoretically
(t2, t3)
and
would play the role of the left and right delimiters for the expression
ON
669
Statements
and t3.b.
t2.b

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents