ADMIN_UTL_SORT stored procedure

The SYSPROC.ADMIN_UTL_SORT stored procedure sorts objects for parallel utility execution using JCL or the ADMIN_UTL_SCHEDULE stored procedure.

Environment

Begin general-use programming interface information.

ADMIN_UTL_SORT runs in a WLM-established stored procedures address space.

Authorization

To execute the CALL statement, the owner of the package or plan that contains the CALL statement must have one or more of the following privileges on each package that the stored procedure uses:

  • The EXECUTE privilege on the package for DSNADMUS
  • Ownership of the package
  • PACKADM authority for the package collection
  • SYSADM authority

The owner of the package or plan that contains the CALL statement must also have SELECT authority on the following catalog tables:

  • SYSIBM.SYSTABLEPART
  • SYSIBM.SYSINDEXPART
  • SYSIBM.SYSINDEXES
  • SYSIBM.SYSTABLES

Syntax

The following syntax diagram shows the SQL CALL statement for invoking this stored procedure:

>>-CALL--SYSPROC.ADMIN_UTL_SORT--(--max-parallel,--------------->

>--+-max-per-job-+-,--+-optimize-workload-+-,------------------->
   '-NULL--------'    '-NULL--------------'     

>--+-batch-execution-+-,--number-of-objects,--parallel-units,--->
   '-NULL------------'                                          

>--max-objects,--max-sequences,--return-code,--message--)------><

Option descriptions

max-parallel
Specifies the maximum number of parallel units. The actual number may be lower than the requested number based on the optimizing sort result. Possible values are: 1 to 99.

This is an input parameter of type SMALLINT and cannot be null.

max-per-job
Specifies the maximum number of steps per job for batch execution. Possible values are:
1 to 255
Steps per job for batch execution
null
Online execution

This is an input parameter of type SMALLINT. This parameter cannot be null if batch-execution is YES.

optimize-workload
Specifies whether the parallel units should be sorted to achieve shortest overall execution time. Possible values are:
NO or null
The workload is not to be sorted.
YES
The workload is to be sorted.

This is an input parameter of type VARCHAR(8). The default value is NO.

batch-execution
Indicates whether the objects should be sorted for online or batch (JCL) execution.
NO or null
The workload is for online execution.
YES
The workload is for batch execution.

This is an input parameter of type VARCHAR(8). The default value is NO.

number-of-objects
As an input parameter, this specifies the number of objects that were passed in SYSIBM.UTILITY_SORT_OBJ. Possible values are: 1 to 999999.

As an output parameter, this specifies the number of objects that were passed in SYSIBM.UTILITY_SORT_OBJ table that are found in the DB2® catalog.

This is an input and output parameter of type INTEGER and cannot be null.

parallel-units
Indicates the number of recommended parallel units.

This is an output parameter of type SMALLINT.

max-objects
Indicates the maximum number of objects in any parallel unit.

This is an output parameter of type INTEGER.

max-sequences
Indicates the number of jobs in any parallel unit.

This is an output parameter of type INTEGER.

return-code
Provides the return code from the stored procedure. Possible values are:
0
Sort ran successfully.
4
The statistics for one or more sorting objects have not been gathered in the catalog or the object no longer exists.
12
An ADMIN_UTL_SORT error occurred. The message parameter will contain details.

This is an output parameter of type INTEGER.

message
Contains messages describing the error encountered by the stored procedure. If no error occurred, then no message is returned.

The first messages in this area are generated by the stored procedure. Messages that are generated by DB2 might follow the first messages.

This is an output parameter of type VARCHAR(1331).

Additional input

In addition to the input parameters, this stored procedure reads the objects for sorting and the corresponding utility names from the created global temporary table SYSIBM.UTILITY_SORT_OBJ.

The following table shows the format of the created global temporary table SYSIBM.UTILITY_SORT_OBJ:

Table 1. Input for the ADMIN_UTL_SORT stored procedure
Column name Data type Contents
OBJECTID INTEGER A unique positive identifier for the object the utility execution is associated with. When you insert multiple rows, increment OBJECTID by 1, starting at 0 for every insert.
TYPE VARCHAR(10) Object type:
  • TABLESPACE
  • INDEXSPACE
  • TABLE
  • INDEX
  • STOGROUP
