【江楓 】Oracle 9i和10g在create index和rebuild index的統計資訊的區別
在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的這個差異。
http://rdc.taobao.com/blog/dba/html/192_differencts_for_statistics_create_or_rebuild_index_9i_
<!--來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1384/viewspace-406968/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- rebuild index 和 recreate index (重新建立index) 的區別RebuildIndex
- alter index rebuild和rebuild online的區別IndexRebuild
- 10g在create index時就有索引統計資訊,9i 沒有Index索引
- rebuild index online和create index online及沒有online的區別RebuildIndex
- Oracle 10g rebuild index,索引原來統計資訊丟失Oracle 10gRebuildIndex索引
- Default behavior of create & rebuild index in 10G (zt)RebuildIndex
- create index/create index online區別Index
- ORACLE中index的rebuildOracleIndexRebuild
- create index , rebuild index troubleshooting 索引故障解決IndexRebuild索引
- pk 、unique index 和 index 區別Index
- 【羅玄】從鎖的角度看rebuild index online和rebuild indexRebuildIndex
- 【Oracle】global index & local index的區別OracleIndex
- 加快create / rebuild index的3個點(zt)RebuildIndex
- 加快建立索引(create / rebuild index) 的幾點索引RebuildIndex
- create index online 與rebuild index onlineIndexRebuild
- create index online 與rebuild index onlineIndexRebuild
- INDEX FULL SCAN和INDEX FAST FULL SCAN的區別IndexAST
- INDEX REBUILD和INDEX REORGANIZE和UPDATE STATISTICS是否涉及Sch-M的案例分析IndexRebuild
- create index online 和create index 不同及注意點Index
- INDEX FULL SCAN和INDEX FAST FULL SCAN區別IndexAST
- index full scan 和 index FAST full scan 區別IndexAST
- 聊聊索引Index Rebuild和Rebuild Online(下)索引IndexRebuild
- 聊聊索引Index Rebuild和Rebuild Online(上)索引IndexRebuild
- alter index ind1 rebuild 和alter index ind1 rebuild onlineIndexRebuild
- rebuild indexRebuildIndex
- index rebuildIndexRebuild
- oracle invisible index與unusable index的區別OracleIndex
- global index & local index的區別Index
- index 和 index_desc hints的一點有意思的區別Index
- Oracle create/rebuild index開並行時要記得noparallel哦~OracleRebuildIndex並行Parallel
- Oracle alter index rebuild 說明OracleIndexRebuild
- oracle index unique scan/index range scan和mysql range/const/ref/eq_ref的區別OracleIndexMySql
- rebuild index 排序RebuildIndex排序
- sybase rebuild indexRebuildIndex
- alter index rebuild與index_statsIndexRebuild
- 關於move table和rebuild index批量操作的記錄RebuildIndex
- oracle 9i index bug?OracleIndex
- Index rebuild --case 1IndexRebuild