PARTITION Option

Only embedded structures can be partitioned. The embedded structure is partitioned based upon the value of an item in the disjoint data set that contains the embedded structure. The data item that controls the partitioning is the partition key. The partition key serves as the key of the partitioning set. The disjoint data set that contains the partition key and the partitioned structure is the partition master. The partition master must not be a compact data set.

Normally all of the records within a data set reside in a single file. This file must be present on disk or pack whenever the data set is in use. The records of a partitioned structure do not all reside in a single file. Instead, the records are divided or partitioned among several files. Only those files required for the current application need be present on disk or pack, while the remaining files can be stored on some backup medium. Partitioning is used for structures which would otherwise require very large files. It reduces the amount of disk or pack space required when only a small portion of the file is used at any single time.

There can be as many partitions as there are unique values of the partition key. The system automatically keeps track of the partitions that currently exist by using a structure called the partition directory. This directory is maintained by the Enterprise Database Server software in a data set called <database name>/PARTITIONINFO/DATA. Refer to Tailored File-Naming Conventions for naming conventions. You should not update the PARTITIONINFO data set.

The partition directory contains a record for each partition in the database. The first time a record in a partitioned structure is referenced after the value of the partition key has changed, the system automatically checks the partition directory to determine whether the partition exists. If the partition does exist, the file is opened and accessed in the typical manner. If the partition does not exist, the proper file is created, and a record for it is created in the partition directory. Subsequent references to the same partition seek records in the same partition file, thereby incurring very little overhead beyond that of a nonpartitioned structure.

The set name specified following the PARTITION keyword identifies the partitioning set. The key of the partitioning set must be an alpha item or a numeric item with a length of 17 characters or less. Alpha items must contain only letters and digits, and the contents of the item must be left-justified with blank fill. If the key contains embedded blanks or special characters, a data exception occurs at run time. The set can allow duplicates, but the keys of existing records must not be changed.

The SYSTEM/ACCESSROUTINES/FULL code file must be used for a database that uses the PARTITION option. You can copy SYSTEM/ACCESSROUTINES/FULL as SYSTEM/ACCESSROUTINES, or use the Accessroutines specification to designate SYSTEM/ACCESSROUTINES/FULL as the title of the Accessroutines code file.

Example 1

In this example, data set E is partitioned. The partition key P is contained in the partition master D, and set S is the partitioning set. All records of data set D reside in a single file. Data set E is divided in several files; one file exists for each unique value of P.

D DATA SET
 (
  P NUMBER(1);
  E UNORDERED DATA SET
   (
    A ALPHA(10);
    B BOOLEAN;
   )
    PARTITION ON S;
 );
S SET OF D KEY P;

Embedded structures at any level can be partitioned. No matter how deeply embedded the partitioned structure can be, the partition master is always the disjoint data set which contains the structure.

Example 2

In this example, data set F is partitioned. As in the previous example, P is the partition key, D is the partition master, and S is the partitioning set. Records of D reside in a single file, as do records of E. Records within F are partitioned among several files.

D DATA SET
 (
  P NUMBER(1);
  E UNORDERED DATA SET
   (
    N NUMBER(4);
    F UNORDERED DATA SET
     (
      A ALPHA(10);
     )
      PARTITION ON S;
   );
 );
S SET OF D KEY P DUPLICATES;

Example 3

If data set D contains three records—two of which contain the value 1976 in YEAR and one of which contains the value 1977—then there are two files each for data set E and set SE1. Records of data set E and set SE1 belong to one of the two files, depending on whether the value in their master record in data set D is 1976 or 1977. Similarly, data set F is partitioned based upon the value in REGION.

D DATA SET
 (
  YEAR    NUMBER(4);
  REGION  ALPHA(10);
  E DATA SET
   (
    X ALPHA(6);
    Y NUMBER(S5,2);
   )
    PARTITION ON S;
  SE1 SET OF E KEY IS X
      PARTITION ON S;
  SE2 SET OF E KEY IS Y;
  F UNORDERED DATA SET
   (
    Z FIELD(8);
   )
    PARTITION ON T,
    OPEN PARTITIONS = 3;
 );
S SET OF D KEY IS YEAR DUPLICATES;
T SET OF D KEY IS REGION;
Note: The Enterprise Database Server does not support the addition of a partitioned structure to an existing unpartitioned data set.