我应该索引 Oracle 中的主键列吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15703640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Should I index primary key column(s) in Oracle
提问by Mikayil Abdullayev
I've recently stopped to think that Primary Keys are not indexes, they're a combination of Unique and Null constraints. And till now, I've never created index for PK columns. My question is if I should create index for PK columns if this column is going to be used in the WHERE part of many queries.
我最近停止认为主键不是索引,它们是唯一和空约束的组合。直到现在,我从未为 PK 列创建索引。我的问题是,如果该列将用于许多查询的 WHERE 部分,我是否应该为 PK 列创建索引。
回答by David Aldridge
Oracle will create an index for you, or can use an existing one. Whether a unique or non-unique index is used is up to you.
Oracle 将为您创建一个索引,或者可以使用现有的索引。使用唯一索引还是非唯一索引取决于您。
http://docs.oracle.com/cd/B28359_01/server.111/b28310/indexes003.htm#i1006566
http://docs.oracle.com/cd/B28359_01/server.111/b28310/indexes003.htm#i1006566
A primary key itself is not an index, and nor is a unique constraint -- they are both constraints. However an index is used to support them.
主键本身不是索引,也不是唯一约束——它们都是约束。然而,使用索引来支持它们。
A unique index is rather different as it can exist in the absence of a unique or primary key constraint, and neither constraint type require that the index supporting it be unique.
唯一索引相当不同,因为它可以在没有唯一或主键约束的情况下存在,并且两种约束类型都要求支持它的索引是唯一的。