|
The Create Index operation (B_BUILD_INDEX) adds a key to an existing file.
The maximum number of key segments allowed depends on the file's page size. The following table shows these values:
16 * (# of segments)
If the new key specifies an ACS other than the default, use the following formula to determine the correct Data Buffer Length:
16 * (# of segments) + 265
Note
Key numbers must be unique to the file. They must also be valid. (The value of each key number must be less than the maximum number of key segments allowed for the file's page size.)
The MicroKernel allows you to assign specific key numbers when creating a key. This capability complements the ability to delete a key and not have the MicroKernel renumber all keys that have a key number greater than that of the deleted key. If an application drops an index and instructs the MicroKernel not to renumber higher-numbered keys, and a user then clones the affected file without assigning specific key numbers, the cloned file has different key numbers than the original.
If you define an ACS in the Data Buffer, the MicroKernel first checks for an existing ACS (using the name you specified) before adding it to the file. If the MicroKernel finds an existing ACS with the name you specified, the MicroKernel does not duplicate the ACS definition in the file, but does associate the ACS with the new key.
If you specify the Use Named ACS attribute in the Key Flags word, the MicroKernel uses the ACS name supplied in the Data Buffer to locate an ACS of the same name within the file, then assigns that ACS to the new key.
If a file is opened by more than one MicroKernel and a client initiates a Create Index process, remote clients can perform Get and Step operations on the same file while the MicroKernel creates the key.
If the key being created is not an AUTOINCREMENT key, the Get and Step operations of remote clients can have lock biases, and when the Create Index process is completed, you can update and delete the locked records without issuing additional read operations. This is possible because the MicroKernel does not have to change the images of the records in order to create the key.
However, if the key being created is an AUTOINCREMENT key, the MicroKernel has to both build the index and change every record with a zero value in the appropriate field. Remote clients that perform Get or Step operations without a lock bias before or during the key creation can receive Status Code 80 when they execute an update or delete operation after the successful completion of the key creation.
Also, the MicroKernel returns Status Code 84 if a client attempts to create an AUTOINCREMENT key while another client has locked a record. Similarly, the MicroKernel returns Status Code 85 if a client attempts to execute a Get or Step operation with a lock bias during index creation for an AUTOINCREMENT key by another client.
The MicroKernel immediately adds the new key to the file. The time required for this operation depends on the total number of records to be indexed, the size of the file, and the length of the new index.
If the Create Index operation is successful, the number of the new key is either the number you specified or one of the following:
You can use the new key to access your data as soon as the operation completes.
If the Create Index operation is unsuccessful, the MicroKernel drops whatever portion of the new index it has already built. The file pages allocated to the new index prior to the error are placed on a list of free space for the file and reused when you insert records or create another key.
If the operation fails during the creation of an AUTOINCREMENT key, any values that have already been altered remain altered. The MicroKernel can return the following status codes:
If processing is interrupted during the creation of a key, you can access the data in the file through the file's other keys. However, the MicroKernel returns a nonzero status code if you try to access data by the incomplete index. To correct this problem, drop the incomplete index with a Drop Index operation (32) and reissue the Create Index operation.
The Create Index operation has no effect on any file currency information.
|
Chapter contents
Prev topic: Create (14)
|