Oracle PL/SQL之函数索引(Function-based indexes)使用示例


函数索引(Function-based indexes)只有在where条件使用了与索引中相同的基于相同列的函数时才起作用。 
  1. duzz$scott@orcl>set autotrace on  
  2. duzz$scott@orcl>create table t1 as select * from dept;  
  3.   
  4. Table created.  
  5.   
  6. Elapsed: 00:00:00.01  
  7. duzz$scott@orcl>create index loc_idx on t1(upper(loc));  
  8.   
  9. Index created.  
  10.   
  11. Elapsed: 00:00:00.06  
  12. duzz$scott@orcl>select * from t1 where deptno=20;  
  13.   
  14.     DEPTNO DNAME                                      LOC  
  15. ---------- ------------------------------------------ ------------   
  16.         20 RESEARCH                                   DALLAS  
  17.   
  18. Elapsed: 00:00:00.00  
  19.   
  20. Execution Plan  
  21. ----------------------------------------------------------   
  22. Plan hash value: 3617692013  
  23.   
  24. --------------------------------------------------------------------------   
  25. | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |  
  26. --------------------------------------------------------------------------   
  27. |   0 | SELECT STATEMENT  |      |     1 |    30 |     3   (0)| 00:00:01 |  
  28. |*  1 |  TABLE ACCESS FULL| T1   |     1 |    30 |     3   (0)| 00:00:01 |  
  29. --------------------------------------------------------------------------   
  30.   
  31. Predicate Information (identified by operation id):  
  32. ---------------------------------------------------   
  33.   
  34.    1 - filter("DEPTNO"=20)  
  35.   
  36. Note  
  37. -----   
  38.    - dynamic sampling used for this statement  
  39.   
  40.   
  41. Statistics  
  42. ----------------------------------------------------------   
  43.          48  recursive calls  
  44.           0  db block gets  
  45.          12  consistent gets  
  46.           0  physical reads  
  47.           0  redo size  
  48.         533  bytes sent via SQL*Net to client  
  49.         385  bytes received via SQL*Net from client  
  50.           2  SQL*Net roundtrips to/from client  
  51.           0  sorts (memory)  
  52.           0  sorts (disk)  
  53.           1  rows processed  
  54.   
  55. duzz$scott@orcl>select * from t1 where loc='DALLAS';  
  56.   
  57.     DEPTNO DNAME                                      LOC  
  58. ---------- ------------------------------------------ -----------------   
  59.         20 RESEARCH                                   DALLAS  
  60.   
  61. Elapsed: 00:00:00.00  
  62.   
  63. Execution Plan  
  64. ----------------------------------------------------------   
  65. Plan hash value: 3617692013  
  66.   
  67. --------------------------------------------------------------------------   
  68. | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |  
  69. --------------------------------------------------------------------------   
  70. |   0 | SELECT STATEMENT  |      |     1 |    30 |     3   (0)| 00:00:01 |  
  71. |*  1 |  TABLE ACCESS FULL| T1   |     1 |    30 |     3   (0)| 00:00:01 |  
  72. --------------------------------------------------------------------------   
  73.   
  74. Predicate Information (identified by operation id):  
  75. ---------------------------------------------------   
  76.   
  77.    1 - filter("LOC"='DALLAS')  
  78.   
  79. Note  
  80. -----   
  81.    - dynamic sampling used for this statement  
  82.   
  83.   
  84. Statistics  
  85. ----------------------------------------------------------   
  86.           5  recursive calls  
  87.           0  db block gets  
  88.           8  consistent gets  
  89.           0  physical reads  
  90.           0  redo size  
  91.         533  bytes sent via SQL*Net to client  
  92.         385  bytes received via SQL*Net from client  
  93.           2  SQL*Net roundtrips to/from client  
  94.           0  sorts (memory)  
  95.           0  sorts (disk)  
  96.           1  rows processed  
  97.   
  98. duzz$scott@orcl>select * from t1 where upper(loc)='DALLAS';  
  99.   
  100.     DEPTNO DNAME                                      LOC  
  101. ---------- ------------------------------------------ ----------------------   
  102.         20 RESEARCH                                   DALLAS  
  103.   
  104. Elapsed: 00:00:00.01  
  105.   
  106. Execution Plan  
  107. ----------------------------------------------------------   
  108. Plan hash value: 3763008475  
  109.   
  110. ---------------------------------------------------------------------------------------   
  111. | Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Time     |  
  112. ---------------------------------------------------------------------------------------   
  113. |   0 | SELECT STATEMENT            |         |     1 |    30 |     2   (0)| 00:00:01 |  
  114. |   1 |  TABLE ACCESS BY INDEX ROWID| T1      |     1 |    30 |     2   (0)| 00:00:01 |  
  115. |*  2 |   INDEX RANGE SCAN          | LOC_IDX |     1 |       |     1   (0)| 00:00:01 |  
  116. ---------------------------------------------------------------------------------------   
  117.   
  118. Predicate Information (identified by operation id):  
  119. ---------------------------------------------------   
  120.   
  121.    2 - access(UPPER("LOC")='DALLAS')  
  122.   
  123. Note  
  124. -----   
  125.    - dynamic sampling used for this statement  
  126.   
  127.   
  128. Statistics  
  129. ----------------------------------------------------------   
  130.          28  recursive calls  
  131.           0  db block gets  
  132.           9  consistent gets  
  133.           0  physical reads  
  134.           0  redo size  
  135.         533  bytes sent via SQL*Net to client  
  136.         385  bytes received via SQL*Net from client  
  137.           2  SQL*Net roundtrips to/from client  
  138.           0  sorts (memory)  
  139.           0  sorts (disk)  
  140.           1  rows processed  
  141.   
  142. duzz$scott@orcl>  

REF:

http://download.Oracle.com/docs/cd/B19306_01/server.102/b14200/statements_5010.htm

相关内容