<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
现场反馈一些功能更新后变慢,决定查看一下现场的执行计划,使用DBMS_STATS进行统计数据的传递。
创建统计表 SQL> exec dbms_stats.create_stat_table('ahsimis','qik'); --Schema,表名 PL/SQL procedure successfully completed
|
导出统计值,这里可以导表,也可以导schema,database,column的统计值 SQL> exec dbms_stats.export_table_stats('ahsimis','ac20','','qik'); -- Schema,统计的表,空,统计表名
PL/SQL procedure successfully completed
|
使用工具将qik表下的数据导出成sql语句。
导入sql语句。
导入的用户也要具有dba权限,要注意,导出和导入统计值的表结构应该一致,否则导入时会报错 SQL> exec dbms_stats.import_table_stats('ahsimis','ac20','','qik');
PL/SQL procedure successfully completed
|
SQL> exec dbms_stats.drop_stat_table('ahsimis','qik'); --Schema,表名
PL/SQL procedure successfully completed |
Wonder
<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><chsdate w:st="on" isrocdate="False" islunardate="False" day="6" month="10" year="2008">2008-10-06</chsdate>
附1:关于DBMS_STATS的其他信息,DBMS_STATS本身存在bug
(http://yumianfeilong.com/2007/05/28/dbms_stats-vs-analyze2/)
使用DBMS_STATS进行Gather表和索引的统计信息,会使得索引监视失效,此问题在<chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899"><span lang="EN-US">10.2.0</span></chsdate>.1中正常,但在10.2.0.3中又出现了,使用analyze语句不会有此问题。
附2:分析数据的三种方法
l ANALYZE
ANALYZE table scott compute statistics;
ANALYZE table scott estimate statistics sample 25 percent;
ANALYZE table scott estimate statistics sample 1000 rows;
analyze index sc_idx compute statistics;
analyze index sc_idx validate structure;
l DBMS_UTILITY.ANALYZE_SCHEMA
exec DBMS_UTILITY.ANALYZE_SCHEMA('SCOTT','COMPUTE');
exec DBMS_UTILITY.ANALYZE_SCHEMA('SCOTT','ESTIMATE',estimate_rows => 1000);
exec DBMS_UTILITY.ANALYZE_SCHEMA('SCOTT','ESTIMATE', estimate_percent
=> 25);
exec DBMS_UTILITY.ANALYZE_SCHEMA('SCOTT','DELETE');
l DBMS_STATS.GATHER_SCHEMA_STATS
exec
DBMS_STATS.GATHER_SCHEMA_STATS('SCOTT',DBMS_STATS.AUTO_SAMPLE_SIZE);
exec
DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>'SCOTT'
,estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);
EXEC DBMS_STATS.gather_schema_stats(ownname => 'SCOTT',
estimate_percent => 25);
EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES');
EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK');
exec DBMS_STATS.DELETE_SCHEMA_STATS('SCOTT');