6: Costs in File Handling Flashcards Preview

207: Databases > 6: Costs in File Handling > Flashcards

Flashcards in 6: Costs in File Handling Deck (11)
Loading flashcards...
1

How are files stored on a disk?

Similar to a relational table, they also have indexes associated with them, and are stored on the disk to improve efficiency of retrieval.

2

What are the steps for storing a file or index on a disk ?

1. Formatting disk
2. Dividing disk into pages (equal size blocks, between 512 to 4096 bytes)
3. The block forming the unit of transfer between disk (secondary storage) and main memory (primary storage in buffers). Buffer size = 1 block.

Can hold more from secondary storage - 'cluster' - several contiguous blocks on disk which can be transferred as a single unit to be held in one buffer. This can be done by adjusting the byte-size of the buffer to match the byte-size of the cluster. (magic)

3

What is spanned organisation ?

When part of a record is stored in one block and a pointer is used within the block to point to the rest of the record in another block.

Used for variable length records.

4

What's an unspanned organisation ?

When a record must fit entirely within one block ie record-size cannot exceed block-size.

Used for fixed-length records, ie when B>=R. (Can also be used for variable-length records).

5

How is data held in a block on a disk found ?

By using an address, that specifies the:

- Surface number
- Track number (within the surface)
- Block number (within the track)

6

How long does it take to retrieve a block and store it in a buffer ?

It takes the sum time of the following actions:

- Seek time: taken to move read/write head over the track required in the address

- Rotational Delay (latency): time taken for the beginning of the block required in the address to rotate into position under the read/write head.

- Block Transfer time: taken to transfer the data block to the buffer

Total retrieval time = seek time + latency + block transfer time.

Usually seek time and latency are much larger than block transfer time.

7

What are the factors to consider when calculating the costs of storing records?

- Block Size B [bytes]
- Record Size R [bytes]
- Blocking Factor B/R [bfr] ie the number of records in a block, rounded down

8

How many blocks are needed to store the file on disk? Given:

- Block Size (B) = 512 bytes
- Record Size (R) (fixed length) = 128 bytes
- Relation (‘File’) Size (F) = 50 records

50*128 = 6400 bytes in total required.

6400/512 = 12.5 blocks required => 13 in total, 12 full blocks holding 4 records per block, plus 1 block extra to hold the remaining 2 records.

------------------------------------

512/128 = 4 records in one block
50/4 = 12.5 = 13 blocks

9

How many blocks are required to store an index on disk for the relation given?

- Block Size (B) = 512 bytes
- Record Size (R) (fixed length) = 128 bytes
- Relation (‘File’) Size (F) = 50 records

There is one index entry per block:
Key-Field Size = 20 bytes
Pointer-Field Size = 10 bytes

20 + 10 = 30 extra bytes per block.

We have 13 blocks: 30*13 = 390 bytes.

390/512 = 0.762 => 1 block

------------------------------

128+30 = 158 bytes

158*50 = 7900

7900/512 = 15.5 bytes/block

Therefore, we need 15.5-12-5 = 3 records to store an index of 30 bytes per block.

3/4 = 0.75 => 1 block.

10

What is the cost (in terms of blocks) to store the following file on disk:

Block Size = 512 bytes
Record Size (fixed length) = 75 bytes
Relation Size = 325 records

75*325 = 24375 bytes

24375/512 = 47.6 => 48 blocks required.

Wrong way
-------------------------------

512/75 = 6.826 records per block => 6 rounded DOWN
325/6 = 54.1 => 55 blocks rounded UP

11

What is the cost (in terms of blocks) to store the following file on disk:

Block Size = 512 bytes
Record Size (fixed length) = 75 bytes
Relation Size = 325 records

Index Entry = 1 per block Key-Field size = 25 bytes Pointer-Field Size = 10 bytes

55 * 35 = 1925

1925/512 = 3.7597 => 4 blocks