Search code examples
sqldatabaseindexingdb2dbtable

Run DB2 Runstats without activity but still get SQLSTATE=01650


After reading many of articles from the internet, I am still not sure what is the actual purpose of DB2 Runstats.

As my understanding, DB2 Runstats will "register" the table index to the DB2 catalog, so that next time when the related query run, it will use the index to increase the performance. (Please correct me if I am wrong)

Meaning, if for a long period of time the DB2 Runstats is not run, the index will be removed from the DB2 catalog?

I am creating a new index for a table. Originally that table already contained another index.

After creating the new index, I ran DB2 Runstats on the table for the old index, but I hit the following error:

SQL2314W Some statistics are in an inconsistent state. The newly collected "INDEX" statistics are inconsistent with the existing "TABLE" statistics. SQLSTATE=01650

At first I was thinking it's cause by the activity to create the new index, and the table was still in the "processing" stage. I ran the DB2 Runstats command again the next day but still got the same error.


Solution

  • Your understanding about db2 runstats is not correct. This command collects statistics on the given table and its indexes and placed it to views in the SYSSTAT schema like SYSSTAT.TABLES, SYSSTAT.INDEXES, etc. This information is used by the DB2 optimizer to produce better access plans of your queries. It doesn't "register" indexes itself. Indexes are not removed automatically if you don't collect statistics on them.

    As for the warning message SQL2314W.

    It's just a warning that table and index statistics is not logically compatible (for example, number of index keys is more than number of rows in the table). Sometimes it happens when you collect statistics on actively updated table at the same time even you run such a collection on a table and its indexes using a single RUNSTATS command. You can either ignore this message or make the RUNSTATS utility lock the table during the statistics collection on table and its indexes using a single command (ALLOW READ ACCESS clause).