Oracle表连接中的索引
如果我这样做,
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 上创建索引,就足够了吗?
if I do
select *
from table1
where table1.col1 = 'xx'
and table1.col2 = 'yy'
and table1.col3= 'zz'`
the execution plan shows full table scan.
The indexes on this table exist for col4 and col5.
Do I need to set an index on each one of col1,col2,col3 to make the query perform better?
Also if the query is like this:
select *
from table1,table2
where table1.col1=table2.col2
and table1.col2 = 'yy'
and table1.col3= 'zz'
If we create an index on col1 and col2, will it suffice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尝试在查询中使用的列上添加索引:
请注意,在某些情况下拥有多列索引也很有好处,例如:
在不了解更多数据的情况下,很难预测哪个索引最有效,但您可以尝试几种不同的可能性,看看哪种索引最有效。
You should try adding indexes on the columns that you are using in the query:
Note that it can also be advantageous in some cases to have multi-column indexes, for example:
It's hard to predict which index will work best without knowing more about your data, but you can try a few different possibilities and see what works best.