Re: More Hashing questions

Lists: pgsql-hackers
From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-hackers(at)postgresql(dot)org
Subject: More Hashing questions
Date: 2004-05-04 22:45:37
Message-ID: 87fzafyfou.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Regarding inter-data-type hash joins, would it make sense to make float
datatypes to hash to the same value as integral data types for integral
values?

Conveniently this would cover the existing special case of -0 and +0 hashing
to the same value. Something like this?

Datum
hashfloat4(PG_FUNCTION_ARGS)
{
float4 key = PG_GETARG_FLOAT4(0);

if (key == (int32)key)
PG_RETURN_UINT32(~(int32)key);

return hash_any((unsigned char *) &key, sizeof(key));
}

Incidentally, why do all the floatfoo functions invert the value? It doesn't
seem like that affects the quality of the hash at all.

--
greg


From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: More Hashing questions
Date: 2004-05-06 14:38:30
Message-ID: 20040506143830.GC41429@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

If you do this I suggest supporting bigint as well.

On Tue, May 04, 2004 at 06:45:37PM -0400, Greg Stark wrote:
>
> Regarding inter-data-type hash joins, would it make sense to make float
> datatypes to hash to the same value as integral data types for integral
> values?
>
> Conveniently this would cover the existing special case of -0 and +0 hashing
> to the same value. Something like this?
>
> Datum
> hashfloat4(PG_FUNCTION_ARGS)
> {
> float4 key = PG_GETARG_FLOAT4(0);
>
> if (key == (int32)key)
> PG_RETURN_UINT32(~(int32)key);
>
> return hash_any((unsigned char *) &key, sizeof(key));
> }
>
>
> Incidentally, why do all the floatfoo functions invert the value? It doesn't
> seem like that affects the quality of the hash at all.
>
>
> --
> greg
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

--
Jim C. Nasby, Database Consultant jim(at)nasby(dot)net
Member: Triangle Fraternity, Sports Car Club of America
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"


From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: More Hashing questions
Date: 2004-05-06 20:33:34
Message-ID: 87k6zpthwh.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


"Jim C. Nasby" <jim(at)nasby(dot)net> writes:

> If you do this I suggest supporting bigint as well.

Well I'm not about to actually do the inter-data-type hash joins. I was just
asking if the hash functions for floats should be adjusted to guarantee this
property. bigints already guarantee it, though I think the hash function can
be improved without breaking it.

> On Tue, May 04, 2004 at 06:45:37PM -0400, Greg Stark wrote:
> >
> > Regarding inter-data-type hash joins, would it make sense to make float
> > datatypes to hash to the same value as integral data types for integral
> > values?

I have a little patch but I have to test it, at least try to compile it,
before I send it anywhere :)

--
greg