Document

advertisement
Database Systems 2, 3rd March, 2007
Tóth Balázs Viktor (CDZ3GR)
Homework 1
1)
Step 1: Insertion of „31”
31
Step 2: Insertion of „29”
29
31
23
29
Step 3: Insertion of „23”
31
Step 4: Insertion of „19”
29
19
23
29
31
29
31
Step 5: Insertion of „17”
29
17
19
23
Step 6: Insertion of „11”
11
17
19
29
19
23
19
29
19
23
29
31
29
31
Step 7: Insertion of „7”
7
11
17
Step 8: Insertion of „5”
1
Database Systems 2, 3rd March, 2007
Tóth Balázs Viktor (CDZ3GR)
11
5
7
11
19
29
17
19
23
29
31
23
29
31
Step 9: Insertion of „3”
11
3
5
7
11
19
29
17
19
Step 10: Insertion of „2”
19
5
2
3
5
7
11
29
11
17
19
23
29
2) Find all records with a search-key value between 7 and 17.
First we have to find 7 and then follow the sibling pointers till we reach 17. So:
 Start with the root node. We are searching for the smallest search-key value > 7. It is
19.
 Assume it is K1. Then follow P1 to the child node (5,11).
 Then we are also searching for the smallest search-key value > 7 what is 11.
 Assume it is K2. Then follow P2 to the child node (5,7). We have reached the leaf
node.
 If for some i, key Ki = 7 follow pointer Pi to the desired record or bucket. Then go
on.
 Then for some j, till reach key Kj = 17 follow pointer Pj to the desired record or
bucket. Then stop.
2
31
Database Systems 2, 3rd March, 2007
Tóth Balázs Viktor (CDZ3GR)
19
5
2
3
5
11
29
7
11
OK
17
19
23
29
31
23
29
31
OK OK
3)
The tree after the insertion „9”: It is just a leaf update, 3 reads - 1 write.
19
5
2
3
5
7
11
29
9
11
17
19
The tree after the insertion of „9”, „10”: 3 reads - 3 writes
19
5
2
3
5
7
9
11
29
9
10
11
17
19
23
The tree after the insertion of „9”, „10”, „8”: It is just a leaf update, 3 reads - 1 write
3
29
31
Database Systems 2, 3rd March, 2007
Tóth Balázs Viktor (CDZ3GR)
19
5
2
3
5
9
7
11
8
29
9
10
11
17
19
23
29
31
The tree after the insertion of „9”, „10”, „8”, „6”: 3 reads - 5 writes
9
5
2
3
5
6
19
7
29
11
7
8
9
10
11
17
19
23
29
4)
Let relations r1(A, B, C) and r2(C, D, E) have the following properties: r1 has 20,000 tuples,
r2 has 45,000 tuples, 25 tuples of r1 fit in one block, and 30 tuples of r2 can be stored in a
block. Estimate the number of block access required, using each of the following join
strategies for r1 r2:
a. nested-loop join
Total: 20,000+20,000*45,000=900,020,000 accesses.
b. block nested-loop join
There are 20,000/25=800 blocks in r1 and 45,000/30=1500 blocks in r2.
Total: 800+800*1500=1,200,800 accesses.
c. merge join
There are 20,000/25=800 blocks in r1 and 45,000/30=1500 blocks in r2.
Each block needs to be read only once.
Total: 800+1500=2300 accesses.
d. hash join (assume that hash buckets fit in main memory)
We have to read each block of r1 and r2 once but the buckets fit in main
memory so each block has to accessed once more.
Total: 2300+2300=4600 accesses.
4
31
Download