Cleaning stale or unneeded Db2 catalog statistics
You can avoid possible access path problems from stale statistics and avoid collection of costly statistics that provide no benefit by removing stale or unneeded catalog statistics. The removal of unneeded statistics is particularly important in Db2 12 when you can use profile-based automation for statistics collection.
About this task
The RUNSTATS utility and inline statistics with other utilities replace existing statistics with new values only based on the keywords that you specify in the utility control statements. They do not remove any previously collected statistics that are not specified. For example, assume that you collect statistics one time with the NUMCOLS 2 COUNT 10 keywords. If you then omit those keywords the next time that you collect statistics, the statistics that were collected for those keywords remain in the catalog. Such values are cleaned up only if you take action to remove them.
If you previously collected some specialized statistics for a one-off tuning effort, Db2 can start automatically and routinely collecting those costly statistics again, even if they are not needed, and were previously collected only long ago.
RUNSTATS TABLE(T1) INDEX(ALL)TABLE(T1) INDEX(ALL)
COLGROUP(C1) FREQVAL COUNT 10
COLGROUP(C2, C4)
COLGROUP(C3) HISTOGRAM NUMQUANTILES 100
COLGROUP(C5) HISTOGRAM NUMQUANTILES 100If you then collect statistics with USE PROFILE, Db2 begins to collect all of those statistics. After the first collection, all of the new entries have the same STATSTIME value, and you cannot tell which were not previously collected on a regular basis. The ongoing collection of such statistics increases the cost for collecting statistics.
Procedure
To identify and remove stale Db2 catalog statistics, complete the following steps: