unique index vs non-unique index
2009-06-30 00:07
267 查看
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.本文出自 “Ask Maclean Liu Oracle” 博客,请务必保留此出处http://maclean.blog.51cto.com/2923249/1276781
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.本文出自 “Ask Maclean Liu Oracle” 博客,请务必保留此出处http://maclean.blog.51cto.com/2923249/1276781
相关文章推荐
- unique index vs non-unique index
- [原]unique index和non unique index的区别
- NONCLUSTERED INDEX VS CLUSTERED INDEX
- gap锁 对于unique index 和Ununique index
- gap锁 对于unique index 和Ununique index
- gap锁 对于unique index 和Ununique index
- index unique scan vs index full scan
- ValueError: cannot reindex a non-unique index with a method or limit
- SQL key vs index
- java direct buffer VS non-direct buffer
- 工作总结 1 sql写法 insert into select from 2 vs中 obj文件和bin文件 3 npoi 模板copy CopySheet 最好先全部Copy完后 再根据生成sheet写数据 4 sheet.CopyRow(rowsindex, rowsindex + x); 5 npoi 复制模板如果出现单元格显示问题
- com.android.dex.DexIndexOverflowException: Cannot merge new index 66078 into a non-jumbo instruction
- Oracle 唯一 约束(unique constraint) 与 索引(index) 关系说明
- INDEX FULL SCAN vs INDEX FAST FULL SCAN
- org.hibernate.NonUniqueObjectException 问题
- ORA-02429: cannot drop index used for enforcement of unique/primary key
- org.hibernate.NonUniqueObjectException
- MySQL hash index VS Btree index
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was ...
- ios - firstObject vs objectAtIndex:0