Variable-length records arise in a database in several ways:
Storage of multiple items in a file
Record types allowing variable field size
Record types allowing repeating fields
We'll look at several techniques, using one example with a variable-length
record:
Account-information is an array with an arbitrary number of elements.
Byte string representation uses the technique of attaching a special
end-of-record symbol () to the end of each record.
Then we can store each record as a string of successive bytes.
(See figure 7.9)
Byte string representation has several disadvantages:
It is not easy to re-use space left by a deleted record
In general, there is no space for records to grow longer.
(Must move to expand, and record may be pinned.)
So this method is not usually used.
Fixed-length representation uses one or more fixed-length records
to represent one variable-length record.
Two techniques:
Reserved space - uses fixed-length records large enough to
accommodate the largest variable-length record.
(Unused space filled with end-of-record symbol.)
Pointers - represent by a list of fixed-length records,
chained together.
The reserved space method requires the selection of some maximum record
length. (figure 7.10)
If most records are of near-maximum length this method is useful.
Otherwise, space is wasted.
Then the pointer method may be used (figure 7.11).
Disadvantage is that space is wasted in successive records in a chain
as non-repeating fields are still present.
To overcome this last disadvantage we can split records into two blocks
(See figure 7.12)
Anchor block - contains first records of a chain
Overflow block - contains records other than first in the chain.
Now all records in a block have the same length, and there is
no wasted space.