Skip site navigation (1) Skip section navigation (2)

Re: Hash function for numeric (WIP)

From: Neil Conway <neilc(at)samurai(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Hash function for numeric (WIP)
Date: 2007-04-28 22:41:26
Message-ID: 1177800086.6440.174.camel@localhost.localdomain (view raw or flat)
Thread:
Lists: pgsql-patches
On Fri, 2007-04-27 at 04:09 -0400, Tom Lane wrote:
> I feel uncomfortable about this proposal because it will compute
> different hashes for values that differ only in having different
> numbers of trailing zeroes.  Now the numeric.c code is supposed to
> suppress extra trailing zeroes on output, but that's never been a
> correctness property ... are we willing to make it one?

I don't think that is such an onerous requirement: we could easily add
code to enforce this invariant (that might even be worth doing
regardless, to verify that the comments remain consistent with reality).

> There are various related cases involving unstripped leading zeroes.

numeric.h claims that leading zeros will also be stripped -- is that not
correct?

> Another point is that sign = NUMERIC_NAN makes it a NAN regardless
> of any other fields; ignoring the sign does not get the right result
> here.

I believe the patch was actually correct for NUMERIC_NAN (it already
special-cased it).

On Fri, 2007-04-27 at 10:02 -0400, Tom Lane wrote:
> Something else I just remembered is that ndigits = 0 makes it a zero
> regardless of the weight.

Good point, fixed.


> > Perhaps a sufficiently robust way would be to form the hash as the
> > XOR of each supplied digit, circular-shifted by say 3 times the
> > digit's weight.

-Neil



In response to

pgsql-patches by date

Next:From: Neil ConwayDate: 2007-04-28 22:47:10
Subject: Re: Hash function for numeric (WIP)
Previous:From: Neil ConwayDate: 2007-04-27 22:59:10
Subject: Re: CREATE TABLE LIKE INCLUDING INDEXES support

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group