Department of Computer Science 1411365 DB Design and Implementation Exercise 3:
ID: 3683305 • Letter: D
Question
Department of Computer Science
1411365 DB Design and Implementation
Exercise 3: Solve Exercise 18.18 (a, b and c) from the textbook.
Exercises 18.18. Consider a disk with block size B = 512 bytes. A block pointer is P = 6 bytes long, and a record pointer is PR-7 bytes long. A file has r = 30,000 EMPLOYEE records of fixed length. Each record has the following fields: Name (30 bytes), Ssn (9 bytes), Department_code (9 bytes), Address (40 bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1 byte), Job code (4 bytes), and Salary (4 bytes, real number). An additional byte is used as a deletion marker. a. Calculate the record size R in bytes. b. Calculate the blocking factor bfr and the number of file blocks b, assum ing an unspanned organization. c. Suppose that the file is ordered by the key field Ssn and we want to con- struct a primary index on Ssn. Calculate (i) the index blocking factor bfr (which is also the index fan-out fo); (ii) the number of first-level index entries and the number of first-level index blocks; (iii) the number of lev- els needed if we make it into a multilevel index; (iv) the total number of blocks required by the multilevel index; and (v) the number of block accesses needed to search for and retrieve a record from the file-given its Ssn value-using the primary index.Explanation / Answer
Hi below i have given the solution for your reference,
(a) Calculate the record size R in bytes:
R = 30 B + 9 B + 9 B + 40 B + 10 B + 8 B + 1 B + 4 B + 4 B + 1 B = 116 B
(b) Calculate the blocking factor bfr and the number of file blocks b assuming an unspanned organization.
Blocking factor bfr = floor (B/R) = floor(512/116) = 4 records per block
Number of blocks needed for file = ceiling(r/bfr) = ceiling(30000/4) = 7500
(c) Suppose the file is ordered by the key field SSN and we want to construct a primary index on SSN. Calculate
(i) the index blocking factor bfr i (which is also the index fan-out fo);
Index record size R i = (V SSN + P) = (9 + 6) = 15 bytes
Index blocking factor bfr i = fo = floor(B/R i ) = floor(512/15) = 34
(ii) the number of first-level index entries and the number of first-level index blocks;
Number of first-level index entries r 1 = number of file blocks b = 7500 entries
Number of first-level index blocks b 1 = ceiling(r 1 / bfr i ) = ceiling(7500/34) = 221 blocks
(iii) the number of levels needed if we make it into a multi-level index;
Number of second-level index entries r 2 = number of first-level blocks b 1 = 221 entries
Number of second-level index blocks b 2 = ceiling(r 2 /bfr i ) = ceiling(221/34) = 7 blocks
Number of third-level index entries r 3 = number of second-level index blocks b 2 = 7 entries
Number of third-level index blocks b 3 = ceiling(r 3 /bfr i ) = ceiling(7/34) = 1
Since the third level has only one block, it is the top index level. Hence, the index has x = 3 levels
(iv) the total number of blocks required by the multi-level index; and
Total number of blocks for the index b i = b 1 + b 2 + b 3 = 221 + 7 + 1 = 229 blocks
(v) the number of block accesses needed to search for and retrieve a record from the file--given its SSN value--using the primary index.
Number of block accesses to search for a record = x + 1 = 3 + 1 = 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.