dbms_stats.gather_table_stats與analyze table 的區別[轉貼]
參考 http://www.itpub.net/viewthread.php?tid=845777&extra=&page=1[@more@]Analyze Statement
The ANALYZE statement can be used to gather statistics for a specific table, index or cluster. The statistics can be computed exactly, or estimated based on a specific number of rows, or a percentage of rows:
ANALYZE TABLE employees COMPUTE STATISTICS;
ANALYZE INDEX employees_pk COMPUTE STATISTICS;
ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 100 ROWS;
ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 15 PERCENT;
DBMS_UTILITY
The DBMS_UTILITY package can be used to gather statistics for a whole schema or database. Both methods follow the same format as the analyze statement:
EXEC DBMS_UTILITY.analyze_schema('SCOTT','COMPUTE');
EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_rows => 100);
EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_percent => 15);
EXEC DBMS_UTILITY.analyze_database('COMPUTE');
EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_rows => 100);
EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_percent => 15);
DBMS_STATS
The DBMS_STATS package was introduced in 8i and is Oracles preferred method of gathering object statistics. Oracle list a number of benefits to using it including parallel execution, long term storage of statistics and transfer of statistics between servers. Once again, it follows a similar format to the other methods:
EXEC DBMS_STATS.gather_database_stats;
EXEC DBMS_STATS.gather_database_stats(estimate_percent => 15);
EXEC DBMS_STATS.gather_schema_stats('SCOTT');
EXEC DBMS_STATS.gather_schema_stats('SCOTT', estimate_percent => 15);
EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES');
EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES', estimate_percent => 15);
EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK');
EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK', estimate_percent => 15);
This package also gives you the ability to delete statistics:
EXEC DBMS_STATS.delete_database_stats;
EXEC DBMS_STATS.delete_schema_stats('SCOTT');
EXEC DBMS_STATS.delete_table_stats('SCOTT', 'EMPLOYEES');
EXEC DBMS_STATS.delete_index_stats('SCOTT', 'EMPLOYEES_PK');
--------------------------------------------------------------------------------------
自從Oracle8.1.5引入dbms_stats包,Experts們便推薦使用dbms_stats取代analyze。 理由如下
dbms_stats可以並行分析
dbms_stats有自動分析的功能(alter table monitor )
analyze 分析統計資訊的不準確some times
1,2好理解,且第2點實際上在VLDB中是最吸引人的;3以前比較模糊,看了metalink236935.1 解釋,analyze在分析Partition表的時候,有時候會計算出不準確的Global statistics .
原因是,dbms_stats會實在的去分析表全域性統計資訊(當指定引數);而analyze是將表分割槽(區域性)的statistics 彙總計算成表全域性statistics ,可能導致誤差。
如果想分析整個使用者或,還可以採用工具包,可以並行分析
Dbms_utility(8i以前的工具包)
Dbms_stats(8i以後提供的工具包)
如
dbms_stats.gather_schema_stats(User,estimate_percent=>100,cascade=> TRUE);
dbms_stats.gather_table_stats(User,TableName,degree => 4,cascade => true);
這是對命令與工具包的一些總結
1、對於,建議使用DBMS_STATS,而不是使用Analyze語句。
a) 可以並行進行,對多個使用者,多個Table
b) 可以得到整個分割槽表的資料和單個分割槽的資料。
c) 可以在不同級別上Compute Statistics:單個分割槽,子分割槽,全表,所有分割槽
d) 可以倒出統計資訊
e) 可以使用者自動收集統計資訊
2、DBMS_STATS的缺點
a) 不能Validate Structure
b) 不能收集CHAINED ROWS, 不能收集CLUSTER TABLE的資訊,這兩個仍舊需要使用Analyze語句。
c) DBMS_STATS 預設不對索引進行Analyze,因為預設Cascade是False,需要手工指定為True
3、對於oracle 9裡面的External Table,Analyze不能使用,只能使用DBMS_STATS來收集資訊。
-----------------------------------------------------------------
10G的文件是這麼說的:
Do not use the COMPUTE and ESTIMATE clauses of ANALYZE to collect optimizer statistics. These clauses are supported for backward compatibility. Instead, use the DBMS_STATS package, which lets you collect statistics in parallel, collect global statistics for partitioned objects, and fine tune your statistics collection in other ways. The cost-based optimizer, which depends upon statistics, will eventually use only statistics that have been collected by DBMS_STATS
analyze的功能已經明確:
Use the ANALYZE statement (rather than DBMS_STATS) forstatistics collection not related to the cost-based optimizer:
To use the VALIDATE or LIST CHAINED ROWS clauses
To collect information on freelist blocks
在收集與CBO最佳化器不相關的統計資訊的時候ANALYZE語句要優於DBMS_STATS包
-----------------------------------
EX:
begin
for owner in (select username from dba_users where username not in ('SYS','SYSTEM'))
loop
dbms_output.disable;
dbms_output.enable(1000000);
dbms_output.put_line('Schema: '||owner.username);
select sysdate into start_time from dual;
dbms_output.put_line('Analyze start from : '||start_time);
dbms_stats.gather_schema_stats(ownname => owner.username, estimate_percent => 20, block_sample=> true, cascade=>true);
select sysdate into end_time from dual;
dbms_output.put_line('Analyze complete at : '||end_time);
dbms_output.put_line('---------------------------');
end loop;
dbms_stats.gather_table_stats(ownname =>,
tabname =>,
partname =>,
estimate_percent =>,
block_sample =>,
method_opt =>,
degree =>,parallel degree(並行收集維度) 看CPU個數
granularity =>,
cascade =>,true is also gather columns and index’s statistics;
no_invalidate =>);
The ANALYZE statement can be used to gather statistics for a specific table, index or cluster. The statistics can be computed exactly, or estimated based on a specific number of rows, or a percentage of rows:
ANALYZE TABLE employees COMPUTE STATISTICS;
ANALYZE INDEX employees_pk COMPUTE STATISTICS;
ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 100 ROWS;
ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 15 PERCENT;
DBMS_UTILITY
The DBMS_UTILITY package can be used to gather statistics for a whole schema or database. Both methods follow the same format as the analyze statement:
EXEC DBMS_UTILITY.analyze_schema('SCOTT','COMPUTE');
EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_rows => 100);
EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_percent => 15);
EXEC DBMS_UTILITY.analyze_database('COMPUTE');
EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_rows => 100);
EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_percent => 15);
DBMS_STATS
The DBMS_STATS package was introduced in 8i and is Oracles preferred method of gathering object statistics. Oracle list a number of benefits to using it including parallel execution, long term storage of statistics and transfer of statistics between servers. Once again, it follows a similar format to the other methods:
EXEC DBMS_STATS.gather_database_stats;
EXEC DBMS_STATS.gather_database_stats(estimate_percent => 15);
EXEC DBMS_STATS.gather_schema_stats('SCOTT');
EXEC DBMS_STATS.gather_schema_stats('SCOTT', estimate_percent => 15);
EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES');
EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES', estimate_percent => 15);
EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK');
EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK', estimate_percent => 15);
This package also gives you the ability to delete statistics:
EXEC DBMS_STATS.delete_database_stats;
EXEC DBMS_STATS.delete_schema_stats('SCOTT');
EXEC DBMS_STATS.delete_table_stats('SCOTT', 'EMPLOYEES');
EXEC DBMS_STATS.delete_index_stats('SCOTT', 'EMPLOYEES_PK');
--------------------------------------------------------------------------------------
自從Oracle8.1.5引入dbms_stats包,Experts們便推薦使用dbms_stats取代analyze。 理由如下
dbms_stats可以並行分析
dbms_stats有自動分析的功能(alter table monitor )
analyze 分析統計資訊的不準確some times
1,2好理解,且第2點實際上在VLDB中是最吸引人的;3以前比較模糊,看了metalink236935.1 解釋,analyze在分析Partition表的時候,有時候會計算出不準確的Global statistics .
原因是,dbms_stats會實在的去分析表全域性統計資訊(當指定引數);而analyze是將表分割槽(區域性)的statistics 彙總計算成表全域性statistics ,可能導致誤差。
如果想分析整個使用者或,還可以採用工具包,可以並行分析
Dbms_utility(8i以前的工具包)
Dbms_stats(8i以後提供的工具包)
如
dbms_stats.gather_schema_stats(User,estimate_percent=>100,cascade=> TRUE);
dbms_stats.gather_table_stats(User,TableName,degree => 4,cascade => true);
這是對命令與工具包的一些總結
1、對於,建議使用DBMS_STATS,而不是使用Analyze語句。
a) 可以並行進行,對多個使用者,多個Table
b) 可以得到整個分割槽表的資料和單個分割槽的資料。
c) 可以在不同級別上Compute Statistics:單個分割槽,子分割槽,全表,所有分割槽
d) 可以倒出統計資訊
e) 可以使用者自動收集統計資訊
2、DBMS_STATS的缺點
a) 不能Validate Structure
b) 不能收集CHAINED ROWS, 不能收集CLUSTER TABLE的資訊,這兩個仍舊需要使用Analyze語句。
c) DBMS_STATS 預設不對索引進行Analyze,因為預設Cascade是False,需要手工指定為True
3、對於oracle 9裡面的External Table,Analyze不能使用,只能使用DBMS_STATS來收集資訊。
-----------------------------------------------------------------
10G的文件是這麼說的:
Do not use the COMPUTE and ESTIMATE clauses of ANALYZE to collect optimizer statistics. These clauses are supported for backward compatibility. Instead, use the DBMS_STATS package, which lets you collect statistics in parallel, collect global statistics for partitioned objects, and fine tune your statistics collection in other ways. The cost-based optimizer, which depends upon statistics, will eventually use only statistics that have been collected by DBMS_STATS
analyze的功能已經明確:
Use the ANALYZE statement (rather than DBMS_STATS) forstatistics collection not related to the cost-based optimizer:
To use the VALIDATE or LIST CHAINED ROWS clauses
To collect information on freelist blocks
在收集與CBO最佳化器不相關的統計資訊的時候ANALYZE語句要優於DBMS_STATS包
-----------------------------------
EX:
begin
for owner in (select username from dba_users where username not in ('SYS','SYSTEM'))
loop
dbms_output.disable;
dbms_output.enable(1000000);
dbms_output.put_line('Schema: '||owner.username);
select sysdate into start_time from dual;
dbms_output.put_line('Analyze start from : '||start_time);
dbms_stats.gather_schema_stats(ownname => owner.username, estimate_percent => 20, block_sample=> true, cascade=>true);
select sysdate into end_time from dual;
dbms_output.put_line('Analyze complete at : '||end_time);
dbms_output.put_line('---------------------------');
end loop;
dbms_stats.gather_table_stats(ownname =>,
tabname =>,
partname =>,
estimate_percent =>,
block_sample =>,
method_opt =>,
degree =>,parallel degree(並行收集維度) 看CPU個數
granularity =>,
cascade =>,true is also gather columns and index’s statistics;
no_invalidate =>);
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/3907/viewspace-1018925/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【轉】dbms_stats.gather_table_stats與analyze table 的區別
- dbms_stat與analyze的區別
- ECC6.0與R/3的區別[轉貼]
- 【效能優化】ANALYZE 與DBMS_STATS的區別優化
- dbms_stat, dbms_utility與analyze的區別
- table move 與 shrink 的區別
- 轉貼_大牛_tolywang_Buffer 與 Cache 的區別
- MySQL的create table as 與 like區別MySql
- insert into select 與 create table as的用法和區別(轉)
- DBMS_STATS.GATHER_TABLE_STATS詳解
- alter table move 與shrink space的區別
- Analyze table對Oracle效能的提升Oracle
- Oracle analyze table的使用總結Oracle
- alter table move跟shrink space的區別(轉)
- dbms_stats.gather_table_stats中 granularity的實驗
- drop table和truncate table的區別
- MySQL:Analyze table導致'waiting for table flush'MySqlAI
- Truncate table 詳解及與delete,drop 的區別delete
- Truncate table詳解及與delete,drop的區別delete
- [轉] js == 與 === 的區別JS
- Oracle DBMS_STATS 包 和 Analyze 命令的區別Oracle
- (轉)CWnd與HWND的區別與轉換
- Flashback database與flashback table使用條件區別Database
- Public與Private的區別 (轉)
- MySQL 5.7 ANALYZE TABLE分析索引的統計資訊MySql索引
- alter table move 和 alter table shrink space的區別
- table中cesllspacing與cellpadding的區別詳解padding
- analyze index 時validate structure和compute statistics的區別IndexStruct
- analyze table/index validate structure加鎖的問題IndexStruct
- 執行收集統計資訊dbms_stats.gather_table_stats包的bug
- 轉發與重定向的區別
- java bean 與 ejb的區別 (轉)JavaBean
- Oracle --- PLAN_TABLE$和PLAN_TABLE區別Oracle
- v$lock之alter table drop column與alter table set unused column區別系列五
- alter table move跟shrink space的區別
- 轉 shell中$(( )) 與 $( ) 還有${ }的區別
- Oracle與MySQL的幾點區別(轉)OracleMySql
- su和sudo的區別與使用(轉)