Rechercher dans le manuel MySQL
8.2.1.8 Outer Join Optimization
Outer joins include LEFT JOIN and
RIGHT JOIN.
MySQL implements an as
follows:
A LEFT
JOIN B
join_specification
Table
Bis set to depend on tableAand all tables on whichAdepends.Table
Ais set to depend on all tables (exceptB) that are used in theLEFT JOINcondition.The
LEFT JOINcondition is used to decide how to retrieve rows from tableB. (In other words, any condition in theWHEREclause 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 dependency, an error occurs.
All standard
WHEREoptimizations are performed.If there is a row in
Athat matches theWHEREclause, but there is no row inBthat matches theONcondition, an extraBrow is generated with all columns set toNULL.If you use
LEFT JOINto find rows that do not exist in some table and you have the following test:in thecol_nameIS NULLWHEREpart, wherecol_nameis a column that is declared asNOT NULL, MySQL stops searching for more rows (for a particular key combination) after it has found one row that matches theLEFT JOINcondition.
The RIGHT JOIN implementation is analogous
to that of LEFT JOIN with the table roles
reversed. Right joins are converted to equivalent left joins,
as described in Section 8.2.1.9, “Outer Join Simplification”.
For a LEFT JOIN, if the
WHERE condition is always false for the
generated NULL row, the LEFT
JOIN is changed to an inner join. For example, the
WHERE clause would be false in the
following query if t2.column1 were
NULL:
Therefore, it is safe to convert the query to an inner join:
In MySQL 8.0.14 and later, trivial WHERE
conditions arising from constant literal expressions are
removed during preparation, rather than at a later stage in
optimization, by which time joins have already been
simplified. Earlier removal of trivial conditions allows the
optimizer to convert outer joins to inner joins; this can
result in improved plans for queries with outer joins
containing trivial conditions in the WHERE
clause, such as this one:
The optimizer now sees during preparation that 0 = 1 is always
false, making OR 0 = 1 redundant, and
removes it, leaving this:
Now the optimizer can rewrite the query as an inner join, like this:
Now the optimizer can use table t2 before
table t1 if doing so would result in a
better query plan. To provide a hint about the table join
order, use optimizer hints; see
Section 8.9.3, “Optimizer Hints”. Alternatively, use
STRAIGHT_JOIN; see
Section 13.2.10, “SELECT Syntax”. However,
STRAIGHT_JOIN may prevent indexes from
being used because it disables semijoin transformations; see
Section 8.2.2.1, “Optimizing IN and EXISTS Subquery predicates with Semijoin
Transformations”.
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-outer-join-optimization.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.