QUALIFIER VARCHAR(128) Qualifier (database or creator) of the object in NAME, empty or null for STOGROUP. If the qualifier is not provided and the type of the object is TABLESPACE or INDEXSPACE, then the default database is DSNDB04. If the object is of the type TABLE or INDEX, the schema is the current SQL authorization ID. If the object no longer exists, it will be ignored.
NAME VARCHAR(128) Unqualified name of the object.

NAME cannot be null.

PART SMALLINT Partition number of the object for which the utility will be invoked. Null or 0 if the object is not partitioned.
UTILITY_NAME VARCHAR(20) Utility name. UTILITY_NAME cannot be null.
Recommendation: Sort objects for the same utility.

Possible values are:

  • CHECK DATA
  • CHECK INDEX
  • CHECK LOB
  • COPY
  • COPYTOCOPY
  • DIAGNOSE
  • LOAD
  • MERGECOPY
  • MODIFY RECOVERY
  • MODIFY STATISTICS
  • QUIESCE
  • REBUILD INDEX
  • RECOVER
  • REORG INDEX
  • REORG LOB
  • REORG TABLESPACE
  • REPAIR
  • REPORT RECOVERY
  • REPORT TABLESPACESET
  • RUNSTATS INDEX
  • RUNSTATS TABLESPACE
  • STOSPACE
  • UNLOAD

Example

The following C language sample shows how to invoke ADMIN_UTL_SORT:

 #include    <stdio.h>
 #include    <stdlib.h>
 #include    <string.h>

