Secondary indexesΒΆ

A secondary index allows the data in a keyed file to be accessed by different keys and in a different sequence from the main file. Secondary indexes are updated dynamically whenever data is inserted, amended or deleted from the file.

A secondary index is created by selecting a different field or fields to be the key. A secondary index key field may be either a key or a data field in the main file. A specified element of a main index subscripted field may also be selected to be a secondary index key field. The key fields are concatenated to form a key in the same way as in the main index, but with the difference that the key to a secondary index need not be unique. Records with identical values for the secondary index key are stored in ascending order of their main file key - the same order as that in which they appear in the main file index. Sculptor achieves this (and guarantees a unique key) by automatically adding the main index key fields to the secondary index fields. However, the values in the main key fields are ignored by the read[u] and readkey commands, which therefore always return the first record with the supplied secondary index key if that key is not unique.

Note

The total length of the secondary index fields and the main index fields cannot exceed 195 bytes.

Users should be aware that in future Sculptor will be modified so that the main keys are no longer appended; the order of records with identical secondary index keys will then be undefined. An option will be provided to convert existing secondary indexes so that they maintain their previous order.

The secondary indexes are located in a special directory which is automatically created for this purpose when the file is first created. The directory bears the same name as the data dictionary file, but with a .x extension. It is created as a subdirectory of the directory in which the data dictionary is located. The actual index file bears the same name as the index itself, but with a .k extension.

New indexes may be added to an existing file without loss of data. The data dictionary is amended to add the new index, and then the kfri or kfbuild program used to create the new index from the existing data.

File access commands have an optional index = clause which allows a secondary index to be specified for a search. If the clause is omitted, the main file index is used.

The main index or a secondary index may be rewound to the beginning or to the end by means of the rewind and wind commands.


RELATED TOPICS

Keyed files

Data dictionary editor

Data dictionaries

Keyed file utilities