[prev] 18 [next]

Sort-Merge Join (cont)

Standard merging requires two cursors:

while (r != eof && s != eof) {
    if (r.val ≤ s.val) { output(r.val); next(r); }
    else { output(s.val); next(s); }
}
while (r != eof) { output(r.val); next(r); }
while (s != eof) { output(s.val); next(s); } 

[Diagram:Pics/join/sort-merge-uniq.png]