0% found this document useful (0 votes)
49 views6 pages

I3306-chap2-TD2-EN - Fa23-24-Solution

The document describes exercises related to file organization and indexing. It provides details on calculating record size, blocking factor, number of blocks, index size and structure for primary, secondary, and clustering indexes on different fields. It also includes exercises on inserting and deleting keys from B-trees and B+-trees. Finally, it describes using a bitmap index to query for employees with certain income levels and gender.

Uploaded by

Elias Khoury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views6 pages

I3306-chap2-TD2-EN - Fa23-24-Solution

The document describes exercises related to file organization and indexing. It provides details on calculating record size, blocking factor, number of blocks, index size and structure for primary, secondary, and clustering indexes on different fields. It also includes exercises on inserting and deleting keys from B-trees and B+-trees. Finally, it describes using a bitmap index to query for employees with certain income levels and gender.

Uploaded by

Elias Khoury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Chapitre 2

Exercise 1:
Consider a disk with block size B=512 bytes. A block pointer is P=6 bytes long, and a record pointer
is P R =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), DEPARTMENTCODE (9 bytes), ADDRESS (40
bytes), PHONE (9 bytes), BIRTHDATE (8 bytes), SEX (1 byte), JOBCODE (4 bytes), SALARY (4
bytes, real number). An additional byte is used as a deletion marker.

(a) Calculate the record size R in bytes.


Record length R = (30 + 9 + 9 + 40 + 9 + 8 + 1 + 4 + 4) + 1 = 115 bytes

(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/115) = 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
the index has x = 3 levels

(iv) the total number of blocks required by the multi-level index;


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

(d) Suppose the file is not ordered by the key field SSN and we want to construct a secondary index
on SSN. Repeat the previous exercise (part c) for the secondary index and compare with the primary
index.
i. Index record size R i = (V SSN + P) = (9 + 6) = 15 bytes
Index blocking factor bfr i = (fan-out) fo = floor(B/R i ) = floor(512/15)= 34 index records per block
ii. Number of first-level index entries r 1 = number of file records r = 30000
Number of first-level index blocks b 1 = ceiling(r 1 /bfr i ) = ceiling(30000/34)= 883 blocks

iii. number of levels:


Number of second-level index entries r 2 = number of first-level index blocks b 1= 883 entries
Number of second-level index blocks b 2 = ceiling(r 2 /bfr i ) = ceiling(883/34)= 26 blocks
Number of third-level index entries r 3 = number of second-level index blocks b 2= 26 entries
Number of third-level index blocks b 3 = ceiling(r 3 /bfr i ) = ceiling(26/34) = 1
Since the third level has only one block, it is the top index level. Hence, the index has x = 3
levels

iv. Total number of blocks for the index b i = b 1 + b 2 + b 3 = 883 + 26 + 1 = 910

v. Number of block accesses to search for a record = x + 1 = 3 + 1 = 4

(e) Suppose the file is ordered by the non-key field DEPARTMENTCODE and we want to construct
a clustering index on DEPARTMENTCODE that uses block anchors (every new value of
DEPARTMENTCODE starts at the beginning of a new block). Assume there are 1000 distinct values
of DEPARTMENTCODE, and that the EMPLOYEE records are evenly distributed among these
values. Calculate
(i) the index blocking factor bfr i (which is also the index fan-out fo);
Index record size R i = (V DEPARTMENTCODE + P) = (9 + 6) = 15 bytes
Index blocking factor bfr i = (fan-out) fo = floor(B/R i ) = floor(512/15)= 34 index records per block

(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 distinct DEPARTMENTCODE values= 1000
entries
Number of first-level index blocks b 1 = ceiling(r 1 /bfr i )= ceiling(1000/34) = 30 blocks

(iii) the number of levels needed if we make it a multi-level index;


Number of second-level index entries r 2 = number of first-level index blocks b 1= 30 entries
Number of second-level index blocks b 2 = ceiling(r 2 /bfr i ) = ceiling(30/34) = 1
Hence, the index has x = 2 levels

(iv) the total number of blocks required by the multi-level index;


Total number of blocks for the index b i = b 1 + b 2 = 30 + 1 = 31 blocks

Exercise 2:
Insert the following key values:
3, 7, 9, 23, 45, 1, 5, 14, 25, 24, 13, 11, 8, 19, 4, 31, 35, 56

a. Into a B-tree.
b. Into a B+-tree.

Consider the order m=5 (for both).

Solution of Exercise 2:

a)
b)

Exercise 3:

On B-tree already created,


• Add : 2, 6, 12
• Delete : 4, 5, 7, 3, 6, 14

Solution Exercise 3:

Add 2 :

Add 6 :

Add 12 :
Delete 4 :

Delete 5 :

Delete 7 :

Delete 3 :

Delete 6 :

Delete 14 :

Exercise 3:

On B+ already created, Delete : 4, 5, 7, 11, 23


Solution Exercise 3:
Delete 4 :

Delete 5 : Remove the key value from the leaf node. It is also an internal node; remove it and
replace it by the next key value in the leaf node.

Delete 7 : We remove it from the leaf and the parent; then we merge with the left sibling. At the higher
level, we have an underflow. We borrow 23 from the right to replace the root and we borrow 13 from the
root.

Delete 11 : We delete it and we borrow 8 from the left.

Delete 23 : and delete it from the root. We replace it by the min of the leaf nodes at the right (24). We also
delete it at the higher level after the merge. When we delete 25, we could not borrow from the left sibling, then
we merge the left, the root and the right.

Exercise 4 :
The following table contains the information of employees in a company.
Using the index bitmap, define:
1- Males with first level income.
2- Employees (male or female) with a first level income.
3- Employees who do not have a 5th level income.

Solution of exercise 4:
1) m AND L1: 10010 AND 10100: 10000 (corresponds to the first record of the table).
2) m of f: 10010 OR 01101: 11111. Then 11111 AND L1 (10100): 10100 (first and third record).
3) NOT L5: NOT 00000 = 11111 (all records).

You might also like