Row* JoinNestedLoops::next()
{
while (r_row != NULL && s_row != NULL && !match(r_row, s_row)) {
// Rows don't match on join columns, advance S.
s_row = S->next();
if (s_row == NULL) {
// Finished the inner loop (on S). Advance R, and if there
is another R row, then restart the scan of S.
r_row = R->next();
if (r_row != NULL) {
S->close();
S->open();
s_row = s->next();
}
}
}
// We either have an r_row and s_row that match and should be joined,
// or there is no more output.
return
r_row != NULL && s_row != NULL
? join_rows(r_row, s_row)
: NULL;
}
|
void JoinNestedLoops::close()
{
R->close();
S->close();
}
|