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(file(“Orders.ctx__idh”):1000000;CustomerID) |
3 | =A1.icursor(;CustomerID==“MAISD”;file(“Orders.ctx__idh”)).fetch() |
4 | =A1.close() |
A2 Create index on CustomerID field of A1’s composite table and name the index file Orders.ctx__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(file(“Orders.ctx__ids”);CustomerID) |
3 | =A1.icursor(;CustomerID==“MAISD”;file(“Orders.ctx__ids”)).fetch() |
4 | =A1.close() |
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.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL