SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


An Implementation of the FNV1a Hash Algorithm for SQL Server


An Implementation of the FNV1a Hash Algorithm for SQL Server

Author
Message
bret.lowery
bret.lowery
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 190
Comments posted to this topic are about the item An Implementation of the FNV1a Hash Algorithm for SQL Server
martinko_michael
martinko_michael
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 134
I use HASHBYTES('SHA1', ... to detect changes in strings.
Can anyone from Microsoft validate your function? If they can I am hoping to save space since HASHBYTES('SHA1' currently uses varbinary(20).
Nathan Veysey
Nathan Veysey
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 13
Can someone please explain to me an example for using this?
Dave Semmelink
Dave Semmelink
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 25
Why ToLower() ? This makes it unusable for hashing passwords (which are mixed case).
peter-757102
peter-757102
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1739 Visits: 2559
Anyone interested in the strength of a universal hash function should read this:

http://home.comcast.net/~bretm/hash/

FNV does'nt come out that well, but that said, its a very simple algorithmn that can easily be implemented in SQL code if one needs a quick solution.

Also take a look at the other hash related work of Bob Jenkins: http://burtleburtle.net/bob/hash/

And an even faster good hash: http://www.azillionmonkeys.com/qed/hash.html
DEK46656
DEK46656
Right there with Babe
Right there with Babe (770 reputation)Right there with Babe (770 reputation)Right there with Babe (770 reputation)Right there with Babe (770 reputation)Right there with Babe (770 reputation)Right there with Babe (770 reputation)Right there with Babe (770 reputation)Right there with Babe (770 reputation)

Group: General Forum Members
Points: 770 Visits: 581
I use hash functions to generate a synthetic key; some people might call it a surrogate key, but I believe the proper phrase is synthetic. I currently use

keyField = CHECKSUM( HASHBYTES(‘MD5’, @VARCHAR(8000)) )

as a deterministic function that produces a INT key for data warehousing work.

I’m not in the position right now (due to work load) to test this out, but it will go into the investigate list for when my workload is lessened.

Beer's Law: Absolutum obsoletum
"if it works it's out-of-date"
rtaylor72
rtaylor72
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 41
When you say 36 byte GUID, I'm assuming you are talking about a string represented with dashes and without brasses. GUIDs are really 16 bytes, but can be represented as 32 byte strings also. Now if you take that into account, going to a 8 byte bigint (2 ^ 64 = 18,446,744,073,709,551,616 combinations) you are still statistically more likely to have collisions than with GUIDs (2 ^ 128), but for your sample, relatively safe. :-)

Robert



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search