Download presentation
Presentation is loading. Please wait.
Published byCornelius Cooper Modified over 9 years ago
1
42 Example Join-- File Information 4 Emp( Fn Char(10), Minit Char, LN Char(20), SSN number(9), Bdate Date, Addr char(40), Sex Char, Salary Number(9,2), Dno number(3))
2
Employee Numbers –r = 10,000 records –|r| = 99 bytes/record –Block Size = 512 bytes/block –bf = 5 records/block –b = 2,000 blocks –B+-Tree on Dno: L dno = 3, d dno = 125, s dno = 80, m dno = 47 B Ldno = 434 43
3
44 Example Join-- File Information 4 Dept( D# Number(3), Dname Char(20), MGRSSN Number(9), MgrStartDate Date)
4
Dept Numbers –r = 125 records –|r| = 38 bytes/record –bf = 13 records/block –b = 10 blocks –B+-Tree on D#: L dno = 2, d dno = 125, s dno = 1, m dno = 47 B Ldno = 5 45
5
46 The Sample Query: I want to use Emp ê Dept. What are my options? Dno=D# 4 Nested Loop approach. 4 Use B-Tree on Emp.Dno. 4 Use B-Tree on Dept.D# 4 Cluster Employee and Department together.
6
47 Join Query -- Nested Loop Emp ê Dept. Dno=D# 4 CJ1 = b dept + b Emp * b Dept = 10 + 2000 * 10 = 20,010
7
48 Join Query -- B-Tree on D# Emp ê Dept. Dno=D# 4 CJ2 D# = b Emp + r Emp * (L Dept.D# + 1) = 2000 + 10000 * (2 + 1) = 32,000
8
49 Join Query -- B-Tree on Dno Emp ê Dept. Dno=D# CBn Dno = L+ ( s / ( m/2 -1) + s = 3 + ( / ( 47/2 -1) + 80 = 3 + 4 1 + 80 = 86 4 CJ2 D# = b Dept + r Dept * (CBn Dno ) = 10 + 125 * (86) = 10,760
9
Join Query – B-Tree on Dno Disucssion 4 This is the better choice. 4 Note: I have ignored the WTDC here because it would be the same in all cases. 50
10
51 Join Query -- Clustered Files Emp ê Dept. Dno=D# 4 CJ3 = b R + b s = 2000 + 10 = 2,010 4 This is the best choice. 4 Note: it does restrict how the files are stored.
11
52 Join Query – Sort Files First Emp ê Dept. Dno=D# 4 Sort Emp: b R *Log 2 (b R ) = 2,000*11= 22000 4 Sort Dept: b S *Log 2 (b S ) = 10*4 = 40 4 CJ3 = b R + b S = 2000+10 = 2010 = = 24050
12
53 Join Query – Build Hash On Emp.DNO Emp ê Dept. Dno=D# 4 Build Hash: b R + r R = 2000+10000 = 12000 4 Hash Join: = 1+ s = 81 4 CJ3 = b s + r S *(81) = 10+125*(81) = 10135 = = 22135
13
Example WTDC 4 If all columns are needed, we have –|r| = 99+38 -3 (D# stored only once) = 134 –r = r Emp = 10,000 –Bf = floor(512/134) = 3 –b = ceil(10,000/3) = 3334 –Thus the WTDC = 3334 54
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.