edited by
23,798 views
63 63 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, instead of Nested-loop join, Block nested-loop join is used, again with the most appropriate choice of table in the outer loop, the reduction in number of block accesses required for reading the data will be

  1. $0$
  2. $30400$
  3. $38400$
  4. $798400$

5 Answers

Best answer
95 95 votes

In Nested loop join for each tuple in first table we scan through all the tuples in second table.

Here we will take table $T2$ as the outer table in nested loop join algorithm. The number of block accesses then will be $20 + (400 × 80) = 32020$

In block nested loop join we keep $1$ block of $T1$ in memory and $1$ block of $T2$ in memory and do join on tuples.

For every block in T1 we need to load all blocks of T2. So number of block accesses is $80$*$20 + 20 = 1620$

So, the difference is $32020 - 1620 =30400$

(B) 30400

edited by
41 41 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 used 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

but If Block nested-loop join is used to perform the join:


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

                                 = 80+80*20 

                                 =1680 blocks 

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

                                =20+20*80 

                               =1620 blocks

 reduction in number of block accesses required for reading the data = 32020-1620

                            =30400

so ans should be B

0 0 votes
  1. Bring a block of T2.
  2. Bring all blocks of T1 one at a time.
  3. Repeat above steps for T1 total block times. 

Complexity -

  1. 1 block access
  2. 80 block accesses 
  3. (80+1)*20 = 1620

Subtract it from 32020.

edited by
0 0 votes

🧠 Step 1: Basic Nested Loop Join

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

🧠 Step 2: Block Nested Loop Join

Now we use block-level batching. Let’s again choose T₂ as outer:

  • Outer loop: T₂ has 20 blocks

  • Inner loop: For each block of T₂, scan all 80 blocks of T₁

  • Total accesses:

Read T₂ once=20 blocks+20⋅80=1600 accesses⇒Total=20+1600=1620

🔻 Reduction in Block Accesses:

Basic NLJ−Block NLJ=32020−1620=30400

✅ Correct Answer: B. 30400

Answer:
Position:
Show:

Related questions

65 65 votes
4 answers 4 answers
14.7k
14.7k views
Ishrat Jahan asked Nov 3, 2014
14,701 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 ...
38 38 votes
2 answers 2 answers
13.6k
13.6k views
Ishrat Jahan asked Nov 3, 2014
13,570 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.4k
23.4k views
Ishrat Jahan asked Nov 3, 2014
23,422 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.6k
17.6k views
Ishrat Jahan asked Nov 3, 2014
17,555 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:...