Sei sulla pagina 1di 7

c 

The RUNSTATS utility gathers summary information about the characteristics of data in table spaces, indexes,
and partitions. DB2® records these statistics in the DB2 catalog and uses them to select access paths to data
during the bind process. You can use these statistics to evaluate the database design and determine when
table spaces or indexes must be reorganized. To obtain the updated statistics, you can query the catalog
tables.

The two formats for the RUNSTATS utility are RUNSTATS TABLESPACE and RUNSTATS INDEX.
RUNSTATS TABLESPACE gathers statistics on a table space and, optionally, on tables, indexes or columns;
RUNSTATS INDEX gathers statistics only on indexes. RUNSTATS does not collect statistics for clone tables or
index spaces.

RUNSTATS can collect statistics on any single column or set of columns. RUNSTATS collects the following
two types of distribution statistics:


 
The percentage of rows in the table that contain a value for a column or combination of values for a set
of columns.
  
The number of distinct values in the column or set of columns.

When you run RUNSTATS TABLESPACE, you can use the COLGROUP option to collect frequency and
cardinality statistics on any column group. You can also collect frequency and cardinality statistics on any
single column. When you run RUNSTATS INDEX, you can collect frequency statistics on the leading
column of an index and multi-column frequency and cardinality statistics on the leading concatenated
columns of an index.

When you run RUNSTATS TABLESPACE, you can use the HISTOGRAM option, with the COLGROUP
option, to indicate that histogram statistics are to be gathered for the specified group of columns.
RUNSTATS TABLESPACE will ignore HISTOGRAM when processing XML table spaces and indexes.
When you run RUNSTATS INDEX, histogram statistics can only be collected on the prefix columns with
the same order. Key columns with a mixed order are not allowed for histogram statistics. RUNSTATS
INDEX will ignore HISTOGRAM when processing XML NODEID or VALUES indexes.





RUNSTATS updates the DB2 catalog with table space or index space statistics, prints a report, or both.


 


To execute this utility, you must use a privilege set that includes one of the following authorities:

÷ STATS privilege for the database


÷ DBADM, DBCTRL, or DBMAINT authority for the database. If the object on which the utility
operates is in an implicitly created database, DBADM authority on the implicitly created database
or DSNDB04 is required.
÷ SYSCTRL or SYSADM authority

An ID with installation SYSOPR authority can also execute the RUNSTATS utility, but only on a table
space in the DSNDB06 database.
To use RUNSTATS with the REPORT YES option, you must have the SELECT privilege on the reported
tables. RUNSTATS does not report values from tables that the user is not authorized to see.

To gather statistics on a LOB table space, you must have SYSADM or DBADM authority for the LOB
table space.

 
 c 

The RUNSTATS utility operates in the following phases:


 

Performs initialization
c 
Scans table space or index and updates catalog.

If you specify COLGROUP, RUNSTATS also performs a subtask that sorts one or more column
group's data. If you specify FREQVAL with COLGROUP or are collecting frequency statistics for data-
partitioned secondary indexes, RUNSTATS also performs a subtask that sorts the partition-level
frequency data.

c
Performs cleanup

÷     c     


The RUNSTATS utility control statement, with its multiple options, defines the
function that the utility job performs.

÷ j
 !c 
Certain activities might be required before you run the RUNSTATS utility, depending
on your situation.

÷ _ 
c 
DB2 uses the statistics that RUNSTATS generates to determine access paths to
data. If no statistics are available, DB2 makes fixed default assumptions.

÷  !" 



Changes to a table space can also change its space requirements and performance.
You can use RUNSTATS to update the table space statistics and then assess the
current status of the table space and decide whether to reorganize or redesign the
table space.

÷   !"
   
!

When RUNSTATS collects distribution statistics for columns groups, the utility
invokes DFSORTΠor a similar product to sort the distribution statistics. This sort
requires its own work data set. You can let this data set be dynamically allocated
through the SORT program, or you can allocate the data set through a DD statement
in the job JCL. The DD name is STATWK01.

÷  !  " 


You can run RUNSTATS on one or more single partitions of one or more table
spaces or indexes (including data-partitioned secondary indexes). When you run the
utility on a single partition of an object, RUNSTATS uses the resulting partition-level
statistics to update the aggregate statistics for the entire object.

÷ c
 !c  j  !
You can run RUNSTATS on the DB2 catalog to gather index space and table space
statistics for various catalog tables. DB2 uses the collected statistics on the catalog to
determine the access path for user queries of the catalog.

÷  # !c   


Certain activities might improve the performance of the RUNSTATS utility.

÷   !
  $      
When RUNSTATS collects frequency statistics on at least one data-partitioned
secondary index, the utility invokes DFSORT or a similar product to sort the statistics.
This sort requires temporary sort work data sets. You can let these data sets be
dynamically allocated through the SORT program, or you can allocate the data sets
through DD statements in the job JCL. The DD name is ST01WKOO.

÷  # !          


DB2 invalidates statements in the dynamic statement cache when you run
RUNSTATS on objects to which those statements refer.

÷   ! 


You can collect statistics history with the RUNSTATS utility.

÷   !  j" 


You can specify that RUNSTATS is to collect space statistics on a LOB table space
so that you can determine when the LOB table space should be reorganized. No
statistics on the LOB table space affect access path selection.

÷    c 


You can terminate and restart the RUNSTATS utility.

÷ c#%c 


RUNSTATS alters tables and columns in the catalog tables. When you specify
REPORT YES, RUNSTATS also generates a report of statistics that are gathered
during processing.

÷ 
 !c 
Certain activities might be required after you run the RUNSTATS utility, depending on
your situation.

÷  c     


Use the sample control statements as models for developing your own RUNSTATS
control statements.

 c     


Use the sample control statements as models for developing your own RUNSTATS control statements.

  &'  ! ! " %% !  !

The following control statement specifies that the RUNSTATS utility is to update the catalog with statistics for
table space DSN8D81A.DSN8S91E and all of its associated tables and indexes. When updating the table
statistics, RUNSTATS is to sample 25% of the rows. The SHRLEVEL change option indicates that DB2® is to
permit other processes to make changes while this utility is executing.

´´ 
 



  
´´
  
´´   
´´
   

´´   

     
 ! 
  !
 " #" $

   '  !   

The following control statement specifies that RUNSTATS is to update the catalog statistics for index
DSN8810.XEMPL1.


    !

  ('  !   %" !




The following control statement specifies that RUNSTATS is to update the catalog statistics for indexes
XEMPL1 and XEMPL2. DB2 does not permit other processes to change the table space that is associated with
XEMPL1 and XEMPL2 (table space DSN8S91E) while this utility is executing. This restricted access is the
default behavior.


      !

  )'  !  


 #"

The following control statement specifies that RUNSTATS is to update the catalog statistics for the following
columns in table space DSN8D91P.DSN8S91C:

÷ All columns in the TCONA and TOPTVAL tables


÷ The LINENO and DSPLINE columns in the TDSPTXT table

      !
  !
  #! 
 !
  ! 
     !

  *'  ! " 

The following control statement specifies that RUNSTATS is to update all catalog statistics (table space, tables,
columns, and indexes) for table space DSN8D81P.DSN8S81C.


      ! 

  +'  ! 


    !  !


The following control statement specifies that RUNSTATS is to update the catalog with   the statistics that
are collected for access path selection. The utility is to report  statistics for the table space and route the
report to SYSPRINT.

     
   

 "

  ,'  !  !  !

The following control statement specifies that RUNSTATS is to update the catalog with  statistics (access
path and space) for table space DSN8D81A.DSN8S81E. The utility is also to report the collected statistics and
route the report to SYSPRINT.


     
   



  -'c ! %



 ! !

The following control statement specifies that RUNSTATS is to collect statistics for table space
DSN8D81A.DSN8S81E and route the report to SYSPRINT. The utility is not to update the catalog with the
collected statistics.


     
   

 

  .'  !  

The following control statement specifies that RUNSTATS is to update the statistics for the first partition of table
space DSN8D81A.DSN8S81E and the first partition of the DSN8810.XEMP1 index.


          !

  &/'  ! !  "  ! 

The following control statement specifies that RUNSTATS is to update the catalog tables and history catalog
tables with all statistics for table space DB0E0101.TL0E0101 (including related indexes and columns). The
utility is to report the collected statistics and route the statistics to SYSPRINT.


    
 

   


"  

  &&'  !  


  
 !#


Assume that the SYSADM.IXNP1 index is defined on four columns: NP1, NP2, NP3, and NP4. The following
control statement specifies that RUNSTATS is to update the statistics for index SYSADM.IXNPI.

The KEYCARD option indicates that the utility is to collect cardinality statistics for column NP1, column set NP1
and NP2, and column set NP1, NP2, and NP3, and column set NP1, NP2, NP3, and NP4. The FREQVAL
option and its associated parameters indicate that RUNSTATS is also to collect the 5 most frequently occurring
values on column NP1 (the first key column of the index), and the 10 most frequently occurring values on the
column set NP1 and NP2 (the first two key columns of the index). The utility is to report the collected statistics
and route the statistics to SYSPRINT.

     !
% 
& #
  

& #
  

   

  & '  !"


  !
  
 
"

The following control statement specifies that RUNSTATS is to update statistics for the columns EMPLEVEL,
EMPGRADE, and EMPSALARY in table DSN8810.DEPT (in table space DSN8D81A.DSN8S81E). The
statement uses the COLGROUP keyword to group these columns. RUNSTATS is to collect the cardinality of
this column group and store the cardinality in the SYSCOLDIST catalog table.


     
  !
 $
 # $    !

  &('  !"


     
 # !

  
 !#


The following control statement specifies that RUNSTATS is to update statistics for the columns EMPLEVEL,
EMPGRADE, and EMPSALARY in table DSN8810.DEPT. The FREQVAL and COUNT options indicate that
RUNSTATS is to collect the 10 most frequently occurring values for each column. The values are to be stored
in the SYSCOLDIST and SYSCOLDISTSTATS catalog tables.


     
  !
 $
 # $    !& #


  &)'  !"


     
 " 
# !
  
 !#


The following control statement specifies that RUNSTATS is to update statistics for the columns EMPLEVEL,
EMPGRADE, and EMPSALARY in table DSN8810.DEPT. The FREQVAL and COUNT options indicate that
RUNSTATS is to collect the 15 least frequently occurring values for each column. The values are to be stored
in the SYSCOLDIST and SYSCOLDISTSTATS catalog tables.


     
  !
 $
 # $    !& #
 

  &*'  !"


     
 "  
# !  
  
 !#


The following control statement specifies that RUNSTATS is to update statistics for the columns EMPLEVEL,
EMPGRADE, and EMPSALARY in table DSN8810.DEPT. The FREQVAL and COUNT options indicate that
RUNSTATS is to collect the 10 most frequently occurring values for each column and the 10 least frequently
occurring values for each column. The values are to be stored in the SYSCOLDIST and SYSCOLDISTSTATS
catalog tables.


     
  !
 $
 # $    !& #
 "
  &+'  !     # !  

  
 !#


The following control statement specifies that RUNSTATS is to collect the 10 most frequently occurring values
and the 10 least frequently occurring values for the first key column of index ADMF001.IXMA0101. The
KEYCARD option indicates that the utility is also to collect all the distinct values in all the key column
combinations. A set of messages is sent to SYSPRINT and all collected statistics are updated in the catalog.


   &!
% 
& #
  
 "
  


  &,' # !          "


 %
!  ! 0

The following control statement specifies that RUNSTATS is to invalidate statements in the dynamic statement
cache for table space DSN8D81A.DSN8S81E. However, RUNSTATS is not to collect or report statistics or
update the catalog.


     
  

 

  &-'c 12c3"  0

The following control statement specifies that RUNSTATS is to gather histogram statistics for the specified
key columns. Histogram statistics can only be collected on the prefix columns with the same order.


   # # 
 
"  $ 
  

  
" # " $!


  

Potrebbero piacerti anche