Segments used for secondary indexes

To set up a secondary index, three types of segments must be defined to IMS: pointer, target, and source segments.

The following figure illustrates the segments used for a secondary index.
Figure 1. Segments used for secondary indexes
begin figure description. This figure is described in the surrounding text. end figure description.
Pointer Segment
The pointer segment is contained in the secondary index database and is the only type of segment in the secondary index database. Its format is shown in the following figure.
Figure 2. Format of pointer segments contained in the secondary index database
Prefix has one delete byte followed by four bytes for RBA of the segment to be retrieved. Data portion has a key field followed by optional fields and then a symbolic pointer to the segment to retrieve.

The first field in the prefix is the delete byte. The second field is the address of the segment the application program retrieves from the regular database. This field is not present if the secondary index uses symbolic pointing. Symbolic pointing is pointing to a segment using its concatenated key. HIDAM and HDAM can use symbolic pointing; however, HISAM must use symbolic pointing. Symbolic pointing is not supported for PHDAM and PHIDAM databases.

For a HALDB PSINDEX database, the segment prefix of pointer segments is slightly different. The RBA of the segment to be retrieved field is part of an Extended Pointer Set (EPS), which is longer than 4 bytes. Within the prefix, the EPS is followed by the key of the target's root.

For a DEDB database, the pointer segments must be symbolic.

Target Segment
The target segment is in the regular database, and it is the segment the application program needs to retrieve. A target segment is the segment to which the pointer segment points. The target segment can be at any one of the 15 levels in the database, and it is accessed directly using the RBA or symbolic pointer stored in the pointer segment. Physical parents of the target segment are not examined to retrieve the target segment, except in one special case discussed in Symbolic pointer field.
Source Segment
The source segment is also in the regular database. The source segment contains the field (or fields) that the pointer segment has as its key field. Data is copied from the source segment and put in the pointer segment's key field. The source and the target segment can be the same segment, or the source segment can be a dependent of the target segment. The optional fields are also copied from the source segment with one exception, which is discussed later in this topic.
Restriction: A DEDB database with sequential dependent (SDEP) segments can have a secondary index database. However, SDEP segments cannot be used as target or source segments for a Fast Path secondary index.

In the full-function education database shown in the following figure, three segments work together. The education database is a HIDAM database that uses RBAs rather than symbolic pointers. Suppose an application program needs to access the education database by student name and then list all courses the student is taking:

Figure 3. Education database record
Database record with root COURSE. Below COURSE is CLASS segment. Below CLASS are segments INSTR and STUDENT.

The following figure shows how the pointer, target, and source segments work together.

Figure 4. How a segment is accessed using a secondary index
begin figure description. This figure is described in the surrounding text. end figure description.

The call that the application program issues when a secondary index is used is GU COURSE (XNAME = BAKER ... ).

XNAME is from the NAME parameter in the XDFLD statement.

COURSE is the target segment that the application program is trying to retrieve.

STUDENT is the source segment containing one or more fields that the application program uses as a qualifier in its call and that the data portion of a pointer segment contains as a key.

The BAKER segment in the secondary index is the pointer segment, whose prefix contains the address of the segment to be retrieved and whose data fields contain the key the application program uses as a qualifier in its call.