From LEFT JOIN and RIGHT JOIN Optimization
The join optimizer calculates the order in which tables should be joined.
MySQL implements an
as follows:
A
LEFT JOINB
join_condition
- Table
B
is set to depend on tableA
and all tables on whichA
depends.- Table
A
is set to depend on all tables (exceptB
) that are used in theLEFT JOIN
condition.- The
LEFT JOIN
condition is used to decide how to retrieve rows from tableB
. (In other words, any condition in theWHERE
clause is not used.)- 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
WHERE
optimizations are performed.- If there is a row in
A
that matches theWHERE
clause, but there is no row inB
that matches theON
condition, an extraB
row is generated with all columns set toNULL
.