Can I convert Hashes to BigInt?

i recently saw a post about sql server deprecating older hashing algorithms requiring the newer sha2 versions to be used which would increase the hash. i tried to reply to that but could not for some reason so i’ll just pitch the question here. we currently get around this by converting the value from hashbytes to a bigint. that has the plus of introducing integer based joins versus character based hash joins as well as providing good partition distribution, but we have always wondered if it increases the risk of collisions. we’ve tested this with all the algorithms and have yet to come across a collision…keeping our fingers crossed.. i actually wondered why this was not mentioned in the book as an alternative. is it because it could increase the chance of collisions or some other consideration dan?

One Response to “Can I convert Hashes to BigInt?”

  1. Dan Linstedt 2017/11/14 at 12:36 am #

    No. Most relational databases (except for Java Implementations) make BigInt too small to carry the full hash converted format.
    They will automatically truncate bits, WITHOUT triggering an error. Please NEVER do this – as it will cause far more problems than it is worth dealing with.
    Size is 8 bytes
    Result size of Hash is 16 bytes (DOUBLE!!!)

    You can & should test this result by converting the bigint BACK to a hash, and then comparing the value – as you will find, this will not work.

    Sorry, you are causing serious problems with your hashing by doing this.

Comment on this FAQ