version 6.5 (Modified)
SET INDEX (field; index{; mode{; *}})
Parameter | Type | Description | |
field | Field or Subfield | Field for which to create or delete the index | |
index | Boolean | Create index (TRUE) or Delete index (FALSE) | |
mode | Longint | Indexing mode (in percentage) | |
* | Asynchronous indexing if * is passed |
Description
The SET INDEX command creates or removes the index for the field or subfield you pass in field.
To index the field or subfield, pass TRUE in index. If the index already exists, the call has no effect. To delete the index, pass FALSE. If the index does not exist, the call has no effect.
SET INDEX will not index locked records; it will wait until the record becomes unlocked.
Starting from version 6.5, 4D allows you to now choose between two index modes: the "traditional" mode, which is the mode used in previous versions of 4D, and the new "fast" mode, which in most cases allows for a significant increase in speed. For more information, refer to the 4D Design Reference manual.
You select the index mode to use by choosing whether to pass the optional mode parameter. The mode parameter is only used if the command is able to actually create the index (that is if the index parameter is True).
If you don't pass the mode parameter, the indexing will be performed in traditional mode. In this case, since indexing is done in a separate process, the database remains available for use during this time. If an operation that uses the index is executed while the index is being built, the index will not be used. To determine if a field has been indexed, use the GET FIELD PROPERTIES command.
If you pass the mode parameter, the command will use the fast mode. In this case, it will not be possible to modify the data of the table during the indexing process.
You must pass an Integer value that represents a percentage to the mode parameter. This value allows you to indicate the usage type for which you want the index to be most efficient. It must be between the following limits:
- mode = 0: the index will be most efficient when adding or inserting records.
- mode = 100: the index will be most efficient when performing queries.
The optional * parameter indicates an asynchronous (simultaneous) indexing. Asynchronous indexing allows the execution of the calling method to continue immediately, whether or not indexing is completed. However, execution will halt at any command that requires the index.
Examples
1. The following example indexes the field [Customers]ID with the classical mode:
UNLOAD RECORD([Customers]) SET INDEX ([Customers]ID; True)
2. You want to index the [Customers]Name field with the fast mode. This field is mainly used for queries:
SET INDEX ([Customers]Name; True;100)
2. You want to index the [Contacts]Name field with the fast mode. This field is mainly used for adding and inserting names, but also for queries:
SET INDEX ([Contacts]Name; True;30)
See Also
GET FIELD PROPERTIES, ORDER BY, QUERY.