使用索引的误区之三:基于函数的索引
来源:互联网 发布:北京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>
使用基于函数的索引(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>
使用索引的误区之三:基于函数的索引使用基于函数的索引(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>
- 使用索引的误区之三:基于函数的索引
- 使用索引的误区之三:基于函数的索引
- 使用索引的误区之三:基于函数的索引
- 使用索引的误区之三:基于函数的索引
- 使用索引的误区之三:基于函数的索引——Oracle
- 谈索引使用的误区
- 使用索引的误区之六:为索引列都建立索引
- 使用索引的误区之六:为索引列都建立索引
- 使用索引的误区之六:为索引列都建立索引
- 基于函数的索引
- 基于函数的索引
- 使用索引的误区之五:空值的妙用
- 使用索引的误区之五:空值的妙用
- 使用索引的误区之五:空值的妙用
- 使用索引的误区之四:空值对索引的影响
- 使用索引的误区之四:空值对索引的影响
- 使用索引的误区之四:空值对索引的影响
- ★ 使用索引的误区之四:空值对索引的影响
- 远程访问mysql数据库
- 使用索引的误区之六:为索引列都建立索引
- 男人必知的9道最佳解酒食品
- 使用索引的误区之四:空值对索引的影响
- 请到我的百度空间来
- 使用索引的误区之三:基于函数的索引
- 喜欢对联的皇帝朱元璋
- 使用索引的误区之二:使用了和!=操作符,导致查询不使用索引
- 使用索引的误区之一:没有使用复合索引的前导列导致查询不使用索引
- 概论笔记(第三天)
- 利用存储过程简化操作
- 通过function解决部分复杂查询的方法
- 数字签名大碰撞
- 精简出最小 jre