View Full Version : Are UNIQUE KEYs also indexed?
Pykex
05-10-2009, 05:58 AM
I understand that UNIQUE KEY makes it so that you can't have duplicate values, but does it also index the column or do you have to add the index?
Edit: Also, I've always assumed that PRIMARY KEY also indexes its column. Does it really index its column?
Old Pedant
05-10-2009, 08:32 AM
Short answer: Yes.
Unless a UNIQUE KEY was indexed, the only way the DB could toss its cookies when a duplicate was entered would be to do a full scan of the table. No DB would be that poorly designed and live for 3 weeks.
Re primary key: Dunno how MySQL does it, but in many DBs the primary key is truly the fundamental building block of a table. The most efficient of possible indexes. A *lot* of attention is paid to making PK's efficient to use. I'd be really really really surprised if MySQL were any different.
Oh, w.t.h. Let's take a look. Yeah, look here:
http://search.mysql.com/search?q=primary+key+implementation&ie=&lr=lang_en
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.