Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAgjr-00011G-0c for pgsql-performance@arkaria.postgresql.org; Wed, 18 Sep 2019 20:39:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iAgjo-0003vh-V0 for pgsql-performance@arkaria.postgresql.org; Wed, 18 Sep 2019 20:39:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iAgjo-0003vM-Im for pgsql-performance@lists.postgresql.org; Wed, 18 Sep 2019 20:39:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iAgjk-0005p7-F0 for pgsql-performance@postgresql.org; Wed, 18 Sep 2019 20:39:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8IKdb02009435; Wed, 18 Sep 2019 16:39:37 -0400 From: Tom Lane To: Stephen Conley cc: pgsql-performance@postgresql.org Subject: Re: Question regarding fast-hashing in PGSQL In-reply-to: References: Comments: In-reply-to Stephen Conley message dated "Wed, 18 Sep 2019 12:41:28 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9433.1568839177.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 18 Sep 2019 16:39:37 -0400 Message-ID: <9434.1568839177@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Stephen Conley writes: > My idea was to hash the string to a bigint, because the likelihood of al= l 3 > columns colliding is almost 0, and if a duplicate does crop up, it isn't > the end of the world. > However, Postgresql doesn't seem to have any 'native' hashing calls that > result in a bigint. regression=3D# \df hashtext* List of functions Schema | Name | Result data type | Argument data types | = Type = ------------+------------------+------------------+---------------------+-= ----- pg_catalog | hashtext | integer | text | = func pg_catalog | hashtextextended | bigint | text, bigint | = func (2 rows) The "extended" hash API has only been there since v11, so you couldn't rely on it if you need portability to old servers. But otherwise it seems to respond precisely to your question. If you do need portability ... does the text string's part of the hash *really* have to be 64 bits wide? Why not just concatenate it with a 32-bit hash of the other fields? regards, tom lane