天天看點

oracle 分析表簡介 Oracle分析表簡介

Oracle分析表簡介

Oracle分析表是Oracle資料庫管理的重要部分,下面就為您詳細介紹Oracle分析表方面的知識,希望對您學習Oracle分析表方面能有所幫助。

1、分析SQL:

analyze table tablename compute statistics 

等同于 analyze table tablename compute statistics for table for all indexes for all columns

for table的統計資訊存在于視圖:user_tables 、all_tables、dba_tables

for all indexes的統計資訊存在于視圖: user_indexes 、all_indexes、dba_indexes

for all columns的統計資訊存在于試圖:user_tab_columns、all_tab_columns、dba_tab_columns

删除分析SQL:

analyze table tablename delete statistics 會删除所有的statistics

2、Oracle分析表的作用:為了使基于CBO的執行計劃更加準确

DBA_tables的資料有變化,可做對比。詳見官方文檔:

Use the ANALYZE statement to collect non-optimizer statistics, for example, to:

Collect or delete statistics about an index or index partition, table or table partition, index-organized table, cluster, or scalar object attribute. 

Validate the structure of an index or index partition, table or table partition, index-organized table, cluster, or object reference (REF). 

Identify migrated and chained rows of a table or cluster.

dbms_stats的作用主要是替代analyze的收集統計資訊這一塊的功能,且在這一方面做了相當大程度上的增強。

以analyze table table_name compute statistics;這條為例,生成的統計資訊會存在于user_tables這個視圖,檢視一下select * from user_tables where table_name='table_name';

觀察一下NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN幾列你就會明白,這就是變化。