Understanding Fixed-Length Records
When all records in a file have the same size, they're called fixed-length records.
Example: Instructor Table
Let's say we have an instructor table with these fields:
ID: 5 characters (5 bytes)
Name: 20 characters (20 bytes)
Department: 20 characters (20 bytes)
Salary: 8 bytes for numbers
Total: 53 bytes per record
Sample Data:
Record 0: 10101 | Srinivasan | Comp. Sci. | 65000
Record 1: 12121 | Wu | Finance | 90000
Record 2: 15151 | Mozart | Music | 40000
Problems with Simple Storage
Problem 1: Block Boundary Crossing
-
If block size is 100 bytes and record size is 53 bytes
-
Block 1 can hold: Record 0 (bytes 0-52) + part of Record 1 (bytes 53-99)
-
Record 1 spans two blocks - need 2 disk reads for 1 record!
Problem 2: Deletion Issues
-
When you delete Record 1, what happens to the empty space?
-
If we move all records forward, it requires many disk operations
Solutions for Fixed-Length Records
Solution 1: Block-Aligned Allocation
-
Only store complete records in each block
-
Example: 100-byte block with 53-byte records = 1 record per block (47 bytes unused)
-
Wastes space but ensures no record spans blocks
Solution 2: Free List for Deletions Instead of moving records, maintain a list of deleted record positions:
Header → Points to first deleted record location
Deleted Record 1 → Points to next deleted record
Deleted Record 4 → Points to next deleted record
And so on...
Example of Free List:
File Header points to position 1
Position 1 (deleted) points to position 4
Position 4 (deleted) points to position 6
Position 6 (deleted) points to NULL
When inserting a new record:
-
Use the position pointed to by header (position 1)
-
Update header to point to next available position (position 4)