3,949 views
19 votes
19 votes

Could Anybody tell me the concept of this block nested join?

I have a dount regarding that whether we have to check each block of S for each block of R or each record of R....If R is the outer Loop

1 Answer

Best answer
56 votes
56 votes

The major difference between nested loop join which is normal and default one and block nested loop join is that :

a) In default nested loop join , for each tuple of 1st and outer relation in this question let it be r(R) , each of the tuple of the second relation s(S) is going to be compared for doing the nested loop join.

In other words , for each tuple of relation r(R) all the blocks of s(S) is required .

Number of blocks for s(S) given   =   m

Number of tuples in r(R)   =   No of tuples in 1 block * No of blocks

                                     =    Rn * n

As mentioned each tuple of r(R) is going to be compared with all tuples of s(S) , in other words all blocks of s(S) are accessed.

So access cost  =  m * Rn * n

Also while accessing the records of r(R) if we consider usage of all tuples of r(R) which needs to be done in join , then the blocks of r(R) is also going to be accessed but each block gets accessed exactly once and that too for all the records within this block , no further access is required as r(R) is in outer loop of the nested loop join (since we compare a given record of r(R) in the outer loop with all records of s(S) and then it is done).So blocks of r(R) is also considered.

Hence total access cost  =   n + m * Rn * n   without block nested loop join

It can be shown in code as :

for ( i = 1 ; i <= n*Rn  ; i++)

{

       for(j = 1 ; j <= m ; j++)

             Compare(r(R)i   ,  s(S)j)

}

But in the question we are given that block nested loop join needs to be used.

b) So in nested loop join instead of each record of outer loop , each block of outer loop is joined with every block of records of inner relation which is s(S) according to our assumption.

So in this case , the blocks of inner relation is not going to be accessed repeatedly for each tuple of outer relation but will be accessed for each block of outer relation instead , thus reducing the access cost drastically.

So here we require for each block of r(R) , no of blocks required to be accessed of s(S)  =  m

So for n blocks  of r(R) , no of blocks required to be accessed of s(S)  =  n * m

Also in the outer loop like in the previous case , the blocks of r(R) are also accessed but once only since they are in outer loop.

So total no of blocks accessed for outer loop = No of blocks of r(R)  =  n

Hence total access cost i.e. no of blocks accessed  =  n + n * m using block nested loop join and provided r(R) is in outer loop and s(S) is in inner loop.

Hence A) is the correct option.

selected by

Related questions

1 votes
1 votes
1 answer
1
Aditya Bahuguna asked Jan 4, 2018
443 views
1 votes
1 votes
0 answers
2
Pawan Kumar 2 asked Jan 2, 2018
586 views
Are block transfers and block access same ?
2 votes
2 votes
2 answers
3
Shubhanshu asked Aug 18, 2017
1,371 views
Consider a relation R with 2000 records and relation S with 500 records. Size of each record is 5 Byte and block size is 100 Byte, then minimum number of block access tha...
1 votes
1 votes
1 answer
4
Gaurangi Katiyar asked Jan 16, 2019
376 views
Let a relation R with n tuples occupying X blocks and relation S with m tuples occupying Y blocks. 5 blocks of main memory are allocated to store records of R and S to pe...