TOPICS (Click to Navigate)

Pages

Saturday, February 10, 2018

Find the number of records and record size for storing data in one disk block

Find the number of records and record size for storing data in one disk block, How to calculate block size, How to calculate record size, calculate the number of records fit in one disk block in database management system


Question:

6. Suppose blocks of 1024 bytes are used to store variable-length records. The fixed part of the block header is 24 bytes, and includes a count of the number of records. In addition, the header contains a 4-byte pointer (offset) to each record in the block. The first record is placed at the end of the block, the second record starts where the first one ends, and so on. The size of each record is not stored explicitly, since the size can be computed from the pointers.
(i) How many records of size 50 bytes could we fully fit (no spanning) in such a block? (The block is designed to hold variable size records, but these records by coincidence happen to be all the same size.)
(ii) Suppose we want to store 20 records in the block, all of the same fixed size. What is the size of such records?
(iii) Now assume the block layout is changed to accommodate only fixed size records. In this case, the block header is still 24 bytes and contains the common length of the records in the block.
How many records of size 50 bytes could we fully fit in such a block?

(a) 20 records, 50 bytes, 20 records
(b) 18 records, 46 bytes, 20 records
(c) 20 records, 46 bytes, 25 records
(d) 50 records, 50 bytes, 20 records

Answer:
(b) 18 records, 46 bytes, 20 records

(i) Given,
Block size – 1024 bytes
Block header size – 24 bytes
Record size – 50 bytes
Pointer to each record – 4 bytes
Number of records = floor {Block size / records} ----- Eq. 1
But in the given case, we need to consider the block size after deducting the header size. And for each record we need to add 4 bytes pointer size because it is given that pointer for each record. Hence Eq 1 is now as follows;
Number of records = floor {(Block size – Header size) / (Record size + Pointer size)}
Number of records = floor { (1024 – 24) / (50 + 4)} = 18 records

(ii) For finding the size of record, we need to find the size left with us in each block. When we deduce the block header size and the size required for 20 pointers from block size, what we get is the size completely available for storing records.
(Block size – Header size – 4*20) will give us the available block space
Number of records = floor { (1024 – 24 – 4 * 20) / x}
20 = floor { (1024 – 24 – 4 * 20) / x}
x = floor { (1024 – 24 – 4 * 20) / 20} = floor{980/20} = 46 bytes

(iii) In this case, the record size becomes fixed. Hence, we do not need pointers to each record. The extra memory 4 bytes can be saved. The number of records can be calculated using Eq. 1 as follows;
Number of records = floor {(Block size – Header size) / Record size}
Number of records = floor { (1024 – 24) / 50} = 20 records



         Previous Question                                                                                Next Question






No comments:

Post a Comment