複合索引與函式索引優化一例
複合索引與函式索引優化一例
導語:業務上有很多應用需求都是date型別轉換成char型別進行比較求值。這樣的應用,使用索引往往就要應用函式索引,本文講一例函式索引的應用。
SELECT
MAX(tt.workitem_id) workitem_id,
tt.task_id
FROM
doudou tt
WHERE
tt.position_id=5
AND TO_CHAR(tt.pos_rcv_datim, 'yyyymmdd')='20140815'
GROUP BY
tt.task_id;
670 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3539805324
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1862 | 91238 | 4570 (1)| 00:00:55 |
| 1 | HASH GROUP BY | | 1862 | 91238 | 4570 (1)| 00:00:55 |
|* 2 | TABLE ACCESS FULL| DOUDOU | 1864 | 91336 | 4569 (1)| 00:00:55 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("TT"."POSITION_ID"=5 AND
TO_CHAR(INTERNAL_FUNCTION("TT"."POS_RCV_DATIM"),'yyyymmdd')='20140815')
Statistics
----------------------------------------------------------
93 recursive calls
0 db block gets
16855 consistent gets
16637 physical reads
0 redo size
35014 bytes sent via SQL*Net to client
1007 bytes received via SQL*Net from client
46 SQL*Net roundtrips to/from client
47 sorts (memory)
0 sorts (disk)
670 rows processed
IMAGING@doudou1> create index idx_doudou on doudou(TO_CHAR(pos_rcv_datim, 'yyyymmdd'),POSITION_ID) online nologging;
Index created.
IMAGING@doudou1>
SELECT
MAX(tt.workitem_id) workitem_id,
IMAGING@doudou1> 2 3 tt.task_id
4 FROM
5 doudou tt
6 WHERE
7 tt.position_id=5
8 AND TO_CHAR(tt.pos_rcv_datim, 'yyyymmdd')='20140815'
9 GROUP BY
10 tt.task_id;
670 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3748972397
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1862 | 87514 | 167 (1)| 00:00:03 |
| 1 | HASH GROUP BY | | 1862 | 87514 | 167 (1)| 00:00:03 |
| 2 | TABLE ACCESS BY INDEX ROWID| DOUDOU | 1864 | 87608 | 166 (0)| 00:00:02 |
|* 3 | INDEX RANGE SCAN | IDX_DOUDOU | 746 | | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access(TO_CHAR(INTERNAL_FUNCTION("POS_RCV_DATIM"),'yyyymmdd')='20140815'
AND "TT"."POSITION_ID"=5)
Statistics
----------------------------------------------------------
25 recursive calls
0 db block gets
191 consistent gets
5 physical reads
0 redo size
35014 bytes sent via SQL*Net to client
1007 bytes received via SQL*Net from client
46 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
670 rows processed
670 rows selected.
總結:
1.業務需求中這種型別的轉換,開發應和DBA多多進行交流,往往就是一個小問題引起系統的崩潰。儘量減少型別轉換。
2.複合索引與函式索引這種結合也是可以考慮的。自己暗喜一下。
附表:
收集多列統計資訊
begin
dbms_stats.gather_table_stats (
ownname => 'DOUDOU',
tabname => 'DOUDOU',
estimate_percent=> 100,
method_opt => 'FOR ALL COLUMNS SIZE SKEWONLY FOR COLUMNS (pos_rcv_datim,POSITION_ID)',
cascade => TRUE
);
end;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26442936/viewspace-1257559/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SUM優化(複合索引)優化索引
- 高效的SQL(函式索引優化VIEW一例)SQL函式索引優化View
- SQL優化--函式索引SQL優化函式索引
- MySQL函式索引及優化MySql函式索引優化
- 一個複合索引的優化案例索引優化
- 查詢中讓優化器使用複合索引優化索引
- 函式索引使用細節——自定義函式的索引化函式索引
- ORACLE 9i資料庫優化案例(2) --- 單列索引變複合索引的優化Oracle資料庫優化索引
- SQL優化案例-自定義函式索引(五)SQL優化函式索引
- Oracle優化案例-自定義函式索引(五)Oracle優化函式索引
- 增加複合索引優化SQL的簡單過程索引優化SQL
- 利用函式索引,最佳化因cluster factor過高導致不走索引一例函式索引
- MySQL複合索引MySql索引
- 理解索引:索引優化索引優化
- SQL優化案例一則--複合索引沒有被使用SQL優化索引
- MySQL複合索引探究MySql索引
- MySQL建立複合索引MySql索引
- 又一個複合索引的SQL調優索引SQL
- SQLServer索引優化(3):對於建組合索引的要求SQLServer索引優化
- 淺談MySQL的B樹索引與索引優化MySql索引優化
- 索引與null(二):組合索引索引Null
- 藉助索引+非空優化distinct操作一例索引優化
- Oracle優化-索引原理[注意索引跳躍式掃描!Oracle優化索引
- oracle複合索引介紹(多欄位索引)Oracle索引
- SQLT 最佳化SQL 用複合索引代替單列索引的案例SQL索引
- MongoDB索引與優化詳解MongoDB索引優化
- MySQL索引與查詢優化MySql索引優化
- 理解 MySQL(2):索引與優化MySql索引優化
- SQL優化(二)(聯合索引的使用)SQL優化索引
- 【oracle 效能優化】組合索引查詢。Oracle優化索引
- MongoDB複合索引詳解MongoDB索引
- DataFrame刪除複合索引索引
- SQL優化中索引列使用函式之靈異事件SQL優化索引函式事件
- 函式索引陷阱函式索引
- oracle函式索引Oracle函式索引
- sql調優一例---索引排序hintSQL索引排序
- 效能調優-Mysql索引資料結構詳解與索引優化MySql索引資料結構優化
- Elasitcsearch索引優化索引優化