Configure incremental statistics for a partitioned table
OracleStatisticsCommand
-- 1) Enable incremental mode (global statistics are derived from partition synopses):
EXEC DBMS_STATS.SET_TABLE_PREFS('CUSTOMER_APP', 'SALE_PART', 'INCREMENTAL', 'TRUE');
EXEC DBMS_STATS.SET_TABLE_PREFS('CUSTOMER_APP', 'SALE_PART', 'INCREMENTAL_STALENESS', 'USE_STALE_PERCENT');
EXEC DBMS_STATS.SET_TABLE_PREFS('CUSTOMER_APP', 'SALE_PART', 'GRANULARITY', 'AUTO');
-- 2) The first gather scans everything and builds synopses; later ones read only changed partitions:
EXEC DBMS_STATS.GATHER_TABLE_STATS(ownname => 'CUSTOMER_APP', tabname => 'SALE_PART');
-- 3) Verify:
SELECT DBMS_STATS.GET_PREFS('INCREMENTAL', 'CUSTOMER_APP', 'SALE_PART') AS incremental FROM dual;
SELECT partition_name, num_rows,
TO_CHAR(last_analyzed,'YYYY-MM-DD HH24:MI:SS') AS last_analyzed, stale_stats
FROM dba_tab_statistics
WHERE owner = 'CUSTOMER_APP' AND table_name = 'SALE_PART'
ORDER BY partition_position NULLS FIRST;
-- 4) Pre-build synopses on a staging table to be loaded via exchange (12c+):
-- EXEC DBMS_STATS.SET_TABLE_PREFS('CUSTOMER_APP', 'SALE_STAGE', 'INCREMENTAL', 'TRUE');
-- EXEC DBMS_STATS.SET_TABLE_PREFS('CUSTOMER_APP', 'SALE_STAGE', 'INCREMENTAL_LEVEL', 'TABLE');
-- EXEC DBMS_STATS.GATHER_TABLE_STATS('CUSTOMER_APP', 'SALE_STAGE');What it does
In incremental mode a synopsis is stored per partition; global (table-level) statistics, NDV in particular, are computed by merging synopses without rescanning the whole table. Only changed partitions are read again.
When to use it
On large (TB-scale) range/interval partitioned tables where new data lands only in recent partitions, when global statistics gathering exceeds the maintenance window.
Caution
No license of its own, but the Partitioning option (extra-cost EE) is already required. Synopses consume SYSAUX space (the 12.2+ HyperLogLog format is much smaller). The first gather is a full scan; start it in a maintenance window. Setting ESTIMATE_PERCENT to anything other than AUTO_SAMPLE_SIZE disables incremental.