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 $0$ $30400$ $38400$ $798400$ Databases gateit-2005 databases normal joins + – Ishrat Jahan 23.8k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments GovindYadav29 commented Dec 30, 2022 reply Follow flag https://www.youtube.com/watch?v=XTMb_9z4qbM Nice video to refer 0 0 replyShare ꧁༒☬ĿọŗԀ 🆂🅷🅸🆅🅰☬༒꧂ commented Jun 5, 2024 reply Follow flag https://15445.courses.cs.cmu.edu/fall2018/notes/12-joins.pdf 1 1 replyShare mv_ind commented Sep 26, 2025 reply Follow flag https://www.youtube.com/watch?v=3Ui4tCS4iKM&list=PLC36xJgs4dxGcz7nZaxGxxmbJrcgDXhFk&index=224 0 0 replyShare Please log in or register to add a comment.
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 Omesh Pandita answered Nov 22, 2014 • edited Jun 3, 2021 by Arjun Omesh Pandita comment Share Follow See all 11 Comments 11 11 Comments reply Himanshu1 commented Nov 14, 2015 reply Follow flag For Block Nested loop Join - Why are you having 1620 accesses, I m having 80 * 20 = 1600, Why 20 extra for Block Nested loop Join..?? 4 4 replyShare Pradip Nichite commented Nov 16, 2015 reply Follow flag Please add formula for cost calculation of nested loop and block nested loop 0 0 replyShare rajan commented Nov 23, 2016 reply Follow flag 20 will be added bcz we choose T2 priviously when apply nestesd loop join as a outer loop 0 0 replyShare mehul vaidya commented Jul 3, 2018 reply Follow flag just explaining calculation 20+(400×80) means bring 20 blocks of T2 in memory either one by one or in single shot(hence +20 added) then for each record (400) in this blocks bring each block of T1 (80) in memory. 80*20+20 means means bring 20 blocks of T2 in memory either one by one or in single shot(hence +20 added) then for each block of T2 bring block of T1. finish all computation between this blocks (Note earlier we did not check for every record of block of T2 , we just checked for first record in T2 with first block of T1 and moved on to next block of T1)then moved on to next block of T1. If all blocks of T1 finished with checking then move on to next block of T2. 9 9 replyShare Shamim Ahmed commented Nov 9, 2018 reply Follow flag Could you please explain how +20 is done in the answer? 1 1 replyShare talha hashim commented Jan 26, 2019 reply Follow flag Smaller table should be outside bro.so 20 added 0 0 replyShare arka084 commented Jan 29, 2020 reply Follow flag you have to add 20 extra block accesses, for outer table T1 0 0 replyShare Venky8 commented May 5, 2021 reply Follow flag Can somebody explain, number of seeks required for nested-loop join and block nested-loop join? 0 0 replyShare Abhrajyoti00 commented Sep 24, 2022 reply Follow flag In Nested Loop Join, each record in outer table joins with every block of inner table + # blocks in Outer Table cost. If we would have taken table $T1$ outside, then number of block accesses would have been : $2000*20+80 = 40080 \ which \ is > 32020$. Hence most appropriate choice of table in the outer loop is $T2 \ (table \ with \ fewer \ records)$ In Block nested loop join, each block in outer table joins with every block of inner table + # blocks in Outer Table cost. If we would have taken table $T2$ outside, then number of block accesses would have been : $80*20+80 = 1680 \ which \ is > 1620$. Hence most appropriate choice of table in the outer loop is $T2 \ (table \ with \ fewer \ blocks)$ 4 4 replyShare Tejaswee_Bommaluleni commented Sep 20, 2025 reply Follow flag @Abhrajyoti00 Bhaiya, because of people like you I am able to understand the concept easily. Thank You for writing such good answers :)) 0 0 replyShare Thanneeru_Venkateswa commented Nov 14, 2025 reply Follow flag helpful 0 0 replyShare Please log in or register to add a comment.
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 rajoramanoj answered Sep 3, 2017 rajoramanoj comment Share Follow See all 2 Comments 2 2 Comments reply srestha commented Sep 15, 2017 reply Follow flag outer table should have less records Then no need to calculate all records 0 0 replyShare Abhijit Sen 4 commented Apr 11, 2018 reply Follow flag It is well explained. https://gateoverflow.in/76143/block-nested-loop-join 5 5 replyShare Please log in or register to add a comment.
2 2 votes Both question, Nested Loop Join and Block Nested Loop Join tusharSingh answered Jan 17, 2021 tusharSingh comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Bring a block of T2. Bring all blocks of T1 one at a time. Repeat above steps for T1 total block times. Complexity - 1 block access 80 block accesses (80+1)*20 = 1620 Subtract it from 32020. 2019_Aspirant answered Nov 23, 2018 • edited Jan 6, 2019 by 2019_Aspirant 2019_Aspirant comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes 🧠 Step 1: Basic Nested Loop JoinLet’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 JoinNow we use block-level batching. Let’s again choose T₂ as outer:Outer loop: T₂ has 20 blocksInner 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 Ujjwal_Nikam answered Oct 29, 2025 Ujjwal_Nikam comment Share Follow 0 reply Please log in or register to add a comment.