Re: Hash function for numeric (WIP)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Hash function for numeric (WIP)
Date: 2007-05-07 01:30:14
Message-ID: 18762.1178501414@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Neil Conway <neilc(at)samurai(dot)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

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Neil Conway 2007-05-07 01:51:59 Re: Hash function for numeric (WIP)
Previous Message Neil Conway 2007-05-07 01:23:05 Re: Hash function for numeric (WIP)