天天看點

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幾列就會明白,這就是變化。

使用了分析表分析之後結果會儲存,以後再查詢的的時候可以根據那些儲存了的字段直接統計出來所需要的資訊,減少了執行時間