高分请教索引失效问题

qiqif 2010-09-25 09:36:54
一句语句
select * from tab1 a,tab2 b where a.cino=b.cino and b.v_month='201001'
tab1表的主键为cino tab2(分区表)的主键为cino,v_month
数据量都非常大 都有几百万条以上记录 以上语句分析后没有用到索引
如加一约束如 and a.cino='050800006458541'
如下面
select * from tab1 a,tab2 b where a.cino=b.cino and b.v_month='201001' and a.cino='050800006458541'
两个索引都生效 请教是何原因?如何解决 谢谢
...全文
73 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
minitoy 2010-09-25
  • 打赏
  • 举报
回复
全匹配的话,oracle认为没hash join有效率,所以没走索引.当你加上and a.cino='050800006458541'后,会筛选掉表a中大部分记录,这时候走索引更有效率.
zhone 2010-09-25
  • 打赏
  • 举报
回复
指定使用那个索引 /*+ index(tablename indexname)*/
心中的彩虹 2010-09-25
  • 打赏
  • 举报
回复
[Quote=引用楼主 qiqif 的回复:]
一句语句
select * from tab1 a,tab2 b where a.cino=b.cino and b.v_month='201001'
tab1表的主键为cino tab2(分区表)的主键为cino,v_month
数据量都非常大 都有几百万条以上记录 以上语句分析后没有用到索引
如加一约束如 and a.cino='050800006458541'
如下面
selec……
[/Quote]

你的分区表是怎么建的 以日期还是什么 查询的时候的要指定分区表 速率快些


加强制
/*+ index(tablename indexname)*/
qiqif 2010-09-25
  • 打赏
  • 举报
回复
对啊tab2的主键为cino,v_month
但在select * from tab1 a,tab2 b where a.cino=b.cino and b.v_month='201001'
条件应该都有
  • 打赏
  • 举报
回复
那是啊 你tab2的主键是 cino,v_month这个啊 要这两个条件都在的时候才会走索引的
你可以给v_month 单独建个索引

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