使用索引的误区之三:基于函数的索引

来源:互联网 发布:北京ps软件培训 编辑:程序博客网 时间:2024/04/30 21:45
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
使用索引误区之三基于函数索引
使用基于函数索引(BFI,BasedFunctionIndex):

从8i开始,可以使用基于函数索引来提高查询性能,

 

使用基于函数索引,需要几个条件:

1, 用户需要有createindex或者createanyindex权限

2, 用户需要有queryrewrite或者globalqueryrewirte权限

3, 设置系统参数query_rewrite_enabled=TRUE

和query_rewrite_integrity=enforced

4, 设置系统参数:COMPATIBLE=8.1.0.0.0或者更高

5,创建了BFI后,需要对表进行分析

 

请看下面的例子:

首先,在没有建立函数索引的情况下,我们看到查询没有如我们想想一样使用单列(dname)索引

SQL>setautotracetraceonly

SQL>select*fromdeptwheresubstr(dname,1,5)='aaa';

 

未选定行

 

已用时间: 00:00:00.00

 

ExecutionPlan

----------------------------------------------------------

  0     SELECTSTATEMENTOptimizer=CHOOSE

  1   0  TABLEACCESS(FULL)OF'DEPT'

 

 

 

 

Statistics

----------------------------------------------------------

       134 recursivecalls

         0 dbblockgets

        20 consistentgets

         0 physicalreads

         0 redosize

       323 bytessentviaSQL*Nettoclient

       372 bytesreceivedviaSQL*Netfromclient

         1 SQL*Netroundtripsto/fromclient

         2 sorts(memory)

         0 sorts(disk)

         0 rowsprocessed

 

 

 

下面直接建立基于函数索引,看看是否查询是否可以使用我们建立的索引

SQL>createindexdept_id5ondept(substr(dname,1,5));

createindexdept_id5ondept(substr(dname,1,5))

                                            *

ERROR位于第1行:

ORA-01031:权限不足

 

 

已用时间: 00:00:00.00

SQL>setautotraceoff

SQL>colusernameformata10

SQL>colprivilegeformata20

SQL>selectusername,privilegefromuser_sys_privs;

 

USERNAME  PRIVILEGE

------------------------------

DEMO      UNLIMITEDTABLESPACE

PUBLIC    SELECTANYTABLE

 

已用时间: 00:00:00.00

SQL>selectusername,granted_rolefromuser_role_privs;

 

USERNAME  GRANTED_ROLE

----------------------------------------

DEMO      CONNECT

DEMO      RESOURCE

PUBLIC    PLUSTRACE上一页 
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击