/******************** DB2 SQL Communication Area ********************/
 EXEC SQL INCLUDE SQLCA;

 int main( int argc, char *argv[] )    /* Argument count and list    */
 {
   /****************** DB2 Host Variables ****************************/
   EXEC SQL BEGIN DECLARE SECTION;

   /* SYSPROC.ADMIN_UTL_SORT parameters                              */
   short int maxparallel;              /* Max parallel               */
   short int ind_maxparallel;          /* Indicator variable         */
   short int maxperjob;                /* Max per job                */
   short int ind_maxperjob;            /* Indicator variable         */
   char optimizeworkload[9];           /* Optimize workload          */
   short int ind_optimizeworkload;     /* Indicator variable         */
   char batchexecution[9];             /* Batch execution            */
   short int ind_batchexecution;       /* Indicator variable         */
   long int numberofobjects;           /* Number of objects          */
   short int ind_numberofobjects;      /* Indicator variable         */
   short int parallelunits;            /* Parallel units             */
   short int ind_parallelunits;        /* Indicator variable         */
   long int maxobjects;                /* Maximum objects per        */
                                       /* parallel unit              */
   short int ind_maxobjects;           /* Indicator variable         */
   long int maxseqs;                   /* Maximum jobs per unit      */
   short int ind_maxseqs;              /* Indicator variable         */
   long int retcd;                     /* Return code                */
   short int ind_retcd;                /* Indicator variable         */
   char errmsg[1332];                  /* Error message              */
   short int ind_errmsg;               /* Indicator variable         */

   /* Temporary table SYSIBM.UTILITY_SORT_OBJ columns                */
   long int objectid;                  /* Object id                  */
   char type[11];                      /* Object type (e.g. "INDEX") */
   char qualifier[129];                /* Object qualifier           */
   short int ind_qualifier;            /* Object qualifier ind. var. */
   char name[129];                     /* Object name (qual. or unq.)*/
   short int part;                     /* Optional partition         */
   short int ind_part;                 /* Partition indicator var    */
   char utname[21];                    /* Utility name               */

   /* Result set locators                                            */
   volatile SQL TYPE IS RESULT_SET_LOCATOR *rs_loc1;

   /* Result set row                                                 */
   long int resobjectid;               /* Object id                  */
   short int unit;                     /* Execution unit value       */
   long int unitseq;                   /* Job seq within exec unit   */
   long int unitseqpos;                /* Pos within exec unit or    */
                                       /* step within job            */
   char exclusive[2];                  /* Exclusive execution flag   */
   EXEC SQL END DECLARE SECTION;

   /******************************************************************/
   /* Set up the objects to be sorted                                */
   /******************************************************************/
   long int objid_array[4] = {0, 1, 2, 3};
   char type_array[4][11] = {"TABLESPACE", "TABLESPACE",
                             "TABLESPACE", "TABLESPACE"};
   char qual_array[4][129] = {"QUAL01", "QUAL01",
                              "QUAL01", "QUAL01"};
   char name_array[4][129] = {"TBSP01", "TBSP02",
                              "TBSP03", "TBSP04"};
   short int part_array[4] = {0, 0, 0, 0};
   char utname_array[4][21]= {"RUNSTATS TABLESPACE",
                              "RUNSTATS TABLESPACE",
                              "RUNSTATS TABLESPACE",
                              "RUNSTATS TABLESPACE"};

   int i = 0;                          /* Loop counter               */

   /******************************************************************/
   /* Assign values to input parameters                              */
   /* Set the indicator variables to 0 for non-null input parameters */
   /* Set the indicator variables to -1 for null input parameters    */
   /******************************************************************/
   maxparallel = 2;
   ind_maxparallel = 0;
   ind_maxperjob = -1;
   strcpy(optimizeworkload, "YES");
   ind_optimizeworkload = 0;
   strcpy(batchexecution, "NO");
   ind_batchexecution = 0;
   numberofobjects = 4;
   ind_numberofobjects = 0;

   /******************************************************************/
   /* Clear temporary table SYSIBM.UTILITY_SORT_OBJ                  */
   /******************************************************************/
   EXEC SQL DELETE FROM SYSIBM.UTILITY_SORT_OBJ;

   /******************************************************************/
   /* Insert the objects into the temporary table                    */
   /* SYSIBM.UTILITY_SORT_OBJ                                        */
   /******************************************************************/
   for (i = 0; i < 4; i++)
   {
     objectid = objid_array[i];
     strcpy(type, type_array[i]);
     strcpy(qualifier, qual_array[i]);
     strcpy(name, name_array[i]);
     part = part_array[i];
     strcpy(utname, utname_array[i]);
     EXEC SQL INSERT INTO SYSIBM.UTILITY_SORT_OBJ
                     (OBJECTID, TYPE, QUALIFIER, NAME, PART,
                      UTILITY_NAME)
              VALUES (:objectid, :type, :qualifier, :name, :part,
                      :utname);
   };

   /******************************************************************/
   /* Call stored procedure SYSPROC.ADMIN_UTL_SORT                   */
   /******************************************************************/
   EXEC SQL CALL SYSPROC.ADMIN_UTL_SORT
                        (:maxparallel       :ind_maxparallel,
                         :maxperjob         :ind_maxperjob,
                         :optimizeworkload  :ind_optimizeworkload,
                         :batchexecution    :ind_batchexecution,
                         :numberofobjects   :ind_numberofobjects,
                         :parallelunits     :ind_parallelunits,
                         :maxobjects        :ind_maxobjects,
                         :maxseqs           :ind_maxseqs,
                         :retcd             :ind_retcd,
                         :errmsg            :ind_errmsg);

   /******************************************************************/
   /* Retrieve result set when the SQLCODE from the call is +446,    */
   /* which indicates that result sets were returned                 */
   /******************************************************************/
   if (SQLCODE == +466)               /* Result sets were returned   */
   {
     /* Establish a link between the result set and its locator      */
     EXEC SQL ASSOCIATE LOCATORS (:rs_loc1)
              WITH PROCEDURE SYSPROC.ADMIN_UTL_SORT;

     /* Associate a cursor with the result set                       */
     EXEC SQL ALLOCATE C1 CURSOR FOR RESULT SET :rs_loc1;

     /* Perform fetches using C1 to retrieve all rows from the       */
     /* result set                                                   */
     EXEC SQL FETCH C1 INTO :resobjectid, :unit,
                            :unitseq, :unitseqpos, :exclusive;
     while(SQLCODE==0)
     {
       EXEC SQL FETCH C1 INTO :resobjectid, :unit,
                              :unitseq, :unitseqpos, :exclusive;
     }

     EXEC SQL CLOSE C1;
   }

   return(retcd);
 }

Output

This stored procedure returns the following output parameters, which are described in Option descriptions:

  • number-of-objects
  • parallel-units
  • max-objects
  • max-sequences
  • return-code
  • message

In addition to the preceding output, the stored procedure returns one result set that contains the objects sorted into parallel execution units.

The following table shows the format of the result set returned in the created global temporary table SYSIBM.UTILITY_SORT_OUT:

Table 2. Result set row for ADMIN_UTL_SORT result set
Column name Data type Contents
OBJECTID INTEGER A unique positive identifier for the object
UNIT SMALLINT Number of parallel execution unit
UNIT_SEQ INTEGER Job sequence within parallel execution unit
UNIT_SEQ_POS INTEGER Step within job
EXCLUSIVE CHAR(1) Requires execution with nothing running in parallel

End general-use programming interface information.