Contents Index Join algorithms Nested loops semijoin

ASA SQL User's Guide
  Query Optimization and Execution
    Query execution algorithms
      Join algorithms

Nested loops join

The nested loops join computes the join of its left and right sides by completely reading the right hand side for each row of the left hand side. (The syntactic order of tables in the query does not matter, because the optimizer chooses the appropriate join order for each block in the request.)

The optimizer may choose nested loops join if the join condition does not contain an equality condition, or if it is optimizing for first-row time.

Since a nested loops join reads the right hand side many times, it is very sensitive to the cost of the right hand side. If the right hand side is an index scan or a small table, then the right hand side can likely be computed using cached pages from previous iterations. On the other hand, if the right hand side is a sequential table scan or an index scan that matches many rows, then the right hand side needs to be read from disk many times. Typically, a nested loops join is less efficient than other join methods. However, nested loops join can provide the first matching row quickly compared to join methods that must compute their entire result before returning.

Nested loops join is the only join algorithm that can provide sensitive semantics for queries containing joins. This means that sensitive cursors on joins can only be executed with a nested loops join.

A semijoin fetches only the first matching row from the right hand side. It is a more efficient version of the nested loops join, but can only be used when an EXISTS, or sometimes a DISTINCT, keyword is used.


Contents Index Join algorithms Nested loops semijoin