Nonstop Database, HiRDB Version 9 System Operation Guide
This example assumes that data for five recent months (May through September 2011) is stored in the ORDER table. The example uses the hash function HASH0 to delete the data for the earliest month, May 2011, from the RDAREA. Then, the example stores the data for the most recent month, October 2011. It is assumed that the matrix-partitioned table is partitioned as follows:
The following figure shows an example of allocating a different RDAREA each month (in the case of matrix partitioning).
Figure 13-89 Allocating a different RDAREA each month (in the case of matrix partitioning)
CREATE TABLE ORDER (FORMNO CHAR(6), CUSTCODE CHAR(5), PRODCODE CHAR(4) NOT NULL, ORDDATE CHAR(8) NOT NULL) PARTITIONED BY MULTIDIM (PRODCODE(('100')), FIX HASH HASHZ BY ORDDATE) IN ((RDA1,RDA2,RDA3,RDA4,RDA5), (RDA6,RDA7,RDA8,RDA9,RDA10));
Use either of the following methods to identify the RDAREA name.
(i) Execute the hash function for table partitioning
Use the HiRDB-provided hash function for table partitioning to identify the RDAREA that contains the data for May 2011, which is to be deleted. The table below shows the arguments of the hash function for table partitioning. For details about the hash function for table partitioning, see the HiRDB Version 9 UAP Development Guide.
No. | Argument | Specification value |
---|---|---|
1 | hashcode (hash function code) | p_rdb_HASH0(100) |
2 | ncol (number of partitioning key columns) | 1 |
3 | collst (partitioning key specification order, data type code, and data length code) | Data type code: PDSQL_CHAR Data length code: 8 |
4 | dadlst (data stored in the partitioning key) | Value of data type in No. 3 |
5 | ndiv (number of table partitions) | 5 |
6 | ncspace (national character for the double-byte space used at the HiRDB servers) | ncspace[0]: 0x81 ncspace[1]: 0x40 |
7 | flags (space conversion level and whether the facility for conversion to a DECIMAL signed normalized number is to be used) | 0 |
8 | rdno (partitioning condition specification order or sequence number in the partitioning key) | None |
When the above hash function for table partitioning is executed, rdno=1 is returned as the partitioning condition specification order.
(ii) Execute the SQL statement
Based on the result of the hash function for table partitioning, execute the following SQL statement to find the name of the RDAREA:
SELECT RDAREA_NAME,DCVALUES FROM MASTER.SQL_DIV_TABLE WHERE TABLE_SCHEMA='USER1' /* user name */ AND TABLE_NAME='ORDER' /* name of hash-partitioned table */ AND MOD(DIV_NO-1,5)+1 = 1 /* RDAREA definition order */
When this SQL statement is executed, RDA1 and RDA6 are returned as the names of the RDAREAs to be deleted, as shown in the following:
RDAREA_NAME DCVALUES# -------------------------- ---------------------- RDA1 100 RDA6 ********************* |
(i) Define CREATE PUBLIC FUNCTION
For the hash function HASH0, you can identify the RDAREA by pre-defining the following SQL statement:
CREATE PUBLIC FUNCTION HASH0 (DIVKEY VARCHAR(8)#, /* 'YYYYMMDD' or 'YYYYMM' */ NDIV INT) /* number of partitioning columns */ RETURNS INT BEGIN DECLARE DIVDATE DATE; SET DIVDATE = CASE LENGTH(DIVKEY) WHEN 6 THEN DATE(SUBSTR(DIVKEY,1,6)||'01','YYYYMMDD') ELSE DATE(DIVKEY,'YYYYMMDD') END; RETURN MOD(YEAR(DIVDATE)*12+MONTH(DIVDATE), NDIV)+1; /* return value */ END END_FUNC;
(ii) Execute the SQL statement
Execute the following SQL statement to find where the data for May 2011 is located:
SELECT RDAREA_NAME,DCVALUES FROM MASTER.SQL_DIV_TABLE WHERE TABLE_SCHEMA='USER1' /* user name */ AND TABLE_NAME='ORDER' /* name of hash-partitioned table */ AND MOD(DIV_NO-1,5)+1=HASH0('20110531',5) /* RDAREA definition order */
When this SQL statement is executed, RDA1 and RDA6 are returned as the names of the RDAREAs to be deleted, as shown in the following:
RDAREA_NAME DCVALUES# -------------------------- ---------------------- RDA1 100 RDA6 ********************* |
pdhold -r RDA1 pdhold -r RDA6 |
pdrorg -k unld -t ORDER -r RDA1 unload_control_file1 |
pdrorg -k unld -t ORDER -r RDA6 unload_control_file6 |
unload bes1:/pdrorg/unload_file1 /* bes1: Name of server that contains unload data file */ /* /pdrorg/unload_file1: Name of unload data file */
unload bes1:/pdrorg/unload_file6 /* bes1: Name of server that contains unload data file */ /* /pdrorg/unload_file6: Name of unload data file */
To delete the data for May 2011 (the data in RDA1 and RDA6), which is the earliest data, execute data loading with a data count of 0.
pdload -d ORDER load_control_file1 |
pdload -d ORDER load_control_file6 |
source RDA1 bes1:/pdload/load_file1 /* RDA1: Name of RDAREA on which data loading is to be performed with a data count of 0 */ /* bes1: Name of server that contains data file to be loaded with a data count of 0 */ /* /pdload/load_file1: Name of data file to be loaded with a data count of 0 */
source RDA6 bes1:/pdload/load_file6 /* RDA6: Name of RDAREA on which data loading is to be performed with a data count of 0 */ /* bes1: Name of server that contains data file to be loaded with a data count of 0 */ /* /pdload/load_file6: Name of data file to be loaded with a data count of 0 */
If a non-partitioning index that is not partitioned is defined for a partitioned table, batch-create non-partitioning indexes after pdload command execution.
pdrels -r RDA1 pdrels -r RDA6 |
If you use a UAP, for example, to insert the data for October 2011 after the command has executed, the data is stored in RDA1 and RDA6.
We recommend that you verify that the execution result is correct after the command has executed. For details about how to check the command's execution results, see the manual HiRDB Version 9 Command Reference.
All Rights Reserved. Copyright (C) 2011, 2015, Hitachi, Ltd.