cursor_sharing和substr函式索引
當cursor_sharing設定為similar的時候substr的函式索引將不會起作用,例如函式是substr(column,0,3),cursor_sharing為similar或者force的時候,這個條件會被解析成SUBSTR(column,:SYS_B_0,:SYS_B_1)=:SYS_B_2,這是函式索引將不會起作用,oracle認為是unsafe的,因為substr(column,0,1)和substr(column,1,2)解析後的格式都是一樣的,例如:
SQL> create table test_function as select * from dba_objects;
表已建立。
SQL> show parameter cursor_sharing
NAME TYPE
------------------------------------ --------------------------------
VALUE
------------------------------
cursor_sharing string
SIMILAR
SQL> set autot trace
SQL> create index i_test_function on test_function(substr(object_name,0,3));
索引已建立。
SQL> exec dbms_stats.gather_table_stats(user,'TEST_FUNCTION',method_opt=>'for all columns size 254')
;
PL/SQL 過程已成功完成。
SQL> set autot trace
SQL> select /*+ aa */ * from test_function where substr(object_name,0,3)='aaa';
未選定行
執行計劃
----------------------------------------------------------
Plan hash value: 3877315499
--------------------------------------------------------------------------------
---------------
| Id | Operation | Name | Rows | Bytes | Cost (%C
PU)| Time |
--------------------------------------------------------------------------------
---------------
| 0 | SELECT STATEMENT | | 103 | 9991 | 34
(0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST_FUNCTION | 103 | 9991 | 34
(0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | I_TEST_FUNCTION | 103 | | 1
(0)| 00:00:01 |
--------------------------------------------------------------------------------
---------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access(SUBSTR("OBJECT_NAME",0,3)='aaa')
統計資訊
----------------------------------------------------------
1464 recursive calls
0 db block gets
1086 consistent gets
1 physical reads
0 redo size
996 bytes sent via SQL*Net to client
389 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
96 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select sql_text,sql_id from v$sql where sql_text like '%/*+ aa */%';
SQL_TEXT
--------------------------------------------------------------------------------
SQL_ID
-------------
EXPLAIN PLAN SET STATEMENT_ID='PLUS4294967295' FOR select /*+ aa */ * from test_
function where substr(object_name,0,3)='aaa'
cgcr4m0jju12u
select /*+ aa */ * from test_function where substr(object_name,:"SYS_B_0",:"SYS_
B_1")=:"SYS_B_2"
905r3hh7vk6sy
SQL> select * from table(dbms_xplan.display_cursor('905r3hh7vk6sy'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID 905r3hh7vk6sy, child number 0
-------------------------------------
select /*+ aa */ * from test_function where
substr(object_name,:"SYS_B_0",:"SYS_B_1")=:"SYS_B_2"
Plan hash value: 3258248351
--------------------------------------------------------------------------------
---
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
---
| 0 | SELECT STATEMENT | | | | 160 (100)|
|
|* 1 | TABLE ACCESS FULL| TEST_FUNCTION | 499 | 48403 | 160 (5)| 00:00:0
2 |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(SUBSTR("OBJECT_NAME",:SYS_B_0,:SYS_B_1)=:SYS_B_2)
已選擇19行。
SQL> create table test_function as select * from dba_objects;
表已建立。
SQL> show parameter cursor_sharing
NAME TYPE
------------------------------------ --------------------------------
VALUE
------------------------------
cursor_sharing string
SIMILAR
SQL> set autot trace
SQL> create index i_test_function on test_function(substr(object_name,0,3));
索引已建立。
SQL> exec dbms_stats.gather_table_stats(user,'TEST_FUNCTION',method_opt=>'for all columns size 254')
;
PL/SQL 過程已成功完成。
SQL> set autot trace
SQL> select /*+ aa */ * from test_function where substr(object_name,0,3)='aaa';
未選定行
執行計劃
----------------------------------------------------------
Plan hash value: 3877315499
--------------------------------------------------------------------------------
---------------
| Id | Operation | Name | Rows | Bytes | Cost (%C
PU)| Time |
--------------------------------------------------------------------------------
---------------
| 0 | SELECT STATEMENT | | 103 | 9991 | 34
(0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST_FUNCTION | 103 | 9991 | 34
(0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | I_TEST_FUNCTION | 103 | | 1
(0)| 00:00:01 |
--------------------------------------------------------------------------------
---------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access(SUBSTR("OBJECT_NAME",0,3)='aaa')
統計資訊
----------------------------------------------------------
1464 recursive calls
0 db block gets
1086 consistent gets
1 physical reads
0 redo size
996 bytes sent via SQL*Net to client
389 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
96 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select sql_text,sql_id from v$sql where sql_text like '%/*+ aa */%';
SQL_TEXT
--------------------------------------------------------------------------------
SQL_ID
-------------
EXPLAIN PLAN SET STATEMENT_ID='PLUS4294967295' FOR select /*+ aa */ * from test_
function where substr(object_name,0,3)='aaa'
cgcr4m0jju12u
select /*+ aa */ * from test_function where substr(object_name,:"SYS_B_0",:"SYS_
B_1")=:"SYS_B_2"
905r3hh7vk6sy
SQL> select * from table(dbms_xplan.display_cursor('905r3hh7vk6sy'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID 905r3hh7vk6sy, child number 0
-------------------------------------
select /*+ aa */ * from test_function where
substr(object_name,:"SYS_B_0",:"SYS_B_1")=:"SYS_B_2"
Plan hash value: 3258248351
--------------------------------------------------------------------------------
---
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
---
| 0 | SELECT STATEMENT | | | | 160 (100)|
|
|* 1 | TABLE ACCESS FULL| TEST_FUNCTION | 499 | 48403 | 160 (5)| 00:00:0
2 |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(SUBSTR("OBJECT_NAME",:SYS_B_0,:SYS_B_1)=:SYS_B_2)
已選擇19行。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8984272/viewspace-619912/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ascii函式和substr函式的用法ASCII函式
- substr函式函式
- [20120612]函式索引中使用substr函式.txt函式索引
- [20150513]函式索引與CURSOR_SHARING=FORCE函式索引
- insert()與substr()函式函式
- instr、substr函式用法函式
- substr擷取函式 筆記函式筆記
- sequence 和索引函式呼叫索引函式
- 【轉】oracle的substr函式的用法Oracle函式
- [20241012]cursor_sharing=force與函式索引.txt函式索引
- 字元函式之Substr(chr,0,m)與Substr(chr,m)的區別字元函式
- js字串擷取函式slice()、substring()、substr()JS字串函式
- 函式索引陷阱函式索引
- oracle函式索引Oracle函式索引
- Javascript之字串擷取函式slice()、substring()、substr()JavaScript字串函式
- 函式索引使用細節——自定義函式的索引化函式索引
- Oracle中REGEXP_SUBSTR函式(字串轉多行)Oracle函式字串
- Oracle之函式索引Oracle函式索引
- 說說函式索引函式索引
- 索引中使用函式索引函式
- 【正則】oracle正規表示式函式之REGEXP_REPLACE和REGEXP_SUBSTROracle函式
- JS字串擷取函式slice(),substring(),substr()的區別JS字串函式
- PHP字串替換substr_replace與str_replace函式PHP字串函式
- 基於函式的索引函式索引
- 函式索引的問題函式索引
- deterministic function 函式索引Function函式索引
- 函式索引的儲存函式索引
- SQL優化--函式索引SQL優化函式索引
- 【轉】linux下awk內建函式的使用(split/substr/length)Linux函式
- php函式substr_replace中文亂碼的替代解決方法PHP函式
- query rewrite和基於函式的索引有關係?函式索引
- day25-索引和函式及儲存過程索引函式儲存過程
- 【STAT】函式索引和使用表示式統計資訊有什麼不同函式索引
- Oracle索引梳理系列(六)- Oracle索引種類之函式索引Oracle索引函式
- MySQL函式索引及優化MySql函式索引優化
- Oracle基於函式的索引Oracle函式索引
- 索引ROWID轉換函式索引函式
- 複合索引與函式索引優化一例索引函式優化