unique index vs non-unique index

简介:
Question:   What is between between "unique index vs non-unique index". Which one is faster. The customer using non-unique and sql is getting delay If we change tp non-unique. Is it work ?   Answer:   Indexes can be unique or non-unique. Unique indexes guarantee that no two rows of a table have duplicate values in the key column (or columns). Non-unique indexes do not impose this restriction on the column values.   Oracle recommends that unique indexes be created explicitly, using CREATE UNIQUE INDEX. Creating unique indexes through a primary key or unique constraint is not guaranteed to create a new index, and the index they create is not guaranteed to be a unique index.   It is just that in a unique index, the rowid is not considered "part of the key" and in a non-unique index "the rowid is considered part of the key".   From Performance point of view:   The optimizer can look at an index that is unique and check, if you use "where x =:x and y = :y and ...." I'm going to get ONE row back, I can cost that much better"   If the index is non-unique, the optimizer will perform , index range scan, he is going to get 0..N rows back" and it'll cost it differently.   So, a unique index will affect the generated plan -- it is more information for the optimizer to grab onto.   If the data must be UNIQUE, you should use a UNIQUE constraint - not an index. We will take care of the index for you. If the constraint is not deferrable, we'll create a unique index for you. If the constraint is deferrable -- we'll use a non-unique index.   Non-Unique indexes have various “overheads” when compared to Unique Indexes   Will examine two key differences today:
  • Extra byte required per index row entry
  • Index requires additional consistent reads and latch gets

Reading a Non-Unique Index is more expensive in terms of consistent reads and latches.



本文转自maclean_007 51CTO博客,原文链接:http://blog.51cto.com/maclean/1276781

相关文章
|
7月前
你真的会z-index吗
你真的会z-index吗
|
SQL 索引
ORA-01502: index ‘index_name' or partition of such index is in unusable state
错误现象:   今天发布脚本时,一个表插入数据时报如下错误   ORA-01502: index ‘index_name' or partition of such index is in unusable state   ORA-06512: at line 168 错误原因:   这个错误一般是因为索引状态为UNUSABLE引起的。
909 0
|
Web App开发 JavaScript
深入理解z-index
要解决的问题 在页面编写的过程中,经常需要处理元素的重叠。重叠的顺序不当则容易造成元素被错误地遮盖等现象。一般地,有很多人认为只需要指定元素的z-index即可调整重叠的顺序,但是实际上并不是这样的。
1516 0
|
SQL 索引
317TABLE ACCESS BY INDEX ROWID BATCHED2
[20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED2.txt --//简单探究12c TABLE ACCESS BY INDEX ROWID BATCHED特性.
1299 0
|
SQL Oracle 关系型数据库
0317TABLE ACCESS BY INDEX ROWID BATCHED
[20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED.txt --//简单探究12c TABLE ACCESS BY INDEX ROWID BATCHED特性.
1455 0
|
缓存 Oracle 关系型数据库
317TABLE ACCESS BY INDEX ROWID BATCHED3
[20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED3.txt --//简单探究12c TABLE ACCESS BY INDEX ROWID BATCHED特性.
1050 0
1041 Be Unique (20)
#include #include #include #include #include using namespace std; int main() { int n; cin >> n; ...
744 0
|
测试技术 索引 关系型数据库
[20171211]UNIQUE LOCAL(Partitioned)Index
[20171211]UNIQUE LOCAL (Partitioned) Index.txt --//如何在分区表中建立local unique index呢?自己对分区表这部分内容了解很少,参考链接: --//https://hemantoracledba.
1119 0
|
Web App开发 前端开发