According to nested join,given relation R and S
For each tuple r in R do
For each tuple s in S do
If r and s satisfy the join condition
Then output the tuple <r,s>
Cost estimations for the above loop:
– b(R) and b(S) number of blocks in R and in S
– Each block of outer relation is read once
– Inner relation is read once for each block of outer relation
Summing up : IO= b(R)+n(R)*b(S) total IO operations
Lets assume |R|>|S| i.e b(R) =10 , n(R) = 100 , n(S)= 30 ,and b(s) =3
Now, if R is outer relation then, IO= 10+100*3=340
if S is outer relation then IO=3+30*10=303
As it can be observed , that total IO is lesser if the value of outer variable is less and as it is already given that |R|<|S|.Therefore, Relation r(R) should be in the outer loop to have fewer number of disk block accesses.
References:


