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
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
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:
The segment the application is trying to retrieve is the COURSE
segment, because the segment contains the names of courses (COURSENM
field). Therefore, COURSE is the target segment, and needs retrieval.
In this example, the application program is going to use the student's
name in its DL/I call to retrieve the COURSE segment. The DL/I call
is qualified using student name as its qualifier. The source segment
contains the fields used to sequence the pointer segments in the secondary
index. In this example, the pointer segments must be sequenced by
student name. The STUDENT segment becomes the source segment. It is
the fields in this segment that are copied into the data portion of
the pointer segment as the key field.
The call from the application program starts a search for a pointer
segment with a key field that matches the student name. After the
correct pointer segment in the index is found, it contains the address
of the COURSE segment the application program is trying to retrieve.
Figure 3. Education database record
The following figure shows how the pointer, target, and source
segments work together.
Figure 4. How a segment is accessed
using a secondary index
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.