Indexes

An index is a structure in a Btrieve file that contains the key values for a specific key. In an index, Btrieve dynamically maintains the key values in a sorted order, storing them in a balanced B-tree structure. When you insert, update, or delete a record, Btrieve adjusts all the indexes for the file to reflect the latest changes in the key values contained in the records.

Btrieve keeps all indexes to the data records in the form of standard B-trees. A B-tree is a data structure that allows external searching by means of multiway tree branching. The B-tree structure features quick access and efficient use of disk space. Once a B-tree structure is created, no periodic maintenance is required. Btrieve creates a separate B-tree for each key you define within a file.

You can create indexes when you are creating the Btrieve data file, or at any time thereafter. When you create a Btrieve data file, you can define one or more keys for Btrieve to use in building indexes.

You can also define external indexes (key-only files, described in Key-Only Files) for a Btrieve file after creating the file. Positioning rules (guidelines governing which record is current, which is next, and so on) are the same, regardless of when you create an index.

The total number of indexes (actually, the total number of key segments) for a file depends on the file's page size:

Page Size Maximum Key Segments

512

8

1,024

23

1,536

24

2,048

54

2,560

54

3,072

54

3,584

54

4,096

119

You can delete, or drop, an index when your application no longer needs it. The space that the index used in the file is freed for data or for other index pages. You can also use index balancing to conserve disk space (see Index Balancing).

If you create an index at file creation time, Btrieve stores duplicate values in the chronological order in which the records are inserted into the file.

IMPORTANT:  The chronological ordering of records can change when you update records and change their key values, when you drop and rebuild an index, or when you rebuild the Btrieve file. An application should not depend on the chronological ordering of records in a Btrieve file.

If you create a new index for a file that was created earlier, Btrieve enters duplicate values into the index in the order in which their corresponding records are physically stored in the file at the time the index is created. For linked-duplicatable keys, additional duplicate values are added to the end of the series of duplicates as new records are inserted.

How Btrieve stores duplicate key values in an index also depends on whether the key is a linked-duplicatable or a repeating-duplicatable key. For more information, see Linked-Duplicatable and Repeating-Duplicatable Keys.

You can also specify a key with an alternate collating sequence. For more information, see Alternate Collating Sequence.