Oracle 选择了错误的索引
我在 Oracle 中建立索引时遇到问题。将尝试用一个实例来解释我的问题,如下所示。
我有一个表 TABLE1,其中包含 A、B、C、D 列 另一个表 TABLE2 包含 A、B、C、E、F、H 列
我已经为 TABLE1 创建了索引
IX_1 A
IX_2 A,B
IX_3 A,C
IX_4 A,B,C
我已经为 TABLE1 创建了索引
IY_1 A,B,C
IY_2 A
当我给出与此类似的查询时,
SELECT * FROM TABLE1 T1,TABLE2 T2
WHERE T1.A=T2.A
当我给出解释计划时,我得到它没有得到 IX_1 也没有得到 IY_2
它采取IX_4 或 IY_1
为什么这没有选择正确的索引?
编辑:
任何人都可以帮助我了解 INDEX RANGE SCAN、INDEX UNIQUE SCAN、INDEX SKIP SCAN 之间的区别
我想 SKIP SCAN 意味着当 Oracle 在复合索引中跳过一列时,
其他我不知道怎么办!
I have a problem in indexing in Oracle. Will try to explain my problem with an instance as follows.
I have a table TABLE1 with columns A,B,C,D
another table TABLE2 with columns A,B,C,E,F,H
I have created Indexes for TABLE1
IX_1 A
IX_2 A,B
IX_3 A,C
IX_4 A,B,C
I have created Indexes for TABLE1
IY_1 A,B,C
IY_2 A
when i gave query similar to this
SELECT * FROM TABLE1 T1,TABLE2 T2
WHERE T1.A=T2.A
When i give Explain Plan i got its not getting IX_1 nor IY_2
Its taking IX_4 nor IY_1
why this is not picking right index?
EDITED:
Can anyone help me to know difference between INDEX RANGE SCAN,INDEX UNIQUE SCAN, INDEX SKIP SCAN
I guess SKIP SCAN means when a column is skipped in Composite Index by Oracle
what about others i dont have idea!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
索引的最大好处是您可以从表中选择几行,而无需扫描整个表。
如果您请求太多行(假设 30% - 取决于很多因素),引擎将更愿意扫描整个表以查找这些行。
这是因为使用索引读取行会产生开销:读取一些索引块,然后读取表块。
在您的情况下,为了连接表 T1 和 T2,Oracle 需要这些表中的所有行。读取(完整)索引将是一个不完整的操作,会增加不必要的成本。
更新:向前迈出一步:如果运行:
Oracle可能会使用索引(IX2,IY2),因为它不需要从表中读取任何内容,因为值T1.B,T2.B ,位于索引中。
The best benefit of indexes is that you can select a few rows from a table without scanning the entire table.
If you ask for too many rows(let's say 30% - depends of many things) the engine will prefer to scan the entire table for those rows.
That's because reading a row using an index is gets an overhead : reading some index blocks, and after that reading table blocks.
In your case, in order to join tables T1 and T2, Oracle needs all the rows from those table. Reading(full) the index will be an unsefull operation, adding unnecesary cost.
UPDATE: A step forward: if you run:
Oracle probably will use the indexes(IX2, IY2), because it does not need to read anything from table, because the values T1.B, T2.B, are in indexes.