Other File Operations for an Indexed File
Loading the Index into Memory
The demonstrations show how to manage the index on a disk. If the file is small, the whole index may be loaded into memory.
Record Deletion
In Chapter 6 we described a number of approaches to deleting records in variable-length record files that allow for the reuse of the space occupied by these records. Two more comments about record deletion are
- When a record is deleted from the data file, the corresponding entry from the index file should be deleted.
- Alternatively, we could simply mark the index record as deleted, just as we might mark the corresponding data record (as deleted).
Record Updating
- The update changes the value of the key field.
Both the index and data file may need to be reordered. The update is easiest to deal with if it is conceptualized as a delete followed by an insert (but the user needs not know about this).
- The update does not affect the key field.
The index does not need reordering, but the data file may. If the updated record is smaller than the original one, it can be re-written at the same location. If it is larger, then a new slot has to be found for it. The starting address of the rewritten record must replace the old address in the byte offset field of the corresponding index record.
†Last comment: Any time a simple index is too large to hold in memory, you should consider using
- A hashed organization if access speed is a top priority; or
- A tree-structured, or multilevel, index , such as a B-tree, if you need the flexibility of both keyed access and ordered, sequential access.