Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efDKO-000344-GI for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jan 2018 23:22:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efDKN-00045A-Ta for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jan 2018 23:22:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1efDKN-00044z-NI for pgsql-bugs@lists.postgresql.org; Fri, 26 Jan 2018 23:22:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1efDKL-0002en-1j for pgsql-bugs@postgresql.org; Fri, 26 Jan 2018 23:22:35 +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 w0QNMQKN012512; Fri, 26 Jan 2018 18:22:26 -0500 From: Tom Lane To: Tomas Vondra cc: "Todd A. Cook" , pgsql-bugs@postgresql.org, Andres Freund Subject: Re: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop In-reply-to: References: <20171127185700.1470.20362@wrigleys.postgresql.org> <5d764e7f-269f-7f6d-3885-88295dc9e03d@blackducksoftware.com> Comments: In-reply-to Tomas Vondra message dated "Sat, 27 Jan 2018 00:11:40 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12510.1517008946.1@sss.pgh.pa.us> Date: Fri, 26 Jan 2018 18:22:26 -0500 Message-ID: <12511.1517008946@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tomas Vondra writes: > I suspect you're right the hash is biased to lohalf bits, as you wrote > in the 19/12 message. I don't see any bias in what it's doing, which is basically xoring the two halves and hashing the result. It's possible though that Todd's data set contains values in which corresponding bits of the high and low halves are correlated somehow, in which case the xor would produce a lot of cancellation and a relatively small number of distinct outputs. If we weren't bound by backwards compatibility, we could consider changing to logic more like "if the value is within the int4 range, apply int4hash, otherwise hash all 8 bytes normally". But I don't see how we can change that now that hash indexes are first-class citizens. In any case, we still need a fix for the behavior that the hash table size is blown out by lots of collisions, because that can happen no matter what the hash function is. Andres seems to have dropped the ball on doing something about that. regards, tom lane