INDEX

Synopsis

HELP:   Activate and define indexing for the column
TYPE:   OBJECT
SYNTAX: INDEX(METHOD=BF1/BF2/BF3/BF4,DATOFS=num,DATLEN=num,SIGLEN=num/SL1/SL2/SL4/SL8/SL16/SL32/SL64/SL128/SL256/SL512/SL1024/SL2048/SL4096/SL8192,PRIKEY,DISTINCT=num,FPRATE=num)

Description

This object can be used to activate indexing for a column. Bloom filters are used for indexing: for each value of the column, 1 to 4 hashes (METHOD BF1 to BF4) each set one bit in a partial signature of SIGLEN bytes per segment, which provides 8 times SIGLEN bit positions.

A search compares its value against these signatures and reads only the segments whose signature can hold it. A false positive costs one segment which is read and decompressed without holding the value; it never returns a wrong record, because the records of a hit segment are compared afterwards. The quality of the index is therefore its false positive rate, and it depends on the number of DIFFERENT values of the column per segment (not on the number of rows, which is only an upper bound).

With n different values per segment, k hashes and m = 8 * SIGLEN bit positions, the false positive rate is (1 - e^(-k*n/m))^k:

 signature per different value       BF1     BF2     BF3     BF4
 1/4 byte  (m = 2*n)                 39 %    40 %    47 %    56 %
 1/2 byte  (m = 4*n)                 22 %    15 %    15 %    16 %
 1 byte    (m = 8*n)                 12 %     5 %     3 %     2 %
 2 byte    (m = 16*n)                 6 %     1.4 %   0.5 %   0.2 %

More hashes are not better in general: up to about 2 bits per different value 1 hash is the best choice, from about 6 bits per value 4 hashes are. For a fixed rate more hashes need a SMALLER signature: 5 percent needs 19.5 bits per value with BF1 but 6.3 bits with BF4.

Automatic sizing

When writing, METHOD and SIGLEN do not have to be given. They are then determined when the first segment of the row is written, from the number of records per segment (MAXREC, which FLAM determines itself if not given), the upper bound of different values (DISTINCT) and the accepted false positive rate (FPRATE in per mille, 50 = 5 percent by default):

FPRATE is the share of segments a search on this column reads for nothing. A member with many segments needs a small rate: with 100000 segments, 50 per mille read 5000 segments per searched value in vain, 1 per mille still 100. BF4 needs 6.3 bits per value at 50, 10.6 at 10 and 20.5 at 1 per mille.

SIGLEN is rounded up to the next power of two, at least 4 bytes (the former default, because with fewer bit positions short similar values collide more often than the formula says) and at most 8192 bytes. If this limit binds, a warning is written: the rate is then above FPRATE, and a partial index (DATOFS/DATLEN), fewer records per segment (MAXREC) or a smaller DISTINCT is the better choice. The values chosen are written into the segment header; the row specification listed by the INFO or LIST command shows them, and they can be copied into the row specification to freeze them.

The sizing happens once per archive, when a row is written into the archive for the first time. A row specification that is already in the archive keeps its indexing: every further member written with the same row specification takes METHOD and SIGLEN from the archive, even if it has another number of records per segment. A search uses one indexing per row specification, so it must not differ between members.

DISTINCT is the number of different values of this column over the whole data, for example 10 for a currency or 3 for a status. Leave it out for a key or an account number, where every value can differ. A value that is too small does not cause an error but a saturated filter that answers every search with "maybe", so the search reads all segments again. When in doubt, give a larger value or none.

A search takes the indexing from the archive, so it does not have to be specified there. Only a search without row and column names (see sample 2 below) and a filter that is built without an archive have to give METHOD and SIGLEN exactly as they are in the archive; LIST shows them.

The signature of a segment is the sum of the partial signatures of all indexed columns of the row and may not exceed 1028196 bytes; a row specification beyond this limit is refused.

Within one member all segments of a row carry the same indexing. When a member is extended or modified, new segments of a row take the indexing of the first segment of this row in the member, because records are located for insert, update and delete by their signature. To change the indexing of a member, write it new (MBRMODE=OVERWRITE). A member that already holds different indexings for one row is reported with a warning; records in the segments with the other indexing are no longer found for insert, update or delete until the member is written new.

Normally the entire content of a column is hashed per line. If you want to restrict this, you can define an offset for the starting point and a length to let the hash be calculated only over a part of the date. The latter is mainly intended for defining only one column for whole records and performing indexing quasi like a VSAM KSDS.

If a KSDS or any record-oriented dataset is read with KEYLEN and KEYPOS (note: KEYPOS started with 1 but DATOFS started with 0) and no explicit row specification has been specified, the following row specification is automatically added if the record is still unchanged.

   ROW(NAME='STDREC' COLUMN(NAME='RECORD' INDEX(DATLEN=llll DATOFS=oooo PRIKEY) LOOKUP))

This means that the indexing of a KSDS is automatically transferred (DATLEN=KEYLEN, DATOFS=KEYPOS-1) to the archive. If this is not desired, a corresponding row specification must be specified for table name STDREC.

Several indexed columns can represent a primary key for a data record, which is important for inserts, updates and deletes. This can be indicated using the PRIKEY keyword. All indexed columns marked in this way are later used to create a signature in order to update, insert or delete a record. If the LOOKUP switch has also been set for the same columns, the record comparison is carried out via a hash table when a matrix has been hit. This is much faster with a large number of records in the matrix, but also consumes more memory.

To search later in the archive you only need to enter the same name for the row specification and also only need to describe each column that is required for the signature calculation in the same way, which is often done in CSV format, as this is the easiest way to enter the data. The non-indexed columns can be omitted here and the column names must match to determine the correct offset for the partial signature.

The examples below shows the 2 different possibilities to match 2 of n indexed columns:

  #SAMPLE 1: with only the 2 required columns and correct columns names#
  MATCH.DATA(FORMAT=CSV ROW(NAME='BBK50'
      COLUMN(NAME='ARCHTRX-MSGID-IN' )
      COLUMN(NAME='ARCHTRX-MSGID-OUT')
    )
    RECORD='"NOLADE20XXX110815102443SCT001","20110815-600000-001"'
    SUBSET)

  #SAMPLE 2: with only the 2 values matching all columns of this kind#
  MATCH.DATA(FORMAT=CSV ROW(NAME='*'
      COLUMN(NAME='*' INDEX(METHOD=BF4 SIGLEN=128))
      COLUMN(NAME='*' INDEX(METHOD=BF4 SIGLEN=128))
    )
    RECORD='"NOLADE20XXX110815102443SCT001","20110815-600000-001"'
    SUBSET)

If you specify the format and column names, FLAM determines the indexing based on the format information from the archive. If you search across all columns and formats, the indexing for the columns of the formats cannot be determined and therefore the indexing must be specified.

Arguments