Table stats not updated immediately after "analyze table xxx compute statistics"
Problem
The "analyze table xxx compute statistics" command doesn't update the user_tab_statistics view immediately.
Cause
In 10g and above, the recommended way to collect table statistics is using "dbms_stats.gather_table_stats(xxx)". When "dbms_stats.gather_*_stats procedures are executed, they internally flush monitoring information to *_TAB_MODIFICATIONS, *_TAB_STATISTICS, and *_IND_STATISTICS views.
Solution
1 use "dbms_stats.gather_table_stats(xxx)" to gather latest table stats.
or
2 use DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO procedure to manually flush memory stats information to the above 3 views.
Note
1 Since 10g, table level monitoring is enabled by default, it's controlled by STATISTIC_LEVEL system parameter. If STATISTICS_LEVEL is set to BASIC, then table monitoring is disabled, otherwise it's enabled.
2 You can use following command to check if a table stats is being locked or not:
– shows when stats is not locked the value of stattype_locked is NULL
SQL> SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = 'TEST' and owner = 'SCOTT';
SQL> SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = 'TEST' and owner = 'SCOTT';
STATT
—–
—–
Related Links
- DBA_TAB_MODIFICATIONS
- Time of last DML
- How to lock/unlock statistics on a table?
- DBA_TAB_MODIFICATIONS - Amin Jaffer
- Automatic Statistics Gathering
- Automatic Statistics Gathering - DEV's Weblog
- oracle dbms_stat与analyze 获取有效的统计信息(3)
- Custom Statistics Gathering Package for 9i, 10g
- Gather Statistics with DBMS_STATS by Jeff
- “dbms_stats.gather_table_stats” vs “analyze table compute stats”
Labels: analyze table, dbms_stats
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home