schema 更新統計數據
SQL> exec dbms_stats.gather_schema_stats(ownname => 'c##sapr3',options => 'GATHER AUTO', estimate_percent => dbms_stats.auto_sample_size,method_opt => 'for all columns size repeat',degree =>15,cascade=>TRUE) PL/SQL procedure successfully completed. SQL> exec dbms_stats.gather_schema_stats(ownname => 'c##sapr3',options => 'GATHER AUTO', estimate_percent => dbms_stats.auto_sample_size,method_opt => 'FOR ALL COLUMNS SIZE AUTO',degree =>15,cascade=>TRUE); PL/SQL procedure successfully completed.
Table 更新統計數據
SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS('c##sapr3',tabname =>'USR02',estimate_percent=>80,method_opt=>'FOR ALL COLUMNS SIZE AUTO',degree=>4,cascade=>TRUE); PL/SQL procedure successfully completed.
index更新統計數據
EXEC DBMS_STATS.GATHER_INDEX_STATS('c##sapr3',"USRBF2^0",estimate_percent=>80,degree=>4);
BEGIN DBMS_STATS.GATHER_TABLE_STATS(ownname => 'c##sapr3', tabname => '*', estimate_percent => 100, method_opt => 'for all columns size repeat', no_invalidate => FALSE, degree => 8, cascade => TRUE); END; / BEGIN DBMS_STATS.GATHER_SCHEMA_STATS(ownname => 'c##sapr3', estimate_percent => 100, method_opt => 'for all columns size repeat', no_invalidate => FALSE, degree => 8, cascade => TRUE); END; /
參數說明:
ownname:要分析表的擁有者
tabname:要分析的表名.
partname:分區的名字,只對分區表或分區索引有用.
estimate_percent:采樣行的百分比,取值范圍[0.000001,100],null為全部分析,不采樣. 常量:DBMS_STATS.AUTO_SAMPLE_SIZE是默認值,由oracle決定最佳取采樣值.
block_sapmple:是否用塊采樣代替行采樣.
method_opt:決定histograms信息是怎樣被統計的.method_opt的取值如下(默認值為FOR ALL COLUMNS SIZE AUTO):
for all columns:統計所有列的histograms.
for all indexed columns:統計所有indexed列的histograms.
for all hidden columns:統計你看不到列的histograms
for columns <list> SIZE <N> | REPEAT | AUTO | SKEWONLY:統計指定列的histograms.N的取值范圍[1,254]; REPEAT上次統計過的histograms;AUTO由oracle決定N的大小;SKEWONLY multiple end-points with the same value which is what we define by "there is skew in thedata
degree:決定並行度.默認值為null.
granularity:Granularity of statistics to collect ,only pertinent if the table is partitioned.
cascade:是收集索引的信息.默認為FALSE.
stattab:指定要存儲統計信息的表,statid如果多個表的統計信息存儲在同一個stattab中用於進行區分.statown存儲統計信息表的擁有者.以上三個參數若不指定,統計信息會直接更新到數據字典.
no_invalidate: Does not invalidate the dependent cursors if set to TRUE. The procedure invalidates the dependent cursors immediately if set to FALSE.
force:即使表鎖住了也收集統計信息.
GATHER_DATABASE_STATS #
This procedure gathers statistics for all objects in the database.
GATHER_DICTIONARY_STATS #
This procedure gathers statistics for dictionary schemas 'SYS', 'SYSTEM' and schemas of RDBMS components.
GATHER_FIXED_OBJECTS_STATS
#
This procedure gathers statistics for all fixed objects (dynamic performance tables).
GATHER_SYSTEM_STATS
#
This procedure gathers system statistics.
exec dbms_stats.flush_database_monitoring_info;
查看統計數據是否更新
SQL> col OWNER for A10 SQL> col TABLE_NAME for A30 SQL> col SUBPARTITION_NAME for A20 SQL> col OBJECT_TYPE for A15 SQL> select owner,table_name,last_analyzed from dba_tables where owner='c##sapr3'; SQL> select owner,table_name,object_type,stale_stats,last_analyzed from dba_tab_statistics where owner = 'c##sapr3' and (stale_stats = 'YES' or last_analyzed in null); SQL> SELECT OWNER,TABLE_NAME,OBJECT_TYPE,STALE_STATS,LAST_ANALYZED FROM DBA_TAB_STATISTICS WHERE (STALE_STATS='YES' OR LAST_ANALYZED IS NULL) AND OWNER NOT IN ('SYS','SYSTEM','SYSMAN','DMSYS','OLAPSYS','XDB','EXFSYS','CTXSYS','WMSYS','DBSNMP','ORDSYS','OUTLN','TSMSYS','MDSYS') AND TABLE_NAME NOT LIKE 'BIN%';
附
alter session set statistics_level=ALL; #session 級別 select /*+gather_plan_statistics*/... #語句級別