Compaq COBOL AAQ2G1FTK User Manual

Page 509

Advertising
background image

Optimizing Your Compaq COBOL Program

15.7 Optimizing File Design (OpenVMS)

15.7.3 Indexed Files

An indexed file contains data records and pointers to facilitate record access.

All data records and record pointers are stored in buckets. A bucket contains
an integral number of contiguous, 512-byte blocks. The number of blocks is the
bucket size.

Every indexed file must have a primary key, a field in the record description
that contains a value for each record. When the I/O system writes records to the
indexed file, it collates them according to increasing primary key value in a series
of chained buckets. Thus, you can access the records sequentially by specifying
ACCESS SEQUENTIAL.

As the I/O system writes records, it builds and maintains a tree-like structure of
key-value and location pointers. The highest level of the index is a single bucket,
called the root bucket. The I/O system scans one bucket at each level until it
reaches the bottom, or data level. In a primary key index, this level contains
actual data records. Buckets in each higher level, called index levels, contain
index records. Successive levels of an index file are numbered. The data level
is level zero. The number of levels above level zero is called the index depth.
Figure 15–2 shows a 2-level primary index.

Figure 15–2 Two-Level Primary Index

LEVEL 2

LEVEL 1

LEVEL 0

ZK−1540−GE

ROOT

BUCKET

An index is also built for each alternate key that you define for the file. Like
the primary index, alternate key indexes are contained in the file. The collating
and chaining done for primary keys are also done for alternate keys. However,
alternate keys do not contain data records at the data level; instead, they contain
pointers, or secondary index data records (SIDRs), to data records in the data
level of the primary index.

Each random access request begins by comparing a key value to the root bucket’s
entries. It seeks the first root bucket entry whose key value equals or exceeds the
value of the access request key. (This search is always successful, because the
root bucket’s highest key value is the highest possible value that the key field can
contain.) Once that key value is located, the bucket pointer is used to bring the
target bucket on the next lower level into memory. This process is repeated for
each level of the index.

One bucket is searched at each level of the index until a target bucket is reached
at the data level. The data record’s location is then determined so that a record
can be retrieved or a new record written.

Optimizing Your Compaq COBOL Program 15–19

Advertising