My Oracle Support Banner

Comparing Statistics For Tables Using History (Same Database) And Stat Table (Different Database) (Doc ID 2285732.1)

Last updated on AUGUST 04, 2018

Applies to:

Oracle Database - Enterprise Edition - Version and later
Information in this document applies to any platform.


Most of the optimizer issues in generating the optimal execution plans for SQL statements are due to the inaccurate statistics for the objects involved.
One of the main reasons an execution plan can differ from one system to another is because optimizer statistics are different.
Having said, from 12c, there is a mechanism in DBMS_STATS to compare the statistics versions within the same database as well with another database.
For example, statistics may be different in a test environment when compared to production if the data is not in sync.
To identify differences in statistics, the DBMS_STATS.DIFF_TABLE_STATS_IN_HISTORY/STATTAB functions can be used to compare statistics for two different sources (denoted source "A" and source "B").


Scope of this bulletin is to explain about the new feature in 12c about comparing the statistics for tables within the same database using statistics history and for tables in different database using statistics table (STATTAB).

DIFF_TABLE_STATS_IN_HISTORY: This function can be used to compare statistics for a table from two timestamps in past and compare the statistics as of that timestamps.
DIFF_TABLE_STATS_IN_STATTAB: This function can be used to compare statistics for a table from two different sources.

The "DIFF" functions also compare the statistics of the dependent objects (indexes, columns, partitions), and displays all the statistics for the object(s) from both sources if the difference between the statistics exceeds a specified threshold. The threshold can be specified as an argument to the function; the default value is 10%. The statistics corresponding to the first source will be used as the basis for computing the differential percentage.


To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!

In this Document
 To compare the statistics of an individual table at two different points in time using history (Same Database):
 To compare the statistics of an individual table from one database to another using STATTAB:

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.