Enscribe Programmer's Guide

If there is enough similarity among records that the first records of successive blocks have
similar primary-key values, then key compression of index blocks is also desirable.
Key compression in data blocks is useful for alternate-key files where several alternate keys
tend to have the same value.
Index Compaction
A separate mechanism is also automatically used to make all index records more compact regardless
of whether key compression is in effect. Index compaction differs from key compression in that it
eliminates the trailing portion of similar records, whereas key compression eliminates the leading
portion.
In an index block of a key-sequenced file there is one index record for each block (data or index)
below it in the tree. This index record is formed by comparing the first primary key of the block
with the last primary key of the previous block. If the two keys are identical for the first N bytes,
then the first N + 1 bytes of the block-starting key are used for the index record. For example, with
the four data blocks:
ALLEN, HARRY FRASER, IAN JONES, JOHN LARIMER, JO
ARKIN, ALAN GAULT, WILLY KILMER,JOYCE LORE, KEVIN
: : : :
EICHER, DAVE HAM, JACK LAINE, LOIS MAILER, NORM
FRANKLIN, BEN JONES,JANE LANSON,SAM MARNER, SID
These three index records are actually written to disk:
FRAS
JONES, JO
LAR
File Creation Examples
The pages that follow present annotated examples showing how to create:
1. A key-sequenced file
2. A key-sequenced file with alternate keys
3. A key-sequenced format 2 file with alternate keys
4. An alternate-key file
5. A partitioned key-sequenced file
Example 1: Creating a Key-Sequenced File
This example shows how to create a credit file in which the individual records are to be accessed
by customer name.
The record format is:
timilecnalab-tnerrucsserddaeman
0
Byte Offset:
Primary-Key
Field
05124143143
With a record size of 150, selecting a block size of 2048 results in a blocking factor of 13 data
records per block:
N = (block-size - 32) / (record-size + 2)
13 = ( 2048 - 32) / ( 150 + 2)
76 Key-Sequenced Files