3
votes

I'm trying to hash some values and use the hashed value as an index in my database. Not having collisions is very important, which is why I'm going with md5. Having 128 bits, gives me more than the space I need to not worry about collisions (I know that md5 is not collision safe).

Anyways, how can I store the result of the md5 in a database and so that I can index it and retrieve it quickly? I was thinking of having two Long variables where one would hold the value of the first 64 bits and the other the second 64 bits and use both keys as an index on my database. But I need a fast way for doing this... what would be the fastest way ?

I don't think storing the md5 hashed value as a byte array will help much when I need indexing.

1
Storing it as a string? Varchar?? - Shashank Kadne
Wouldn't a sequence be good enough to generate unique numbers for a primary key ? - Tulains Córdova
Wouldn't indexing as an int be faster than string or varchar? - Roozbeh15
@user1598390, I don't follow what you mean. Could you elaborate please? - Roozbeh15
@Roozbeh15 it seemed to me that the only reason you wanted the md5 for was to use it as a colission free value for a key. But maybe I got it wrong. - Tulains Córdova

1 Answers

3
votes

Just store it as a string (VARCHAR) and let your DB index that. This is the easiest solution, and you'll get the performance boost from the index.