SQL Server 7.0 supports three types of join operations:
In this article I want to tell you about Nested-Loop joins, what kinds
of Nested-Loop joins exist, and when SQL Server will choose this kind
of join operation.
If you join two tables, and SQL Server optimizer choose Nested-Loop
join, then one table will be selected as outer table and the other
as inner table. SQL Server will scan the outer table row by row and
for each row in the outer table, it will scan the inner table, looking
for matching rows.
Nested-Loop join will be chosen if one of the tables is small and
the other table has an index on the column that joins the tables.
This is the example:
|
These are the results:
|
Because the query optimizer usually selects the best execution plan
for a given select statement, it is not necessary to change the kind
of join, but sometimes it can be useful. You can enforce the desirable
join type with OPTION clause.
This is the example to enforce Nested-Loop join:
|
There are three variants of Nested-Loop join:
(index, which was created by query optimizer and was destroyed when the query was completed)