oracle database 12cr2 使用 dbms_stat 采集统计信息
dbms_stat 是oracle database 采集統(tǒng)計(jì)信息的集成工具。非常方便和高效。
備份
創(chuàng)建stat_table
begindbms_stats.create_stat_table(ownname => 'drp',stattab => 'stat_table') ; end;導(dǎo)出整個(gè)scheme的統(tǒng)計(jì)信息
begindbms_stats.export_schema_stats(ownname => 'drp',stattab => 'stat_table') ; end;分析
begin--固定表的統(tǒng)計(jì)信息 sys.dbms_stats.gather_fixed_objects_stats;--數(shù)據(jù)字典的統(tǒng)計(jì)信息 sys.dbms_stats.gather_dictionary_stats;--instance的統(tǒng)計(jì)信息 sys.dbms_stats.gather_system_stats(); end;抽樣分析drp用戶對(duì)象
BEGINsys.dbms_stats.gather_schema_stats(ownname=> 'drp' ,estimate_percent=> 50 , cascade=> TRUE,--method_opt=>'for all columns size 1 '--method_opt=>'for all columns size repeat ',method_opt=>'for all indexed columns size skewonly ',degree=>8); END ;抽樣分析drp.order表
BEGINdbms_stats.gather_table_stats(ownname=> 'drp' ,tabname=> 'order',estimate_percent=> 50 , cascade=> TRUE,--method_opt=>'for all columns size 1 ',--method_opt=>'for all columns size repeat ',method_opt=>'for all indexed columns size skewonly ',no_invalidate=>FALSE,granularity=>'AUTO',degree=>8); END ;抽樣分析drp.order表的idx_order_x1索引
BEGINsys.dbms_stats.gather_index_stats(ownname=> 'drp' ,indname=>'idx_order_x1',estimate_percent=> 100 ); END ;method_opt選項(xiàng)
for table–只統(tǒng)計(jì)表
for all indexed columns–只統(tǒng)計(jì)有索引的表列
for all indexes–只分析統(tǒng)計(jì)相關(guān)索引
for all columns
在method_opt子句中,還有一些重要的新選項(xiàng),包括skewonly,repeat和auto:
method_opt=>’for all columns size 1’
method_opt=>’for all columns size skewonly’
method_opt=>’for all columns size repeat’
method_opt=>’for all columns size auto’
刪除
重新采集后發(fā)現(xiàn)效果不好的,可以刪除統(tǒng)計(jì)信息
刪除整個(gè)schema的統(tǒng)計(jì)信息
begindbms_stats.delete_schema_stats(ownname => 'drp') ; end;刪除表的統(tǒng)計(jì)信息
begindbms_stats.delete_table_stats(ownname => 'drp',tabname => 'order') ; end;導(dǎo)入
導(dǎo)入表的統(tǒng)計(jì)信息
begindbms_stats.import_table_stats(ownname => 'drp',tabname => 'order',stattab => 'stat_table') ; end;導(dǎo)入整個(gè)schema的統(tǒng)計(jì)信息
begindbms_stats.import_schema_stats(ownname => 'drp',stattab => 'stat_table'); end;轉(zhuǎn)載于:https://www.cnblogs.com/ctypyb2002/p/9793016.html
總結(jié)
以上是生活随笔為你收集整理的oracle database 12cr2 使用 dbms_stat 采集统计信息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 1.3 xss原理分析与剖析(4)
- 下一篇: js求区间随机数