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 1igg2p-0000Fy-Um for pgsql-general@arkaria.postgresql.org; Mon, 16 Dec 2019 02:23:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1igg2o-0006gT-RY for pgsql-general@arkaria.postgresql.org; Mon, 16 Dec 2019 02:23:34 +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 1igg2o-0006gM-Dn for pgsql-general@lists.postgresql.org; Mon, 16 Dec 2019 02:23:34 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1igg2i-00055X-39 for pgsql-general@lists.postgresql.org; Mon, 16 Dec 2019 02:23:33 +0000 Received: by mail-ot1-x336.google.com with SMTP id o9so7081516ote.2 for ; Sun, 15 Dec 2019 18:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=KituA5mqdnSRNV0L21oUqlsvFxWmfevtUTT3f8LVGEY=; b=psuSUE0KUo4MNPd0EadKvSnWw0O+8hNfyEqyqeHkJ2V41wwWBsqq5Kv0bQ6FUVeARM X3RDZX/X21Qh29nl+Bf/TUFzfDGPaKHkh19vM9X2QESjgkQvocI7/ASwj60JIFUyQoFJ su7yPrDNa/bXXvtwhe7R28hdextBJ9s33Nz5HvBS4fmHpGaLBbs8lbHSXxBHBG9+/LgC XvW+eD+qbSifswnENe96HI7g4LpuRK3kH4zUMzFFUmv7AA9WxaMzR7KaNcrByCdvQEcd bdJtAQapeE2ODGAxpyL0SK+GHYbRQDKRaUlIVmvp/Irr8QtwvPTpKvXrWKwBwGWNKMgC Mfng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=KituA5mqdnSRNV0L21oUqlsvFxWmfevtUTT3f8LVGEY=; b=LkFSsZSHBCi8ZlQvBUukB7tk/eJNRzR1oNKKlTE8LbPUk1NJ0xls6QgT5wo6duj4dm liCRCOg6yVqb6msWfKaM4kesc8F0aqDfgyoqkuUc6ZFjpsfc4H+vekighDI5Q0NgTeUY HQ5l5M52I/kZEyMg5H1K7jW+ebw18y3QU17rzuhTFsH4wNF8Wl2dWLZRveRdCpVfCSFU l7GnuKYzum6PwleF6pRgOhilSDoG2d1lE+UWrblSQ0kqKUyipp0x3EWhUoTetbYedKUn PyDmJg0j22ZE+0tE448rWt0kdpsJdrtRfRlYxZ8M3UCHMvUs+jlKZcjErAXx9C1o/DFq iKGw== X-Gm-Message-State: APjAAAWh9CxuFx0kl98l6vRqd0Z5mw+tVqWSd2rt9ZEH15nzQ3jSINwT JkRg9n0/9SRrH19HEVLQ3h24JvZ32rM= X-Google-Smtp-Source: APXvYqxPXvyzn3FwXW/h3MiVAKbpXFucVeLcRUIsqYQoEK/+UvUbO3asHC6cDjv8pENzMIJHzjZTkA== X-Received: by 2002:a05:6830:1ed0:: with SMTP id c16mr28530310otj.21.1576463006990; Sun, 15 Dec 2019 18:23:26 -0800 (PST) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id h24sm6295787otn.29.2019.12.15.18.23.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Dec 2019 18:23:26 -0800 (PST) Subject: Re: Fast, stable, portable hash function producing 4-byte or 8-byte values? To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Sun, 15 Dec 2019 20:23:25 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/15/19 3:59 PM, George Neuner wrote: > On Tue, 10 Dec 2019 18:00:02 -0600, Ron > wrote: > >> 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. > On long text CRC will not be as discriminating as a real cryptohash, When specifying a 4 byte hash, something must be sacrificed... -- Angular momentum makes the world go 'round.