Re: does unique index do more than just being a constraint?
Posted by:
Rick James
Date: April 25, 2009 09:11PM
Don't know about the docs, but a UNIQUE index is an index. Querying by the field(s) in the unique index will be (much) faster than if you did not have the UNIQUE index.
There is a slight difference between a UNIQUE index and a non-unique INDEX:
SELECT * FROM tbl WHERE xx = 1234;
needs to do only one probe if xx is known to be UNIQUE. If, instead, xx were a non-unique field, the query would start at the first occurrence of 1234 and scan forward until a different value is encountered.
Having both
UNIQUE(foo)
INDEX(foo)
is inefficient because both indexes have to be updated on INSERT.
In your case, DROP the non-unique INDEX.
All (with a few exceptions) indexes (including UNIQUE and PRIMARY KEY) are implemented as BTrees. This is a very efficient way for locating an individual row, or a "range" or rows with consecutive index values.
(The above comments apply to both MyISAM and InnoDB.)
Subject
Views
Written By
Posted
8325
April 24, 2009 08:29PM
Re: does unique index do more than just being a constraint?
4910
April 25, 2009 09:11PM
Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.