監視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 REBUILD和INDEX REORGANIZE和UPDATE STATISTICS是否涉及Sch-M的案例分析IndexRebuild
- [重慶思莊每日技術分享]-重建LOB欄位上的IndexIndex
- 檢視無線網路卡是否支援監聽模式模式
- 3個最典型的圖表錯誤使用方式,趕緊看看自己是否中招
- 使用IntersectionObserver 實現:自動監聽元素是否進入了裝置的可視區域之內Server
- 監視磁碟使用情況
- 使用BPF監視你的Kubernetes叢集
- 花旗:重建朝鮮的經濟成本需要約631億美元
- 在oracle中監視索引的使用情況Oracle索引
- 使用Shell指令碼程式監控網站URL是否正常指令碼網站
- 016、Vue3+TypeScript基礎,使用watch監視和結束監視VueTypeScript
- db2死鎖監視器的使用(好用)DB2
- MySQL Index Condition Pushdown(ICP)的使用限制MySqlIndex
- 精益生產是否需要高層的支援?
- 小企業是否需要施行ERP?
- PostgreSQL如何檢視page、index的詳細資訊SQLIndex
- 分享實用監控指令碼:使用Shell檢查程式是否存在指令碼
- 資料泵重建使用者
- win10檢視是否使用虛擬記憶體情況 win10是否使用虛擬記憶體在哪裡檢視Win10記憶體
- 探究是否需要@autoreleasepool優化迴圈優化
- Java是否需要內聯型別? -DukesletterJava型別
- synchronized的monitor監視器synchronized
- Java的物件監視器Java物件
- WGCLOUD實時視覺化監控 使用監測FTP和SFTP教程GCCloud視覺化FTP
- Performance Index 64 Pro for Mac(系統效能監測軟體)ORMIndexMac
- map判斷值是否存在需要注意的問題
- 滲透測試是否需要學習LinuxLinux
- 微服務是否真的需要服務網格?微服務
- win10系統如何檢視自己電腦有沒有被監控_win10怎麼檢視自己電腦是否被監控Win10
- Edison 等公司如何監視使用者的電子郵件
- 入門系列之使用Sysdig監視您的Ubuntu 16.04系統Ubuntu
- oracle invisible index與unusable index的區別OracleIndex
- 幽默:重建模、重建和重構
- 為什麼我建議需要定期重建資料量大但是效能關鍵的表
- shell監控服務程式是否啟動
- 教你如何監控網站URL是否正常網站
- win10怎麼檢視expressCache功能是否正常_win10檢視expressCache功能是否正常的方法Win10Express
- Block 形式的通知中心觀察者是否需要手動登出BloC
- wdcp環境innodb結構mysql資料庫表異常需要重建MySql資料庫