高效的SQL(index skip scan使用條件)
高效的SQL(index skip scan使用條件)
Index Skip Scan
Index skip scans improve index scans by nonprefix columns. Often, scanning index blocks is faster than scanning table data blocks.
Skip scanning lets a composite index be split logically into smaller subindexes. In skip scanning, the initial column of the composite index is not specified in the query. In other words, it is skipped.
The number of logical subindexes is determined by the number of distinct values in the initial column. Skip scanning is advantageous if there are few distinct values in the leading column of the composite index and many distinct values in the nonleading key of the index.
INDEX SKIP SCAN 使用條件
1、 index skip scan often are used in composite index
2、 leading column (few distinct) and nonleading column (many distinct)
3、 initial column not specified in the query and other words specified in the query
1) leading column(few distinct) are M and F
doudou@TEST> create table tab_skip as select decode(mod(rownum,2),0,'M','F') gender , all_objects.* from all_objects;
Table created.
doudou@TEST> create index tab_skip on tab_skip(gender,object_id);
Index created.
doudou@TEST> exec dbms_stats.gather_table_stats('DOUDOU','TAB_SKIP',cascade=>true);
PL/SQL procedure successfully completed.
doudou@TEST> set autot trace
2) initial column(gender) not specified in the query and other words(object_id) specified in the query
doudou@TEST> select * from tab_skip where object_id=258;
Execution Plan
----------------------------------------------------------
Plan hash value: 123902562
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 97 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TAB_SKIP | 1 | 97 | 4 (0)| 00:00:01 |
|* 2 | INDEX SKIP SCAN | TAB_SKIP | 1 | | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=258)
filter("OBJECT_ID"=258)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
1256 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
【There are “INDEX SKIP SCAN”】
3) leading column(many distinct) are 1..256
doudou@TEST> create table tab_skip01 as select chr(mod(rownum,256)) gender,all_objects.* from all_objects;
Table created.
doudou@TEST> create index tab_skip01 on tab_skip01(gender,object_id);
Index created.
doudou@TEST> exec dbms_stats.gather_table_stats('DOUDOU','TAB_SKIP01',cascade=>true);
PL/SQL procedure successfully completed.
4) initial column(gender) not specified in the query and other words(object_id) specified in the query
doudou@TEST> select * from tab_skip01 where object_id=258;
Execution Plan
----------------------------------------------------------
Plan hash value: 258644213
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 97 | 132 (0)| 00:00:02 |
|* 1 | TABLE ACCESS FULL| TAB_SKIP01 | 1 | 97 | 132 (0)| 00:00:02 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=258)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
583 consistent gets
0 physical reads
0 redo size
1256 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
【There are not “INDEX SKIP SCAN”.Bacause leading column values are (many distinct)】
總結:
INDEX SKIP SCAN使用條件:
1、 組合索引(composite indexes)
2、 領導列選擇度低(leading column few distinct),其他列選擇度高(nonleading column many distinct)
3、 查詢where語句中沒有指明領導列(not specified leading column in the query),但指明瞭其他列(specified nonleading column)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26442936/viewspace-751572/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- index range scan,index fast full scan,index skip scan發生的條件IndexAST
- INDEX SKIP SCANIndex
- 理解index skip scanIndex
- [轉貼]Skip Scan IndexIndex
- 關於INDEX SKIP SCANIndex
- 索引優化index skip scan索引優化Index
- 高效的SQL(Index unique scan最優化)SQLIndex優化
- 高效的SQL(index range scan優化排序)SQLIndex優化排序
- 【TUNE_ORACLE】列出走了INDEX SKIP SCAN的SQL參考OracleIndexSQL
- INDEX SKIP SCAN適用場景Index
- index skip scan的一些實驗。Index
- oracle hint_skip scan_index_ssOracleIndex
- 跳躍式索引(Skip Scan Index)的淺析索引Index
- 【INDEX_SS】使用HINT使SQL用索引跳躍掃描(Index Skip Scan)方式快速獲取資料IndexSQL索引
- 跳躍式索引(Skip Scan Index)淺析 - 轉索引Index
- 【每日一摩斯】-Index Skip Scan Feature (212391.1)Index
- 跳躍式索引掃描(index skip scan) [final]索引Index
- 【SQL】SQL中if條件的使用SQL
- 收集full table / index scan sqlIndexSQL
- 【SQL 提示 之二】index_ss Index Skip HintSQLIndex
- INDEX UNIQUE SCAN,INDEX FULL SCAN和INDEX FAST FULL SCANIndexAST
- [20180725]index skip-scan operation.txtIndex
- 高效的partition(使用分割槽條件)
- Index的掃描方式:index full scan/index fast full scanIndexAST
- rowid,index,INDEX FULL SCAN,INDEX FAST FULL SCAN|IndexAST
- Index Full Scan vs Index Fast Full ScanIndexAST
- Index Full Scan 與 Index Fast Full ScanIndexAST
- INDEX FULL SCAN和INDEX FAST FULL SCAN的區別IndexAST
- [20181201]奇怪的INDEX SKIP SCAN執行計劃.txtIndex
- index full scan 和 index fast full scan (IFS,FFS)的不同IndexAST
- INDEX FULL SCAN和INDEX FAST FULL SCAN區別IndexAST
- index full scan 和 index FAST full scan 區別IndexAST
- Index Full Scan 與 Index Fast Full Scan (Final)IndexAST
- 高效的SQL(index values與index column values關係?)SQLIndex
- Clustered Index Scan and Clustered Index SeekIndex
- sql 使用變數帶入in條件SQL變數
- skip_unusable_index parameterIndex
- Index Unique Scan (213)Index