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.
    Bigint: https://docs.microsoft.com/en-us/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql
    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.

Leave a Reply

*