Understanding Data Files
The transactional database engine stores information in data files. Inside each data file is a collection of records and indexes. A record contains bytes of data. That data might represent an employee’s name, ID, address, phone number, rate of pay, and so on. An index provides a mechanism for quickly finding a record containing a specific value for a portion of the record.
The transactional database engine interprets a record only as a collection of bytes. It does not recognize logically discrete pieces, or fields, of information within a record. To the transactional database engine, a last name, first name, employee ID, and so on do not exist inside a record. The record is simply a collection of bytes.
Because it is byte-oriented, the transactional database engine performs no translation, type verification, or validation of the data in a record—even on keys (for which you declare a data type). The application interfacing with the data file must handle all information about the format and type of the data in that file. For example, an application might use a data structure based on the following format:
1
4
4
Inside the file, an employee’s record is stored as a collection of bytes. The following diagram shows the data for the record for Cliff Jones, as it is stored in the file. (This diagram replaces ASCII values in strings with the appropriate letter or number. Integers and other numeric values are unchanged from their normal hexadecimal representation.)
The only discrete portions of information that the transactional database engine recognizes in a file are keys. An application (or user) can designate one or more collection of bytes in a record as a key, but the bytes must be contiguous inside each key segment.
The transactional database engine sorts records on the basis of the values in any specified key, providing direct access to return the data in a particular order. The transactional database engine can also find a particular record based on a specified key value. In the preceding example, the 25 bytes that contain a last name in each record might be designated as a key in the file. An application could use the last name key to obtain a listing of all the employees named Smith, or it could obtain a listing of all employees and then display that listing, sorted by last name.
Keys also allow the transactional database engine to access information quickly. For each key defined in a data file, the transactional database engine builds an index. The index is stored inside the data file itself and contains a collection of pointers to the actual data within that file. A key value is associated with each pointer.
In the preceding example, the index for the Last Name key sorts the Last Name values and has a pointer indicating where the record is located in the data file:
Normally, when accessing or sorting information for an application, the transactional database engine does not search through all the data in its data file. Instead, it goes to the index, performs the search, and then manipulates only those records that meet the application’s request.