12
返回列表 发新帖
楼主: lession

那位DX能告诉小弟为什么这个查询不使用索引

[复制链接]
论坛徽章:
2
授权会员
日期:2005-10-30 17:05:33会员2006贡献徽章
日期:2006-04-17 13:46:34
11#
发表于 2005-4-30 10:20 | 只看该作者
如果连接的表数目较少,而且统计信息准确,
oracle cbo选择的执行计划应该是最优的。
   不过对rbo,调整还是非常有必要的。

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
17
会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:442010新春纪念徽章
日期:2010-03-01 11:20:05
12#
发表于 2005-5-7 15:14 | 只看该作者
估计全表扫描的表是数据量很小,ORACLE的优化计划就直接不用索引了。-----这是可能一个原因。

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
13#
发表于 2005-5-8 06:14 | 只看该作者

Re: 那位DX能告诉小弟为什么这个查询不使用索引

最初由 lession 发布
[B]
select
  b.deptid, b.deptname
  from dept b,person1 a
where a.personid = b.personid
   and (a.firstname like 'test%'
   or a.lastname like 'test%'
   or a.chinesename like 'test%');

Execution Plan
------------------------------------------------------------   
SELECT STATEMENT, GOAL = RULE                                       
NESTED LOOPS                                       
  TABLE ACCESS FULL        Object owner=TEST Object name=DEPT                       
  TABLE ACCESS BY INDEX ROWID        Object owner=TEST        Object name=PERSON1                       
   INDEX UNIQUE SCAN        Object owner=TEST        Object name=PK_PERSON1 [/B]


I don't understand. Do you want an index scan for DEPT even though you already have an index scan on PK_PERSON1 for PERSON1? That doesn't make sense. A nested loop is supposed to full scan the driving table (preferably the smaller one) and for each row scanned, you find the corresponding row(s) in the other (driven) table, preferably by way of an index on the driven table. If you force Oracle to use PK_DEPT, Oracle may use it but it just adds unnecessary overhead.

Your question is not clear because you didn't say which index you think should be used and is not. If you mean the indexes on non-primary-key columns of PERSON1 should be used and are not, then the reason could be that Oracle thinks restricting by PERSON1's PK is more selective. If you think that's not the case (i.e. there're many people in each department but only 1 or 2 named 'test%'), I suggest you use CBO and gather table stats.

Yong Huang

使用道具 举报

回复
论坛徽章:
0
14#
发表于 2005-5-8 10:09 | 只看该作者
oracle 選用的執行計劃,你
的數據可能很少,與其用index還不如不用

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表