10g在create index時就有索引統計資訊,9i 沒有
http://rdc.taobao.com/blog/dba/html/192_differencts_for_statistics_create_or_rebuild_index_9i_10g.html
在9.2.0.6和10.2.0.4做了個小小的試驗,演示9i和10g對於create index和rebuild index時統計資訊的區別。這裡列出試驗的過程,由於結果比較明顯,就懶得寫太多文字做說明了。其中tbsql是一個常用指令碼的整合環境,tbsql tabstat使用者輸出一個表以及列和索引的資訊,其實就是關聯dba_tables/dba_indexes/dba_tab_columns的一個查詢。
先來看9.2.0.6的情況:
SQL> create table t as select * from all_objects; Table created. SQL> create index t_id on t(object_id); Index created.
$tbsql tabstat t Table Number Empty Average Chain Average OWNER Name of Rows Blocks Blocks Space Count Row Len ---------- ------ -------- ------- ------- -------- -------- -------- SYS T Column Column Distinct Name Details Values Density ------------------ ------------------------ -------- ------- OWNER VARCHAR2(30) NOT NULL OBJECT_NAME VARCHAR2(30) NOT NULL SUBOBJECT_NAME VARCHAR2(30) OBJECT_ID NUMBER(22) NOT NULL DATA_OBJECT_ID NUMBER(22) OBJECT_TYPE VARCHAR2(18) CREATED DATE NOT NULL LAST_DDL_TIME DATE NOT NULL TIMESTAMP VARCHAR2(19) STATUS VARCHAR2(7) TEMPORARY VARCHAR2(1) GENERATED VARCHAR2(1) SECONDARY VARCHAR2(1) 13 rows selected. B Average Average Index Tree Leaf Distinct Leaf Blocks Data Blocks Cluster Name Unique Level Blks Keys Per Key Per Key Factor --------- --------- ----- ----- -------------- ----------- ----------- ------- T_ID NONUNIQUE Index Column Col Column Name Name Pos Details --------- --------------- ---- ------------------------ T_ID OBJECT_ID 1 NUMBER(22) NOT NULL
可以看到到表,列和索引都沒有統計資訊。
SQL> alter index t_id rebuild online compute statistics; Index altered.
$tbsql tabstat t Table Number Empty Average Chain Average OWNER Name of Rows Blocks Blocks Space Count Row Len ------- ------ -------- ------- ------- -------- -------- -------- SYS T 25,420 348 0 0 0 100 Column Column Distinct Name Details Values Density ----------------- ------------------------ --------- ------- OWNER VARCHAR2(30) NOT NULL OBJECT_NAME VARCHAR2(30) NOT NULL SUBOBJECT_NAME VARCHAR2(30) OBJECT_ID NUMBER(22) NOT NULL 25,420 0 DATA_OBJECT_ID NUMBER(22) OBJECT_TYPE VARCHAR2(18) CREATED DATE NOT NULL LAST_DDL_TIME DATE NOT NULL TIMESTAMP VARCHAR2(19) STATUS VARCHAR2(7) TEMPORARY VARCHAR2(1) GENERATED VARCHAR2(1) SECONDARY VARCHAR2(1) 13 rows selected. B Average Average Index Tree Leaf Distinct Leaf Blocks Data Blocks Cluster Name Unique Level Blks Keys Per Key Per Key Factor -------- --------- ----- ----- --------- ----------- ----------- ------- T_ID NONUNIQUE 1 56 25,420 1 1 22,731 Index Column Col Column Name Name Pos Details ------- ---------- ---- ------------------------ T_ID OBJECT_ID 1 NUMBER(22) NOT NULL
注意到表,object_id列和索引都有統計資訊了
再來看10.2.0.4的情況
SQL> create table t as select * from all_objects; Table created. SQL> create index t_id on t(object_id); Index created.
$tbsql tabstat t Table Number Empty Average Chain Average OWNER Name of Rows Blocks Blocks Space Count Row Len ---------- ------- -------- ------- ------- -------- ------ -------- SYS T Column Column Distinct Name Details Values Density ---------------- ----------------------- --------- ------- OWNER VARCHAR2(30) NOT NULL OBJECT_NAME VARCHAR2(30) NOT NULL SUBOBJECT_NAME VARCHAR2(30) OBJECT_ID NUMBER(22) NOT NULL DATA_OBJECT_ID NUMBER(22) OBJECT_TYPE VARCHAR2(19) CREATED DATE NOT NULL LAST_DDL_TIME DATE NOT NULL TIMESTAMP VARCHAR2(19) STATUS VARCHAR2(7) TEMPORARY VARCHAR2(1) GENERATED VARCHAR2(1) SECONDARY VARCHAR2(1) 13 rows selected. B Average Average Index Tree Leaf Distinct Leaf Blocks Data Blocks Cluster Name Unique Level Blks Keys Per Key Per Key Factor ------- --------- ----- ------ --------- ----------- ----------- -------- T_ID NONUNIQUE 1 21 9,610 1 1 134 Index Column Col Column Name Name Pos Details --------- ------------ ---- ------------------------ T_ID OBJECT_ID 1 NUMBER(22) NOT NULL
注意到表和列都沒有統計資訊,而索引有統計資訊
SQL> alter index t_id rebuild online compute statistics; Index altered.
$tbsql tabstat t Table Number Empty Average Chain Average OWNER Name of Rows Blocks Blocks Space Count Row Len ------- ------- -------- ------- ------- -------- ------- -------- SYS T Column Column Distinct Name Details Values Density ----------------- ------------------------ ------------ ------- OWNER VARCHAR2(30) NOT NULL OBJECT_NAME VARCHAR2(30) NOT NULL SUBOBJECT_NAME VARCHAR2(30) OBJECT_ID NUMBER(22) NOT NULL DATA_OBJECT_ID NUMBER(22) OBJECT_TYPE VARCHAR2(19) CREATED DATE NOT NULL LAST_DDL_TIME DATE NOT NULL TIMESTAMP VARCHAR2(19) STATUS VARCHAR2(7) TEMPORARY VARCHAR2(1) GENERATED VARCHAR2(1) SECONDARY VARCHAR2(1) 13 rows selected. B Average Average Index Tree Leaf Distinct Leaf Blocks Data Blocks Cluster Name Unique Level Blks Keys Per Key Per Key Factor -------- --------- ----- ------ ---------- ----------- ----------- -------- T_ID NONUNIQUE 1 21 9,610 1 1 134 Index Column Col Column Name Name Pos Details ---------- ------------- ---- ------------------------ T_ID OBJECT_ID 1 NUMBER(22) NOT NULL
注意到表和列還是沒有統計資訊,索引有統計資訊。
應該說,10g的處理方式要更加合理一些。我只是alert index rebuild online compute statistics,9i卻同時收集了表,列和索引的統計資訊,這有點屬於自做主張,而10g則正確的按照語法,只計算了索引的統計資訊。有個時候,收集列的統計資訊,可能導致執行計劃選擇錯誤,尤其是這個列是遞增列的時候,一定要注意到9i和10g的這個差異。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-626506/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【江楓 】Oracle 9i和10g在create index和rebuild index的統計資訊的區別OracleIndexRebuild
- Oracle 10g rebuild index,索引原來統計資訊丟失Oracle 10gRebuildIndex索引
- create index , rebuild index troubleshooting 索引故障解決IndexRebuild索引
- 執行資訊統計後沒有使用索引索引
- 10g resource許可權中沒有create viewView
- Default behavior of create & rebuild index in 10G (zt)RebuildIndex
- oracle 10g表沒有收集統計資訊的一點研究與思考Oracle 10g
- 加快建立索引(create / rebuild index) 的幾點索引RebuildIndex
- oracle 建立或重建索引時收集統計資訊不自動收集(_optimizer_compute_index_stats)Oracle索引Index
- ORACLE表統計資訊與列統計資訊、索引統計資訊Oracle索引
- rebuild index online和create index online及沒有online的區別RebuildIndex
- Oracle表table與索引index的分析及索引重建及統計資訊匯入匯出Oracle索引Index
- Oracle11g,沒有統計資訊時,表的Card從哪來?Oracle
- Sql Server關於create index include帶有包含列的索引的最全解釋SQLServerIndex索引
- create index/create index online區別Index
- CREATE BITMAP INDEXIndex
- 使用dbms_stats列出沒有統計資訊的物件!物件
- 11.2新特性之不可見索引-臨時統計資訊索引
- create和recreate index時縮短時間的選項Index
- create index online 和create index 不同及注意點Index
- Oracle index索引塊分裂split資訊彙總OracleIndex索引
- 9i 100G大小的庫imp到10g庫中後有必要對所有table及index做一次統計分析?Index
- 如何加快建 index 索引 的時間Index索引
- 【STAT】函式索引和使用表示式統計資訊有什麼不同函式索引
- hive orc表'orc.create.index'='true'與'orc.create.index'='false'HiveIndexFalse
- index索引Index索引
- 在收集統計資訊時指定method_opt=>.. size auto 時,有可能不收集直方圖直方圖
- 沒有整合的管理體系便沒有整合的資訊系統
- Oracle 9i統計資訊備份與恢復Oracle
- create index .. onlineIndex
- Unable to create git index lockGitIndex
- create index onlineIndex
- Create Index ...ONLINEIndex
- SQL優化之統計資訊和索引SQL優化索引
- Create index with open on-line index creationIndex
- oracle 9i index bug?OracleIndex
- 沒有審計系統就沒有資料庫安全資料庫
- MySQL中Innodb如何計算索引的統計資訊?MySql索引