edited by
14,852 views
65 65 votes

A database table $T_1$ has $2000$ records and occupies $80$ disk blocks. Another table $T_2$ has $400$ records and occupies $20$ disk blocks. These two tables have to be joined as per a specified join condition that needs to be evaluated for every pair of records from these two tables. The memory buffer space available can hold exactly one block of records for $T_1$ and one block of records for $T_2$ simultaneously at any point in time. No index is available on either table.

If Nested-loop join algorithm is employed to perform the join, with the most appropriate choice of table to be used in outer loop, the number of block accesses required for reading the data are

  1. $800000$
  2. $40080$
  3. $32020$
  4. $100$

4 Answers

Best answer
117 117 votes

We just have to think which table would be in the outer loop. To minimize block accesses, we have to put that table outside having fewer records because for each outer record, one block access inside will be required.

Therefore, putting $2$nd table outside,

  • for each of $400$ records
    • $80$ block accesses in the first table $ \implies 32000$ accesses.
  • $20$ block accesses of the outer table.

So, the answer comes out to be $32000+20 = 32020$

Correct answer: C.

edited by
50 50 votes

Reference: http://en.wikipedia.org/wiki/Nested_loop_join

As per this reference this algorithm will involve $nr*bs+ br$ block transfers

$T_1$ can be either $R$ or $T_2$

  • If $R$ is $T_1$ then total number of block accesses is $2000 \times 20 + 80 = 40080$
  • If $R$ is $T_2$ then total number of block accesses is $400 \times 80+20 = 32020$

So, better is the second case $(32020)$ Hence, I go for option C.

edited by
12 12 votes

rel T1 with n (2000) tuples and x (80) blocks
rel T2 with m (400) tuples and y (20) blocks

If Nested-loop join algorithm is employed to perform the join:


R join S access cost = { X+N*Y } blocks

                                 = 80+2000*20

                                 =40080 blocks

S join R access cost = { Y+M*X } blocks

                                =20+400*80

                               =32020 blocks

edited by
0 0 votes

Let’s choose T₂ as outer (smaller record count → fewer iterations):

  • For each of 400 records in T₂:

    • Scan all 80 blocks of T₁

  • Total accesses:

Read T₂ once=20 blocks+400⋅80=32000 accesses⇒Total=20+32000=32020

Answer:
Position:
Show:

Related questions

63 63 votes
5 answers 5 answers
23.9k
23.9k views
Ishrat Jahan asked Nov 3, 2014
23,939 views
A database table $T_1$ has $2000$ records and occupies $80$ disk blocks. Another table $T_2$ has $400$ records and occupies $20$ disk blocks. These two tables have to be ...
39 39 votes
2 answers 2 answers
13.6k
13.6k views
Ishrat Jahan asked Nov 3, 2014
13,610 views
In a schema with attributes $A, B, C, D$ and $E$ following set of functional dependencies are given $A \rightarrow B$$A \rightarrow C$$CD \rightarrow E$$B \rightarrow D$...
74 74 votes
9 answers 9 answers
23.7k
23.7k views
Ishrat Jahan asked Nov 3, 2014
23,707 views
In an inventory management system implemented at a trading corporation, there are several tables designed to hold all the information. Amongst these, the following two ta...
78 78 votes
6 answers 6 answers
17.7k
17.7k views
Ishrat Jahan asked Nov 3, 2014
17,690 views
A table 'student' with schema (roll, name, hostel, marks), and another table 'hobby' with schema (roll, hobbyname) contains records as shown below:$$\overset{\text{Table:...