【索引】反向索引引起排序
反向索引是B*Tree索引的一個分支,它的設計是為了運用在某些特定的環境下的。Oracle推出它的主要目的就是為了降低在並行(Oracle Parallel Server)環境下索引葉塊的爭用。當B*Tree索引中有一列是由遞增的序列號產生的話,那麼這些索引資訊基本上分佈在同一個葉塊,當使用者修改或訪問相似的列時,索引塊很容易產生爭用。反向索引中的索引碼將會被分佈到各個索引塊中,減少了爭用。也是由於索引被散佈在不同的索引塊中,會引起不必要的排序。
SQL> create table t1 as select * from dba_objects;
Table created.
Elapsed: 00:00:00.66
SQL> create index i_id on t1(object_id);
Index created.
Elapsed: 00:00:00.28
SQL> create table t2 as select * from dba_objects;
Table created.
Elapsed: 00:00:01.89
SQL> create index i_id_t2 on t2(object_id) reverse;
Index created.
Elapsed: 00:00:00.36
--為收集統計資訊之前。
SQL> set autot traceonly
SQL> select object_id from t2 where object_id is not null order by object_id;
53521 rows selected.
Elapsed: 00:00:00.25
Execution Plan
----------------------------------------------------------
Plan hash value: 783427685
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
|* 2 | TABLE ACCESS FULL| T2 |
-----------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("OBJECT_ID" IS NOT NULL)
Note
-----
- rule based optimizer used (consider using cbo)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
738 consistent gets
0 physical reads
0 redo size
975129 bytes sent via SQL*Net to client
39740 bytes received via SQL*Net from client
3570 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
53521 rows processed
SQL> select object_id from t1 where object_id is not null order by object_id;
53519 rows selected.
Elapsed: 00:00:00.26
Execution Plan
----------------------------------------------------------
Plan hash value: 2500393926
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
|* 2 | TABLE ACCESS FULL| T1 |
-----------------------------------
Predicate Information (identified by operation id):
--------------------------------------------------
2 - filter("OBJECT_ID" IS NOT NULL)
Note
-----
- rule based optimizer used (consider using cbo)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
738 consistent gets
0 physical reads
0 redo size
974981 bytes sent via SQL*Net to client
39729 bytes received via SQL*Net from client
3569 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
53519 rows processed
--收集統計資訊之後。
SQL> exec dbms_stats.gather_table_stats(user,'t1');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.73
SQL> exec dbms_stats.gather_table_stats(user,'t2');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.73
SQL> select object_id from t1 where object_id is not null order by object_id;
53519 rows selected.
Elapsed: 00:00:00.25
Execution Plan
----------------------------------------------------------
Plan hash value: 2369746005
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 53519 | 261K| 120 (1)| 00:00:02 |
|* 1 | INDEX FULL SCAN | I_ID | 53519 | 261K| 120 (1)| 00:00:02 |
-------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID" IS NOT NULL)
Statistics
----------------------------------------------------------
138 recursive calls
0 db block gets
3697 consistent gets
0 physical reads
0 redo size
974981 bytes sent via SQL*Net to client
39729 bytes received via SQL*Net from client
3569 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
53519 rows processed
SQL> select object_id from t2 where object_id is not null order by object_id;
53521 rows selected.
Elapsed: 00:00:00.26
Execution Plan
----------------------------------------------------------
Plan hash value: 4001069977
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 53521 | 261K| | 197 (4)| 00:00:03 |
| 1 | SORT ORDER BY | | 53521 | 261K| 1272K| 197 (4)| 00:00:03 |
|* 2 | INDEX FAST FULL SCAN| I_ID_T2 | 53521 | 261K| | 29 (4)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("OBJECT_ID" IS NOT NULL)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
738 consistent gets
0 physical reads
0 redo size
975129 bytes sent via SQL*Net to client
39740 bytes received via SQL*Net from client
3570 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
53521 rows processed
---反向索引可以解決塊爭用的問題,但是如果要對結果集進行排序的話,儘量不要在該表上使用反向索引。不能在所有使用常規索引的地方使用。在範圍搜尋中其不能被使用,例如,where column>value,因為在索引的葉塊中索引碼沒有分類,所以不能透過搜尋相鄰葉塊完成區域掃描。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-672858/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【索引】反向索引--條件 範圍查詢索引
- 反向索引處理前%索引
- oracle之 反向鍵索引Oracle索引
- 【索引】反向索引--條件 範圍查詢(二)索引
- 反向索引與模糊查詢索引
- 使用索引消除排序索引排序
- 【優化】使用反向索引(Reverse Key Indexes)減少索引熱點塊優化索引Index
- 引起索引失效的原因和解決方法索引
- 演算法與排序--索引演算法排序索引
- mysql innodb 索引失效問題引起表級鎖MySql索引
- SQL優化之利用索引排序SQL優化索引排序
- cassandra的索引查詢和排序索引排序
- 索引反向使用案例,加index_desc hint索引Index
- ORACLE 12c索引分裂引起的會話夯Oracle索引會話
- 六條幹貨幫你的MySQL索引起飛MySql索引
- 索引失效系列——繫結變數引起的peeking索引變數
- 【SQL 學習】排序問題之order by與索引排序SQL排序索引
- Oracle 反向索引 where index_column like '%xxx'Oracle索引Index
- 索引無法消除排序的問題索引排序
- 使用索引掃描來進行排序索引排序
- 本地索引、全域性索引、字首索引、非字首索引索引
- MYSQL 字符集不同引起的join無法走索引MySql索引
- 記一次資料庫索引引起的當機。。。資料庫索引
- PHP 實現堆, 堆排序以及索引堆PHP排序索引
- MySQL利用索引優化ORDER BY排序語句MySql索引優化排序
- MYSQL order by排序與索引關係總結MySql排序索引
- 索引裡的NULL值與排序小記索引Null排序
- sql調優一例---索引排序hintSQL索引排序
- 主鍵索引 (聚集索引) 和普通索引 (輔助索引) 的區別索引
- Python Numpy 切片和索引(高階索引、布林索引、花式索引)Python索引
- mysql索引之字首索引MySql索引
- ElasticSearch 索引 VS MySQL 索引Elasticsearch索引MySql
- 理解索引:索引優化索引優化
- 索引@oracle索引技術索引Oracle
- cassandra高階操作之索引、排序以及分頁索引排序
- 索引塊內容dump說明已經排序索引排序
- 索引@oracel索引技術之索引最佳化索引
- 【索引】使用索引分析快速得到索引的基本資訊索引