I use DBMS_STATS.GATHER_SCHEMA_STATS procedure to collect statistics in my code.
BEGIN
DBMS_STATS.gather_schema_stats
(ownname => '<SCHEMA NAME',
estimate_percent => DBMS_STATS.auto_sample_size,
options => 'GATHER STALE',
DEGREE => NULL,
CASCADE => DBMS_STATS.auto_cascade,
granularity => 'auto'
);
end;
My question: After I executed this code, i checked the last analyzed date of tables using TOAD tool and it is showing some other past date instead of the current date when i ran the DBMS_STATS.GATHER_SCHEMA_STATS procedure.
Does this mean that the DBMS_STATS will not analyze the table?
When you specify the option
GATHER STALE, you are telling Oracle that you only want to gather statistics on objects that have undergone “significant” change since the last time statistics were gathered on that object. If Oracle determines that the table has not changed much since statistics were last gathered, it will not gather statistics again.Oracle determines that tables have changed significantly by monitoring DML on those tables (Oracle by default monitors tables in 11g– you had to enable monitoring in earlier versions). That data is written to
DBA_TAB_MODIFICATIONSperiodically (roughly every few hours). WhenDBMS_STATSruns with theGATHER STALEoption, Oracle compares the approximate number of changes inDBA_TAB_MODIFICATIONSagainst the prior statistics for the table to determine whether enough rows have changed to make it worthwhile to gather statistics again.