← Statistics
Oracle · Statistics
How to gather statistics on a table in Oracle
Gather fresh optimizer statistics for a table and its indexes with DBMS_STATS.GATHER_TABLE_STATS, then verify the new row count.
Tested on11g12c18c19c21c23ai26ai
Gather fresh optimizer statistics for one table and its indexes.
Gathering statistics changes the optimizer inputs and can change execution plans. On busy systems run it in a maintenance window.
BEGIN
DBMS_STATS.GATHER_TABLE_STATS(
ownname => '&&owner',
tabname => '&&table_name',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt => 'FOR ALL COLUMNS SIZE AUTO',
cascade => TRUE,
degree => DBMS_STATS.AUTO_DEGREE);
END;
/
-- Verify (read-only)
SELECT num_rows,
TO_CHAR(last_analyzed,'YYYY-MM-DD HH24:MI') AS last_analyzed
FROM dba_tables
WHERE owner = UPPER('&owner')
AND table_name = UPPER('&table_name');StatisticsDBMS_STATSGATHER_TABLE_STATS