DBAtlas · Atlas für Datenbankbetrieb

Inkrementelle Statistiken für eine partitionierte Tabelle konfigurieren

OracleStatistiken

Befehl

-- 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');

Was es tut

Im inkrementellen Modus wird je Partition eine Synopsis gespeichert; globale Statistiken (Tabellenebene), insbesondere NDV, werden durch Zusammenführen der Synopsen berechnet, ohne die ganze Tabelle erneut zu scannen. Nur geänderte Partitionen werden erneut gelesen.

Wann einsetzen

Bei großen (TB-Bereich) Range-/Interval-partitionierten Tabellen, bei denen neue Daten nur in den jüngsten Partitionen landen, wenn die globale Statistikerfassung das Wartungsfenster überschreitet.

Vorsicht

Keine eigene Lizenz, aber die Partitioning-Option (kostenpflichtig, EE) ist ohnehin nötig. Synopsen belegen Platz in SYSAUX (das HyperLogLog-Format ab 12.2 ist viel kleiner). Die erste Erfassung ist ein Full Scan; starte sie in einem Wartungsfenster. Ein ESTIMATE_PERCENT ungleich AUTO_SAMPLE_SIZE deaktiviert den inkrementellen Modus.

In DBAtlas öffnen →

Verwandte Einträge