Performance Optimization - 1.6 [In-memory search] Index on in-memory table

 

Performance Optimization - 1.5 [In-memory search] Multi-layer sequence number positioning

The indexes on the table sequence are all for the primary key, and the primary key values are required to be unique across the entire table. If the TBS key is not primary key, or its values are not unique, resulting in a failure to establish it as primary key, what should we do?

Let’s examine the working principles of the algorithms mentioned earlier. Neither binary search nor hash index requires the value of the TBS key to be unique in the entire table. SPL currently does not provide non-primary key index on table sequence in order to keep table sequence simple. Index only makes sense when the amount of data is large, and is often only used in read-only data scenarios. However, table sequence is not always used in scenarios with large amounts of data, it often involves update actions, and index also needs to be updated accordingly, which is very cumbersome. Moreover, there may be more than one non-primary key index, yet too many indexes on a table sequence will make it too heavy and unsuitable for small data and more flexible application scenarios.

SPL specifically provides an in-memory data table derived from table sequence, which is called in-memory table and mainly used in scenarios with large amounts, and allows us to establish non-primary key index to achieve fast search.

A
1 =200000.new(~:id,rand(1000000):K,…)
2 =A1.memory()
3 =A2.index(IDX;K)
4 =A2.icursor(;K==123456;IDX).fetch()
5 =A2.icursor(;K>=123456 && K<=654321;IDX).fetch()

When establishing an index, you need to give it a name. When using the corresponding index to search, icursor will return the result as a cursor, which then needs to be fetched with fetch to keep the index of in-memory table consistent with that of the data table in external storage. The working principles and application characteristics of these indexes will be explained in “Search in external storage”.


Performance Optimization - 2.1 [Dataset in external storage] Text file segmentation
Performance Optimization - Preface