The base algorithm shown in the presentation iterates over the **tuples **of S and R. That means, if it encounters equality of S.a=R.b, let the equal tuples be numbered as S[i], R[j], then it continues checking equality for:

S[i].a = R[j+1].b

S[i].a = R[j+1].b

and so on, breaking only when reaching the end of R relation \ inequality.

Thus for the next tuple of S, we may need to re-read the already read blocks of R.

A simple improvement of the algorithm may use **Page Oriented** equality check:

Let M denote the number of blocks our memory can contain. We need 1 buffer block for R, 1 buffer block for the output and we can use the remaining M-2 blocks for loading S blocks.

Thus the number of I/O operations is: B(R) * (B(S) / (M - 2)) + B(S)

Hope it helps.