From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Fast, stable, portable hash function producing 4-byte or 8-byte values?
Date: Tue, 10 Dec 2019 18:00:02 -0600
Message-ID: <f930cb2e-a1c1-9a4c-afa1-194a2bb9d0c5@gmail.com> (raw)
In-Reply-To: <CAGHENJ5MnkKeymEVFO6daga6qzTruG91u9yeuwkBuTZ_xRSPRg@mail.gmail.com>
References: <CAGHENJ5MnkKeymEVFO6daga6qzTruG91u9yeuwkBuTZ_xRSPRg@mail.gmail.com>
On 12/10/19 3:11 PM, Erwin Brandstetter wrote:
> I am looking for stable hash functions producing 8-byte or 4-byte hashes
> from long text values in Postgres 10 or later.
>
> There is md5(), the result of which can be cast to uuid. This reliably
> produces practically unique, stable 16-byte values. I have usecases where
> an 8-byte or even 4-byte hash would be good enough to make collisions
> reasonably unlikely. (I can recheck on the full string) - and expression
> indexes substantially smaller. I could truncate md5 and cast back and
> forth, but that seems like a lot of wasted computation. Are there
> suggestions for text hash functions that are
> - fast
> - keep collisions to a minimum
> - stable across major Postgres versions (so expression indexes don't break)
> - croptographic aspect is not needed (acceptable, but no benefit)
What about a CRC32 function? It's fast, and an SSE4 instruction has been in
Intel CPUs for about 10 years.
>
> There is an old post from 2012 by Tom Lane suggesting that hashtext() and
> friends are not for users:
>
> https://www.postgresql.org/message-id/24463.1329854466%40sss.pgh.pa.us
>
> Postgres 11 added hashtextextended() and friends to generate bigint
> hashes. In a more recent post from 3 months ago, Tom suggests to use it in
> user-land - if portability is not needed:
>
> https://www.postgresql.org/message-id/9434.1568839177%40sss.pgh.pa.us
>
> Is pghashlib by Marko Kreen my best option?
>
> https://github.com/markokr/pghashlib
>
> Or the "version-independent hash functions for PostgreSQL" from Peter
> Eisentraut:
>
> https://github.com/petere/pgvihash
>
> Neither received updates for a couple of years. Unmaintained? Or obsolete?
> And neither is available on most hosted services like RDS or Heroku (which
> would be required in come cases).
>
> So what are my best options?
>
> Regards
> Erwin
--
Angular momentum makes the world go 'round.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ronljohnsonjr@gmail.com
Subject: Re: Fast, stable, portable hash function producing 4-byte or 8-byte values?
In-Reply-To: <f930cb2e-a1c1-9a4c-afa1-194a2bb9d0c5@gmail.com>
References: <CAGHENJ5MnkKeymEVFO6daga6qzTruG91u9yeuwkBuTZ_xRSPRg@mail.gmail.com> <f930cb2e-a1c1-9a4c-afa1-194a2bb9d0c5@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox