STATSCHK SMART RUNSTATS UTILITY
_______________________________
:set tabstop=4 to display correctly.

Specification: This utility creates a list of tables to RUNSTATS.
-------------  By default, it selects all tables in permanent tablespaces with a positive Update Delete Insert (UDI) counter.
               You can configure the candidate list so that it examines:
               a) the UDI counters of either (i) tables in an optional list of tablespaces OR (ii) all catalogued tables
                  AND  
               b) an optional include list of tablespaces whose tables will always  be RUNSTATSd, regardless of UDI counts.
               The assumption here is that related objects are grouped in the same tablespaces.
               The utility will also invoke RUNSTATS, if the command line arguments request it.
               Further details are in the A_STATS_README file and in the comments at the top of the Stats_Check.ksh program.

Packing List: 
------------- statschk.awkin1 ............ awk script file
              statschk.awkin2 ............ awk script file
              A_SETUP_STATS_README ....... (this file)
              A_STATS_README ............. technical background
	      	  STATSCHK.ksh ............... main program - code uses a rich function library [1]
	      	  STATSVIEWS.ksh ............. separate program for statistical views
              statschk_search_tbspaces ... as a) (i) above; delivered empty
              statschk_include_tbspaces .. as b) above ; contains 0 (syscatspace) since catalog tables should always have recent stats.

Customisation
-------------

A. Set the scope for this utility.
1. Decide whether you want to examine tables in all permanent data tablespaces, or tables in just some tablespaces.
   For example, there may be some development or scratchpad public tablespaces you just don't care about and which get pruned regularly.
   Or there may be static tablespaces where data changes only very slowly over time.
   To examine all tables, leave the statschk_search_tbspaces file empty.
   To examine some tables only, edit the statschk_search_tbspaces file with one tablespace id per line.
   The following query will list each tablespace  with permanent data and its corresponding TBSPACEID:
		select tbspace, tbspaceid from syscat.tablespaces where datatype in ('A','L')
   So if you want to examine just SYSCATSPACE, the file will contain 1 line containing a 0 (zero) followed by an end of line character, total 2 bytes.

2. Decide whether there are some tables you always want to RUNSTATS, regardless of UDI activity.
   Examples may include the system catalog, small dimension tables and so on.
   If there are any of these, edit statschk_include_tbspaces to include each TBSPACEID on a new line.

B. Cater for database deactivations.
The A_STATS_README file contains the background for when UDI counters get hardened to disk.
If database activations/reactivations are regularly scheduled, schedule this utility before the recycle. 

C. Review and edit the supplied runtime options in the F_RUNSTATS and F_RUNSTATS_TABLE functions if you want the program to update statistics.
   [1] The A_MAINTENANCE_SETUP_README in the root $INSTHOME/MAINTENANCE folder contains the install setup for the function library at $FPATH.

D. Decide whether you wish to update catalog stats for statistical views in a separate job.
This is recommended at the current version, because the logic in STATSVIEWS.ksh is currently unconditional - it will RUNSTATS all views irrespective of 
changes to underlying base tables; this could potentially take a long time if the statistical views involve multiple joins and hierarchically reference other views. 
A later version will inspect the UDI counters for the views' base tables.
If you do wish to update stats for views and base tables in the same job, please follow the editing instructions in both .ksh scripts.
If you have no statistical views, this obviously does not apply.

Alex Levy, Jan 2010
Revised June and September 2012.
Sustainable Software Ltd.
http://www.sustainablesoftware.net
Last Updated June 2012
-----------
