Oracle 5.0 Reference Manual page 686

Table of Contents

Advertisement

SELECT * FROM t1, t2 WHERE t2.column2=5 AND t1.column1=t2.column1;
This can be made faster because MySQL can use table
in a better query plan. To provide a hint about the table join order, use STRAIGHT_JOIN. (See
Section 13.2.8,
8.3.1.8. Nested-Loop Join Algorithms
MySQL executes joins between tables using a nested-loop algorithm or variations on it.
Nested-Loop Join Algorithm
A simple nested-loop join (NLJ) algorithm reads rows from the first table in a loop one at a time,
passing each row to a nested loop that processes the next table in the join. This process is repeated as
many times as there remain tables to be joined.
Assume that a join between three tables t1, t2, and
types:
Table
Join Type
t1
range
t2
ref
t3
ALL
If a simple NLJ algorithm is used, the join is processed like this:
for each row in t1 matching range {
for each row in t2 matching reference key {
for each row in t3 {
if row satisfies join conditions,
send to client
}
}
}
Because the NLJ algorithm passes rows one at a time from outer loops to inner loops, it typically reads
tables processed in the inner loops many times.
Block Nested-Loop Join Algorithm
A Block Nested-Loop (BNL) Join algorithm uses buffering of rows read in outer loops to reduce the
number of times that tables in inner loops must be read. For example, if 10 rows are read into a buffer
and the buffer is passed to the next inner loop, each row read in the inner loop can be compared
against all 10 rows in the buffer. The reduces the number of times the inner table must be read by an
order of magnitude.
MySQL uses join buffering under these conditions:
• The
join_buffer_size
• Join buffering can be used when the join is of type
when no possible keys can be used, and a full scan is done, of either the data or index rows,
respectively), or
• One buffer is allocated for each join that can be buffered, so a given query might be processed using
multiple join buffers.
• A join buffer is never allocated for the first nonconst table, even if it would be of type
[648].
index
• A join buffer is allocated prior to executing the join and freed after the query is done.
• Only columns of interest to the join are stored in the join buffer, not whole rows.
Optimizing
"SELECT
Syntax".)
[457]
system variable determines the size of each join buffer.
[647].
range
Statements
SELECT
before table
t2
is to be executed using the following join
t3
[648]
or
ALL
666
if doing so would result
t1
[648]
(in other words,
index
ALL
[648]
or

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents