MySQL table with couple of fields:
id–PRIMARY KEYurl–CHAR(255).
url field is also unique and indexed. Currently have couple of hundreds of thousands entries in that table. MySQL gets really slow.
The idea is: if I add hash BIGINT UNIQUE INDEXED field, and create composite index hash/url – will it work faster? Means will MySQL first check my hash/url pair using hash and then url? Will it be faster?
If answer is yes – for what reason this is not transparently implemented for indexed strings in MySQL?
The key lookup on a
BIGINTfield is faster than on aCHARfield (surprisingly, performance gain is more noticeable on a key miss than on a key hit).Note, however, that a
BIGINThash has very high probability of hash collisions, that’s why I’d not recommend to use it in aUNIQUEfieldIf you create a composite key on
(hash, url)and search for thehashonly, it will use therefcondition on thehashpart of the index.