7.1 Equivalent value Search

 

SQL

SELECT *
FROM Orders
WHERE CustomerID='MAISD'

SPL

For a string type primary key field containing ID values, such as CustomerID, equivalent value search is most used and the interval-based search is seldom used. For equivalent value search, both hash index and sorting index work well.

Hash index:

A
1 =file(“Orders.ctx”).open()
2 =A1.index(idh:1000000;CustomerID)
3 =A1.icursor(;CustomerID==“MAISD”).fetch()

A2 Create index on CustomerID field of A1’s composite table and name it idh. 1000000 defines range of hash values in the hash index. Whenever the parameter is present, the index is a hash index.
A3 icursor() function performs filtering on the composite table according to the index-based condition and returns a single cursor.

Sorting index:

A
1 =file(“Orders.ctx”).open()
2 =A1.index(ids;CustomerID)
3 =A1.icursor(;CustomerID==“MAISD”).fetch()

A2 Without the parameter specifying hash value range, the index is by default a sorting index.

Using sorting index to perform equivalent value search requires binary search on each level of index, making it slightly slower than hash index, which locates target records directly. During searching on external storage, much of the time is spent on data retrieval instead of CPU computation, so the gap between the two types of indexes is not big. Since sorting index is more widely applicable, most indexes on external storage are sorting indexes. The hash index is only used in a few scenarios demanding extremely high performance and only requiring equivalent value search.