表连接中的oracle索引

时间:2011-03-09 22:33:49

标签: oracle10g

如果我这样做

select * 
    from table1 
    where table1.col1 = 'xx' 
        and table1.col2 = 'yy' 
        and table1.col3= 'zz'`

执行计划显示全表扫描。 col4和col5上存在此表的索引。 我是否需要在col1,col2,col3中的每一个上设置索引以使查询执行得更好?

此外,如果查询是这样的:

select * 
    from table1,table2 
    where table1.col1=table2.col2 
        and table1.col2 = 'yy' 
        and table1.col3= 'zz'

如果我们在col1和col2上创建一个索引,它就足够了吗?

1 个答案:

答案 0 :(得分:1)

您应该尝试在查询中使用的列上添加索引:

  • table1 col1
  • table1 col2
  • table1 col3
  • table2 col2

请注意,在某些情况下,使用多列索引也是有利的,例如:

  • table1(col2,col3)

如果不了解您的数据,很难预测哪种指数最有效,但您可以尝试一些不同的可能性,看看哪种方法效果最佳。