Can anyone tell me which table is considered to be the inner one in a nested loop join? For example if the query is from a inner join b on...
, which one, a
, or b
will be considered inner? I knew that it is b
, but from the article at dbsophic, the first example under Small outer loop with a well indexed inner input seems to suggest the reverse.
Different Types of SQL JOINs(INNER) JOIN : Returns records that have matching values in both tables. LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table. RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the left table.
Inner Join Vs Other Joins Basically, these two clauses are the same. The INNER JOIN selects the common rows between two tables. Whereas the LEFT JOIN selects the common rows as well as all the remaining rows from the left table. The INNER JOIN selects the common rows between two tables.
SQL Server Nested Loops Join ExplainedOne of the joining tables is designated as the outer table and another one as the inner table. For each row of the outer table, all the rows from the inner table are matched one by one if the row matches it is included in the result-set otherwise it is ignored.
Inner joins use a comparison operator to match rows from two tables based on the values in common columns from each table. For example, retrieving all rows where the student identification number is the same for both the students and courses tables.
To be sure...
The choice of inner and outer tables for the physical operator is made by the optimiser and is unrelated to the logical operator.
Now, the nested loop psudeo code is this
for each row R1 in the outer table
for each row R2 in the inner table
if R1 joins with R2
return (R1, R2)
So it doesn't make a difference in theory.
In practice, the optimiser will work out the best way around for inner and outer tables: which is what your article link should describe. A.k.a how to reduce the number of iterations
For completeness... INNER JOIN
logical operator is commutative and associative
So A INNER JOIN B
is the same as B INNER JOIN A
.
There is no inner and outer table here
Actually, both tables are inner
as only rows are returned if there is a match in both tables.
When doing an outer join, you specify which table should be the outer one:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With