tags:

views:

23

answers:

1

If I have a column short_title in MySQL table and it is defined as UNIQUE, do I also have to add FULLTEXT for it to be searchable really fast? Or does UNIQUE already guarantee it will be searchable quickly (without full table scan)?

Thanks, Boda Cydo

+1  A: 

UNIQUE will locate the verbatim short_title using the underlying index.

If you need a word match (as opposed to verbatim match), use FULLTEXT index.

Also note that by default the B-Tree indexes in MyISAM against the VARCHAR columns are subject to key compression. This can slow down the searches for the titles closer to the end of the alphabet:

Finally, the VARCHAR keys tend to be large in size.

For the fastest verbatim searches, you should store a MD5 hash of the title in a BINARY(16) column, create a UNIQUE index over it (disabling the key compression) and search for the hash.

Quassnoi
I see. Thanks for the answer. But does it mean then that I have to have both UNIQUE and FULLTEXT indexes on short_title column for it to be UNIQUE and quickly searchable at the same time?
bodacydo
I got it. I am doing verbatim match (I think I understand it right - it's matching the whole column), so I need only UNIQUE index. :)
bodacydo