【索引】反向索引--條件 範圍查詢
---檢視索引的型別
SQL> col table_name for a10
SQL> col index_name foa a10
SQL> select table_name ,index_name ,index_type from user_indexes where table_name in ('T1','T2');
TABLE_NAME INDEX_NAME INDEX_TYPE
---------- ------------------------------ ---------------------------
T2 I_ID_T2 NORMAL/REV ---反向索引
T1 I_ID NORMAL ---常規索引
Elapsed: 00:00:00.08
---手動轉變索引的型別
SQL> alter index i_id rebuild reverse; ---將常規索引轉變為反向索引
Index altered.
Elapsed: 00:00:00.36
SQL> alter index i_id_t2 rebuild noreverse;---將反向索引轉變為常規索引
Index altered.
Elapsed: 00:00:00.30
SQL> select table_name ,index_name ,index_type from user_indexes where table_name in ('T1','T2');
TABLE_NAME INDEX_NAME INDEX_TYPE
---------- ------------------------------ ---------------------------
T2 I_ID_T2 NORMAL
T1 I_ID NORMAL/REV
Elapsed: 00:00:00.00
---檢視反向索引對於範圍查詢和比較 < > 條件查詢的執行計劃 表t1 是反向索引,走iffs 原因:因為這裡select 的欄位是索引欄位,所以走了iffs。
SQL> set autot traceonly
SQL> select object_id from t1 where object_id between 2 and 50;
49 rows selected.
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 711836071
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 15 | 75 | 29 (4)| 00:00:01 |
|* 1 | INDEX FAST FULL SCAN| I_ID | 15 | 75 | 29 (4)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"<=50 AND "OBJECT_ID">=2)
Statistics
----------------------------------------------------------
15 recursive calls
0 db block gets
132 consistent gets
118 physical reads
.
.
.
49 rows processed
Elapsed: 00:00:00.00
--表t2 走range scan 常規索引
SQL> select object_id from t2 where object_id between 2 and 50;
49 rows selected.
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 3216146664
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 26 | 130 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| I_ID_T2 | 26 | 130 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("OBJECT_ID">=2 AND "OBJECT_ID"<=50)
Statistics
----------------------------------------------------------
15 recursive calls
.
.
.
49 rows processed
-----全表掃描,由於select * 選擇所有的欄位資訊,object_id 索引裡面的資料不能滿足要求,所以走了全表掃描,當然,更重要的原因是因為索引項在索引塊中的雜亂排序。
SQL> select * from t1 where object_id between 2 and 50;
49 rows selected.
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 838529891
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 15 | 1395 | 164 (2)| 00:00:02 |
|* 1 | TABLE ACCESS FULL| T1 | 15 | 1395 | 164 (2)| 00:00:02 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"<=50 AND "OBJECT_ID">=2)
Statistics
----------------------------------------------------------
244 recursive calls
0 db block gets
778 consistent gets
0 physical reads
0 redo size
3278 bytes sent via SQL*Net to client
525 bytes received via SQL*Net from client
5 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
49 row
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-672884/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【索引】反向索引--條件 範圍查詢(二)索引
- Mysql索引的使用 - 組合索引 + 範圍條件的處理MySql索引
- MongoDB範圍查詢的索引優化MongoDB索引優化
- 反向索引與模糊查詢索引
- 關於聯合索引,範圍查詢,時間列索引的幾個問題索引
- MySQL 唯一索引範圍查詢鎖下一個記錄的理解MySql索引
- MYSQL DQL in 到底會不會走索引&in 範圍查詢引發的思考。MySql索引
- 【索引】Oracle查詢指定索引提高查詢效率索引Oracle
- 【索引】反向索引引起排序索引排序
- oracle 索引升降序及排序條件 對查詢計劃的影響Oracle索引排序
- MySQL實驗: 實踐索引對全列匹配、最左字首匹配、範圍查詢等條件的影響以及瞭解髒讀、幻讀等MySql索引
- Mysql索引的使用-組合索引+跳躍條件MySql索引
- elasticsearch之多索引查詢Elasticsearch索引
- Elasticsearch(三):索引查詢Elasticsearch索引
- 查詢索引 常用SQL索引SQL
- 查詢相似的索引索引
- 【索引】oracle查詢使用索引和不使用索引的比較索引Oracle
- ElasticSearch分片互動過程(建立索引、刪除索引、查詢索引)Elasticsearch索引
- 【原創】MySQL 模擬條件索引MySql索引
- MongoDB查詢條件MongoDB
- MongoDB條件查詢MongoDB
- mysql條件查詢MySql
- MongoDB慢查詢與索引MongoDB索引
- 字母索引查詢ListView元件索引View元件
- mysql查詢索引結構MySql索引
- 根據某個查詢條件的前50條資料來決定UPDATE語句的更新範圍
- 索引監控-查詢從未被使用過的索引索引
- Oracle日期時間範圍查詢Oracle
- 【原創】MySQL 模擬條件索引薦MySql索引
- 謂詞條件是is null走索引嗎?Null索引
- 反向索引處理前%索引
- oracle之 反向鍵索引Oracle索引
- Laravel 多條件查詢Laravel
- SQL多條件查詢SQL
- 條件查詢JSPJS
- MySQL索引與查詢優化MySql索引優化
- (利用索引)大資料查詢索引大資料
- 根據表查詢索引資訊索引