Presentation is loading. Please wait.

Presentation is loading. Please wait.

Query Execution :Nested-Loop Joins Rohit Deshmukh ID 120 CS-257 Rohit Deshmukh ID 120 CS-257.

Similar presentations


Presentation on theme: "Query Execution :Nested-Loop Joins Rohit Deshmukh ID 120 CS-257 Rohit Deshmukh ID 120 CS-257."— Presentation transcript:

1 Query Execution :Nested-Loop Joins Rohit Deshmukh ID 120 CS-257 Rohit Deshmukh ID 120 CS-257

2 Tuple-Based Nested-Loop Join 1.The Nested-Loop joins can be used for relations of any size 2.Hence it is not necessary one relation fits in main memory. 3.In this algorithm we compute join R(X,Y) join S(Y,Z) 1.The Nested-Loop joins can be used for relations of any size 2.Hence it is not necessary one relation fits in main memory. 3.In this algorithm we compute join R(X,Y) join S(Y,Z)

3 Tuple-Based Nested-Loop Join R(X,Y) join S(Y,Z) Algorithm FOR each tuple s in S DO FOR each tuple r in R DO IF r and s join to make a tuple t THEN output t; R(X,Y) join S(Y,Z) Algorithm FOR each tuple s in S DO FOR each tuple r in R DO IF r and s join to make a tuple t THEN output t;

4 Tuple-Based Nested-Loop Join 1.To lower the number of disk I/O’s there are two cases § Use of index on the join attribute or attributes of R to find the tuples of R that match a given tuple of S § Divide the tuples R,S in blocks and use as much of the memory as it can to reduce the number of disk I/O’s. 1.To lower the number of disk I/O’s there are two cases § Use of index on the join attribute or attributes of R to find the tuples of R that match a given tuple of S § Divide the tuples R,S in blocks and use as much of the memory as it can to reduce the number of disk I/O’s.

5 Iterator for Tuple-Based Nested- Loop Join  One advantage of nested loop join is that it fits well into an iterator framework.  This allows us to avoid storing intermediate relations on disk in some situations  The iterator R join S is easy to build from iterators of R and S.  It makes the assumption that neither relation R nor S is empty.  One advantage of nested loop join is that it fits well into an iterator framework.  This allows us to avoid storing intermediate relations on disk in some situations  The iterator R join S is easy to build from iterators of R and S.  It makes the assumption that neither relation R nor S is empty.

6 Block-Based Nested-Loop Join The nested-loop join can be improved if we compute R join S as:  Organizing access to both argument relations by blocks  Using as much main memory as we can to store tuples belonging to relation S. The nested-loop join can be improved if we compute R join S as:  Organizing access to both argument relations by blocks  Using as much main memory as we can to store tuples belonging to relation S.

7 Block-Based Nested-Loop Join  The first point makes sure that when we run through tuples in R we use few disk I/O’s to read R  Second point enables us to join each tuple of R with as many tuples of S as will fit in memory  The first point makes sure that when we run through tuples in R we use few disk I/O’s to read R  Second point enables us to join each tuple of R with as many tuples of S as will fit in memory

8 Nested-Loop Join Algorithm FOR each chunk of M-1 blocks of S DO BEGIN read blocks in main memory; organize their tuples such that search key is common attribute; FOR each block b of R DO BEGIN read b into main memory; FOR each tuple t of v DO BEGIN find the tuples of S in main memory that join with t; Output the join of t with each of these tuples; End; FOR each chunk of M-1 blocks of S DO BEGIN read blocks in main memory; organize their tuples such that search key is common attribute; FOR each block b of R DO BEGIN read b into main memory; FOR each tuple t of v DO BEGIN find the tuples of S in main memory that join with t; Output the join of t with each of these tuples; End;

9 Nested loop Join Algorithm  Assuming S is the smaller relation, the iterations of the outer loop is: B(S) / (M-1).  The number of Disk I/O’s is B(S) + [B(S) B(R) / (M-1) ]  Assuming S is the smaller relation, the iterations of the outer loop is: B(S) / (M-1).  The number of Disk I/O’s is B(S) + [B(S) B(R) / (M-1) ]


Download ppt "Query Execution :Nested-Loop Joins Rohit Deshmukh ID 120 CS-257 Rohit Deshmukh ID 120 CS-257."

Similar presentations


Ads by Google