bdfd1m1fDatabase Administration

Partitions

Figure 68 shows an example of three partitioned files. Seventy-eight blocks of a fixed file are subdivided into three partitions. The relative ordinal numbers in each partition are numbered starting at zero.

Figure 68. Partitioning: &SW00xxx: PTN, BOR, EOR, and EO#


Note:
For partitioned files, EOR must be set to the number of ordinals in the partition. EO# can be set to -1 or to a specific ordinal.

Advantages of Partitioned Files

You can easily add a new partition (for example, to accommodate a new set of customers) by doing the following:

  1. Increase the number of ordinals in the fixed file
  2. Reset the parameter EO# to the new number of ordinals (if not -1)
  3. Redefine the number of partitions in the DSECT macro (using &SW00PTN).

It is more difficult to increase the number of blocks in each partition. This requires a reorganization of the files.

Partitioning is appropriate when the number of subfiles in each table is likely to stay the same but the number of files might change.

Example of Partitioning

Suppose you maintain a set of customer name files. The customers live in three cities. Sometimes you need to access the customer LRECs directly and sometimes you need to process a set by city.

Assume that the number of customers is such that algorithm #TPFDB01 is appropriate. This means that you need 26 prime blocks for each file (partition).

Table 37 shows the customers allocated to ordinals in each file on the basis of the first character in their surname (algorithm #TPFDB01) and to a partition on the basis of which city they live in (Rome=1, Paris=2, London=3).

The total number of ordinals (blocks) required for all 3 partitions is 78 (26 x 3).

Table 37. Allocation in Partitioned File

Customer name City Partition number Ordinal number in the file (partition) Ordinal number in the fixed file
Adams Rome  1  0  0
Andrews Rome  1  0  0
Bernoulli Rome  1  1  1
Rodriquez Rome  1 17 17
Zerlini Rome  1 25 25
Andrews Paris  2  0 26
Zeisel Paris  2 25 51
Alans London  3  0 52
Zimmerman London  3  0 77

Coding the DSECT for Partitioned Files

The following statements are needed in the DSECT macro of a file, to allow application programs to access data in any of three partitions.

&SW00PTN SETC '3'         Number of partitions
&SW00EOR SETC '25'        Ending ordinal of partition 0
&SW00RBV SETC '#TPFDB01'  Addressing algorithm
&SW00EO# SETC '77'
Note:
&SW00PTN defines a set of three partitioned files. Code the remaining &SW00xxx fields, including &SW00RBV, as if the file were not partitioned.

The application program can specify which partition it is to access by using the PARTITN parameter in a DBOPN macro. For example:

DBOPN REF=zzzzzz,...,PARTITN=2

Alternatively, the program can omit the PARTITN parameter with the DBOPN macro and specify the partition by using the PARTITN parameter with other macros (for example, DBRED or DBADD). This is less controlled and is not recommended.

For C applications, a program accesses a partition using the dfopt function with the DFOPT_PARTITION option.

Adding a New Partition

To add a new partition to the fixed file (in the example, to add another city), allocate another 26 blocks and reset the EO# parameter in the DBDEF to 104:

EO#=104    Set total number of blocks in the fixed file

Also, update the &SW00PTN setting in the DSECT macro to 4:

&SW00PTN SETC '4'         Number of partitions (override)

Alternatively, you could override any DSECT setting of &SW00PTN by setting a parameter PTN in the DBDEF:

PTN=4     Set number of partitions