在 oracle 中索引 FK
我有 table1 在 ColA 上有唯一索引的 PK。
我有表2,在ColA和ColB上有唯一索引的PK,
我将FK添加到ColA上的表2回到表1。
我知道我应该在外键列上有索引。 https://forums.oracle.com/forums/thread.jspa?threadID=201154 http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:292016138754 根据上述文章。
我的问题是 table2 的 PK 索引足以满足该要求。索引应该按照 ColA、ColB 的顺序排列,因此应该能够使用它作为 FK 的索引,因为 ColA 排在第一位。正确的?
谢谢。
I have table1 with uniquely indexed PK on ColA.
I have table2 with uniquely indexed PK on ColA and ColB
I add FK to table2 on ColA back to table1.
I know that I should have indexes on foreign key columns.
https://forums.oracle.com/forums/thread.jspa?threadID=201154
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:292016138754
according to the above articles.
My question is the index on the PK for table2 good enough to satisfy that requirement. The index should be in the order of ColA,ColB so it should be able to use that as a index for the FK because the ColA comes first. right?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的你是对的。表 2 中的 ColA 不需要单独的索引。
Yes, you are right. There should be no need for a separate index on ColA in table2.
这是正确的 - Oracle 将能够使用现有索引的前沿(即 ColA),而索引中的任何剩余字段(即 ColB)并不重要(它们会稍微“加宽”索引,但您付出的代价这比您为单独的索引支付的费用要少得多)。
That's correct - Oracle will be able to use the leading edge (i.e. ColA) of the existing index and any remaining fields (i.e. ColB) in the index will not matter much (they will slightly "widen" the index but the price you pay for that is much less than what you would pay for a separate index).