監視index的使用看看是否需要重建!
SQL> desc t
名稱 是否為空? 型別
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(30)
SQL> select count(*)from t;
COUNT(*)
----------
9848
SQL> create index idx_t on t(id);
索引已建立。
SQL> SET autotrace on
SQL> select count(*)from t where id=1;
COUNT(*)
----------
1
執行計劃
----------------------------------------------------------
Plan hash value: 1500240790
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 4 | | |
|* 2 | INDEX RANGE SCAN| IDX_T | 1 | 4 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=1)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
408 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> SET autotrace off
SQL> delete from t where id>1;
已刪除9847行。
SQL> commit;
提交完成。
SQL> analyze index idx_t validate structure;
索引已分析
SQL> select blocks,lf_rows,lf_blks,del_lf_rows from index_stats where name='IDX_
T';
BLOCKS LF_ROWS LF_BLKS DEL_LF_ROWS
---------- ---------- ---------- -----------
32 9848 21 9847
SQL> alter index idx_t monitoring usage;
索引已更改。
SQL> select count(*)from t where id=1;
COUNT(*)
----------
1
SQL> select index_name,table_name,monitoring,used from v$object_usage;
INDEX_NAME TABLE_NAME MON USE
------------------------------ ------------------------------ --- ---
IDX_T T YES YES
SQL> alter index idx_t nomonitoring usage;
索引已更改。
SQL> select index_name,table_name,monitoring,used from v$object_usage;
INDEX_NAME TABLE_NAME MON USE
------------------------------ ------------------------------ --- ---
IDX_T T NO YES
SQL> set autotrace on
SQL> select count(*)from t where id=1;
COUNT(*)
----------
1
執行計劃
----------------------------------------------------------
Plan hash value: 2371838348
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 6 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
|* 2 | INDEX FAST FULL SCAN| IDX_T | 1 | 2 | 6 (0)| 00:00:01 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=1)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
26 consistent gets
0 physical reads
0 redo size
408 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> set autotrace off
SQL> alter index idx_t monitoring usage;
索引已更改。
SQL> select /*+ rule */ count(*)from t where id=1;
COUNT(*)
----------
1
SQL> select index_name,table_name,monitoring,used from v$object_usage;
INDEX_NAME TABLE_NAME MON USE
------------------------------ ------------------------------ --- ---
IDX_T T YES YES
SQL> set autotrace on
SQL> select /*+ rule */ count(*)from t where id=1;
COUNT(*)
----------
1
執行計劃
----------------------------------------------------------
Plan hash value: 1500240790
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT AGGREGATE | |
|* 2 | INDEX RANGE SCAN| IDX_T |
-----------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=1)
Note
-----
- rule based optimizer used (consider using cbo)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
408 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> alter index idx_t nomonitoring usage;
索引已更改。
SQL>
--================================
SQL> alter index idx_t monitoring usage;
索引已更改。
SQL> select index_name,table_name,monitoring,used from v$object_usage;
INDEX_NAME TABLE_NAME MON USE
------------------------------ ------------------------------ --- ---
IDX_T T YES NO
SQL> set autotrace on
SQL> select /*+ no_index(t idx_t) */ count(*)from t where id=1;
COUNT(*)
----------
1
執行計劃
----------------------------------------------------------
Plan hash value: 2966233522
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 11 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
|* 2 | TABLE ACCESS FULL| T | 1 | 2 | 11 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=1)
統計資訊
----------------------------------------------------------
127 recursive calls
0 db block gets
57 consistent gets
0 physical reads
0 redo size
408 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select /*+ no_index(t idx_t) */ count(*)from t where id=1;
COUNT(*)
----------
1
執行計劃
----------------------------------------------------------
Plan hash value: 2966233522
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 11 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
|* 2 | TABLE ACCESS FULL| T | 1 | 2 | 11 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("ID"=1)
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
40 consistent gets
0 physical reads
0 redo size
408 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> set autotrace off
SQL> select index_name,table_name,monitoring,used from v$object_usage;
INDEX_NAME TABLE_NAME MON USE
------------------------------ ------------------------------ --- ---
IDX_T T YES NO
SQL>
我的試驗效果不是很理想,當刪除了大量資料之後,還是選擇使用了index,透過執行計劃對比發現使用索引所需要的邏輯讀確實比全表掃表還要小。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/19602/viewspace-1024820/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 監控index是否被使用Index
- 監控Index是否被使用過的方法Index
- 監視index的使用情況Index
- 監控index 的使用情況Index
- 自動重建失效index的shell指令碼Index指令碼
- 如何監控oracle的索引是否使用Oracle索引
- 【INDEX】重建索引的兩條參考依據Index索引
- 【INDEX】使用“alter index ××× monitoring usage;”語句監控索引使用與否Index索引
- SQL Server2000 刪除大量資料後需要重建index或rebuild 麼 ?SQLServerIndexRebuild
- index 監控Index
- 監控Oracle索引是否被使用?Oracle索引
- Oracle資料庫監控Index的使用情況Oracle資料庫Index
- oracle對字元型別的列上線上重建index的限制!Oracle字元型別Index
- 關於rebuild index online 及drop index後重建問題RebuildIndex
- 重建索引index rebuild online vs offline vs index coalesce vs index shrik space索引IndexRebuild
- 使用index_stats檢視檢視索引效率Index索引
- 把握安全監視你的網路是否受到攻擊(轉)
- 檢視無線網路卡是否支援監聽模式模式
- 你是否需要GitHub?Github
- 使用select監視update的操作
- INDEX REBUILD和INDEX REORGANIZE和UPDATE STATISTICS是否涉及Sch-M的案例分析IndexRebuild
- 你需要了解的z-index世界Index
- 使用memadmin視覺化監視我們的memcache視覺化
- [重慶思莊每日技術分享]-重建LOB欄位上的IndexIndex
- adpatch 時是否需要停應用,opatch是否需要停資料庫資料庫
- 客戶端的socket是否需要bind?客戶端
- 大家幫我看看,下面寫的是否對。(web.xml)WebXML
- 官方mysql中檢視索引是否被使用到MySql索引
- 使用pidstat命令監視某程式的資源使用
- 啟動資料庫,啟動監聽,檢視是否歸檔資料庫
- 值物件是否需要持久化物件持久化
- 看看一段工廠模式的程式碼是否正確?模式
- 使用Shell指令碼程式監控網站URL是否正常指令碼網站
- 查詢使用表空間的TABLE,INDEX,INDEX SUBPARTITIONIndex
- 建立檢視和淺析LOCAL INDEX和GLOBAL INDEXIndex
- db2死鎖監視器的使用(好用)DB2
- 是否需要漢語程式語言
- Oracle什麼情況下需要rebuild indexOracleRebuildIndex