Previous Table of Contents Next


Data Spaces

Data spaces contain the database records. The records in a given data space are homogeneous and fixed in length. In other words, all records in the same data space look alike. The records are stored in arrival sequence, and all records that have been deleted still occupy space.

Three types of segments make up a data-space object. In addition to the base and associated space segments, up to 120 data-space records segments can be part of this object. The data-space records segments, as their name implies, contain the database records. Each entry in a data-space records segment has a status byte and one database record. The status byte provides information about the record, such as its validity, or whether it has been deleted.

Each record in a data-space records segment has a number, called the ordinal number. The ordinal number identifies the record position in the segment. Do not confuse ordinal number, which starts again with each segment, with the more familiar relative record number, as it is often referred to at the OS/400 level. The relative record numbers contained in a logical file or a view indicate the location of the data in the physical file or table. These same numbers are sometimes called the data-space entry numbers in the MI.

Starting with zero, the ordinal number identifies whether the record is the first, second, or nth one in the segment. Because all records are fixed in length, the ordinal numbers do not have to be stored in the segment. By knowing the ordinal number and the length of each record, we can find the starting byte location of any record in the segment. We will see shortly how the ordinal number is used to locate records in the database.

The base segment does contain information about the data space, but its primary role is to contain the addresses of the many data-space records segments. The base segment also contains the addresses of the data-space indexes that are used with this data space.

The associated space contains the field descriptor table, which provides the description of each field in the record. The associated space also contains a work area that the OS/400 part of the database uses. For example, pointers to logical cursors are kept in the associated space.

Data-Space Indexes

A data-space index provides an alternate ordering for the records in a data space. A binary radix tree is used to provide the alternate ordering. Later in the chapter, in the “Binary Radix Trees” section, we look at the implementation of such a tree and see how it is used to support several functions on the AS/400, including the data-space index.

Numerous options are available for arranging the data-space index. A data-space index supports variable length keys. The value of the keys can be calculated using a variety of operators such as concatenate, add, subtract, and multiply. You can build a data-space index over as many as 32 data spaces. Options for ordering the index include ascending, descending, numeric, and absolute value. Finally, there are the maintenance options. Updates to the index can be applied immediately, or they can be delayed. Delaying updates to an index saves the overhead of maintaining it when a change to the underlying data space occurs and the index is not being used.

In Chapter 5, we briefly looked at examples of objects, including a data-space index. We saw that a data-space index was composed of three segment types: a base segment, an associated space segment, and a delayed-maintenance segment. We have already discussed the latter two segments, but we need to take a little closer look at the base segment.

The base segment contains the attributes of the alternate collating sequence this index provides. The base segment has a table that describes the way the index views each field in the record of the data space. This is the logical-view description. The base segment also contains up to 32 addresses to data spaces that this index can cover. Finally, the base segment contains the binary radix tree.

The binary radix tree may not totally fit into the base segment. To accommodate a very large tree, you can attach a fourth segment type to contain portions of the tree. In fact, up to 64 of these tree segments can be attached to a data-space index.

Each key stored in a tree segment has the byte string containing the actual key value, followed by a pair of fields that serve as a suffix for the key. The pair of fields is generally called the relative address. The first field contains the data-space number and the identification of the data-space records segment. The second field contains the ordinal number of the record in the segment. These two numbers uniquely identify the record associated with the key, and this ID is analogous to the relative record number in the logical file or view.

Cursors

A cursor provides the mechanism to view data in the data space; all data access is via cursors. The cursor we are describing in this section is an MI system object. DB2/400 supports both scrollable and sequential file cursors as defined in the 1992 SQL standard. This SQL cursor is not the same as the MI system object known as a cursor, although the MI system object is used to support the SQL cursor.

As described earlier in this chapter, records for a physical file are stored in members. A physical file can have one or more members. Members provide a convenient way to partition data in a single physical file. Logical files use this same multimember concept. We also saw that SQL tables and views are limited to a single member per table or view. A cursor is identified with each file member. A cursor can provide access to the data-space records in arrival sequence or in keyed sequence using an index. In other words, a cursor can point directly to a data space, or it can point to a data space through a data-space index. A single cursor can cover multiple data spaces, and there can be multiple cursors over the same data space. A cursor keeps track of the position in an access path held by a program (or job or activation group). This function helps explain why a cursor is called a cursor.

A cursor can also provide a mapping to and from a data space. The mapping allows the data to be viewed differently from the way it is stored in the data space. Examples of the kinds of mapping are field renaming, arithmetic and character-string expressions, and data-type conversions.


Previous Table of Contents Next

Copyright © NEWS/400 Books