Nested Loops, Indexed Lookups, and Join Reuse
Estimate a join that iterates one input and queries the other, then decide when repeated probe keys can share work.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Choose an outer input and an inner access path
A plain nested-loop join can compare every outer row to every inner row. With an ordered inner index, each outer key can instead locate its matching range. Total cost then includes the number of outer rows times lookup work plus retrieving all matches. For ten selected orders and a unique indexed customer key, about ten lookups may be attractive. For a large outer input, repeatedly accessing dispersed pages can dominate.
Correlation and repetitions can change the cost
If many outer rows share a key, a cache of inner lookups can reduce repeated seeks while still emitting the correct pair multiplicities. The saved work depends on repeated keys, memory and what each row needs. Join cardinality bounds emission work. A hash join can arrange candidate access differently when the engine must process a large fraction of both inputs.[1][2]