0% found this document useful (0 votes)
23 views5 pages

Dbms Assignment Indexes by Shivanshu Mishra

The document contains two questions regarding the calculation of maximum block accesses required to reach data items in a database with primary and secondary indexes. For the primary index, the maximum number of block accesses is determined to be 5, while for the secondary index, it is 6. Both calculations involve determining the number of records per block, total blocks needed, index entry sizes, and levels of indexing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Dbms Assignment Indexes by Shivanshu Mishra

The document contains two questions regarding the calculation of maximum block accesses required to reach data items in a database with primary and secondary indexes. For the primary index, the maximum number of block accesses is determined to be 5, while for the secondary index, it is 6. Both calculations involve determining the number of records per block, total blocks needed, index entry sizes, and levels of indexing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

DBMS ASSIGNMENT INDEXES

Q1. There is a Primary index(sparse) created on a table. Total number of


records in the table is 700000. Size of a block is 512 bytes. Each data record is
of fixed 100 bytes in size and unspanned. Ordering key size is 9 bytes and
block pointer size is 6 bytes. Find the maximum number of block accesses
required to reach the block that contains the searched data item.

Answer:
Given
 Total records: 700,000
 Block size: 512 bytes
 Record size: 100 bytes
 Ordering key size: 9 bytes
 Block pointer size: 6 bytes
 Unspanned records (no record spans multiple blocks)

Steps & Calculations


Step 1: Calculate the number of data records that fit in one block
The size of each record is 100 bytes, and the block size is 512 bytes. Since
unspanned records are stored:

Records per block=¿

Step 2: Calculate the total number of blocks needed for 700,000 records
Each block can store 5 records. The total number of blocks required is:

Number of blocks=
[ Total Records
][
Records per block
=
700000
5 ]=140,000 blocks

Step 3: Calculate the size of one index entry


An index entry consists of the ordering key (9 bytes) and a block pointer (6
bytes). The size of one index entry is:
Index entry ¿ 9bytes (key )+6 bytes( pointer )=15 bytes

Step 4: Calculate the number of index entries that fit in one block
The block size is 512 bytes, and each index entry is 15 bytes. The number of
entries per block is:
Entrie s per block=¿

Step 5: Calculate the total number of index blocks needed


Each index block stores 34 entries, and we need 140,000 entries (one entry per
data block). The total number of index blocks is:

Index block s=
[ ][
Total data blocks
Entries per block
=
140000
34 ]
= 4188 index blocks

Step 6: Determine the number of index levels


Each index level points to blocks in the next lower level. Starting from 4,118
index blocks:
 Level 1: 4,1184 index blocks.
4118
 Level 2: ⌈ 34 ⌉ =122 blocks

122
 Level 3: ⌈ 34 ⌉ =4 blocks

4
 Level 4: ⌈ 34 ⌉=1 blocks

Thus, the index has 4 levels.


Step 7: Calculate the total block accesses for a sparse index
To search for a data record, we traverse from the root of the index to the data
block. Each level requires one block access:
Total block accesses=Number of index levels+ 1(data block)=4+1=5 block accesses

Final Answer:
The maximum number of block accesses required to reach the block
containing the searched data item is 5.
Q2. Consider a secondary index created on the same table as in Question1.
Total number of records in the table is 700000. Size of a block is 512 bytes.
Each data record is of fixed 100 bytes in size and unspanned. Non-ordering
key which is a secondary field is of 12 bytes and block pointer size is 6 bytes.
Find the maximum number of block accesses required to reach the block that
contains the searched data item.

Answer:
Given
 Total number of records = 700,000
 Block size = 512 bytes
 Record size = 100 bytes
 Non-ordering key size (secondary field) = 12 bytes
 Block pointer size = 6 bytes
 Unspanned records (each block holds complete records).

Steps and Calculations


Step 1: Number of records per data block
The data record size is 100 bytes, and the block size is 512 bytes.
Records per block=¿

Step 2: Calculate the total number of blocks needed for 700,000 records
Each block can store 5 records. The total number of blocks required is:

[
Number of blocks=
Total Records
][
Records per block
=
700000
5 ]=140,000 blocks

Step 3: Size of one secondary index entry


A secondary index entry consists of:
1. The non-ordering key = 12 bytes
2. The block pointer = 6 bytes
Index entry ¿ 12 bytes(key )+ 6 bytes( pointer)=18 bytes

Step 4: Number of index entries per block


Each block is 512 bytes, and each index entry is 18 bytes, so the number of
entries per index block is:
Entrie s per block=¿

Step 5: Total number of index blocks


We need one index entry for each record (700,000 entries). With 28 entries
per block, the total number of index blocks required is:

Index block s=
[ ][
Total data blocks
Entries per block
=
70 0000
28 ]
= 25000index blocks

Step 6: Number of levels in the secondary index


To manage 25,000 index blocks, additional levels of indexing are required.
Using the same calculation, each higher-level index block can store 28 entries.
 Level 1: 25000 index blocks.
25000
 Level 2: ⌈ 28 ⌉=893 blocks

893
 Level 3: ⌈ 25 ⌉=32 blocks

32
 Level 4: ⌈ 28 ⌉=2 blocks

2
 Level 5: ⌈ 28 ⌉=1 blocks

Thus, the secondary index has 5 levels.

Step 7: Total block accesses


To find a record, we need to:
1. Traverse all 5 levels of the index.
2. Access the data block containing the record.
Total block accesses=Index levels+1=5+1=6 block accesses

Final Answer
The maximum number of block accesses required to reach the block
containing the searched data item is 6.

You might also like