Re: Hash function for numeric (WIP) - Mailing list pgsql-patches

From Tom Lane
Subject Re: Hash function for numeric (WIP)
Date
Msg-id 18762.1178501414@sss.pgh.pa.us
Whole thread Raw
In response to Re: Hash function for numeric (WIP)  (Neil Conway <neilc@samurai.com>)
Responses Re: Hash function for numeric (WIP)  (Neil Conway <neilc@samurai.com>)
Re: Hash function for numeric (WIP)  (Neil Conway <neilc@samurai.com>)
List pgsql-patches
Neil Conway <neilc@samurai.com> writes:
> On Thu, 2007-03-05 at 23:57 -0400, Tom Lane wrote:
>> Hm, but apply hash_any() to the remaining digits?  That might work, if
>> you are careful about how you factor the weight into it (or just not try
>> to use the weight in the hash).

> Attached is a patch that implements this idea. Since leading or trailing
> zeroes are far from the common case, I think we should still include the
> weight in the hash when possible: the patch does so when it doesn't find
> a leading zero in the Numeric.

You can do it always if you simply decrement the weight for each leading
zero removed.  (Of course, if you end up with no nonzero digits, you
need to return a fixed hashcode such as 0, regardless of weight.  The
patch as given is wrong since it makes the test for no-digits before
instead of after removing zeroes.)

It'd be a good idea if you repeat the previous number-of-collisions
experiment on this code.

            regards, tom lane

pgsql-patches by date:

Previous
From: Neil Conway
Date:
Subject: Re: Hash function for numeric (WIP)
Next
From: Neil Conway
Date:
Subject: Re: Hash function for numeric (WIP)