隐式转换引起的索引失效
SQL> create table test1 (userid varchar2(10));
Table created.
SQL> select * from test1;
no rows selected
SQL> insert into test1 select object_id from dba_objects;
72693 rows created.
SQL> create index id_idx on test1 (userid);
Index created.
SQL> set autotrace trace
SQL> select * from test1 where userid=2; --条件是number类型
Execution Plan
----------------------------------------------------------
Plan hash value: 4122059633
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 7 | 33 (4)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST1 | 1 | 7 | 33 (4)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(TO_NUMBER("USERID")=2)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
116 consistent gets
0 physical reads
0 redo size
523 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select * from test1 where userid='2'; --加上引号后变成字符类型
Execution Plan
----------------------------------------------------------
Plan hash value: 1357208269
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 7 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| ID_IDX | 1 | 7 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("USERID"='2')
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
523 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26655292/viewspace-753368/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26655292/viewspace-753368/