Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efD9w-0002Ls-Gz for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jan 2018 23:11:48 +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 1efD9v-00081X-U2 for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jan 2018 23:11:47 +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 1efD9v-00081N-OI for pgsql-bugs@lists.postgresql.org; Fri, 26 Jan 2018 23:11:47 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1efD9s-0002RZ-0m for pgsql-bugs@postgresql.org; Fri, 26 Jan 2018 23:11:46 +0000 Received: by mail-wr0-x241.google.com with SMTP id w50so1834486wrc.2 for ; Fri, 26 Jan 2018 15:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=nWEa5b/UQ9o2uP/7Bnjml4bm6JqDAcsvSzAWnY6CLJA=; b=0KtLEWKjtE5+f+0HLJ0PMWxIjaruaVgrn7nVISONkwxWxt15CQC0Ipn4a8WLNGOIUU lrXlULhkhznQYqlvpz1Q5CG97jzPruYBmQKocewNkgadpLzLwonUVHcpUOGfWw7pBQ3G R+8QJYbNSIKXPbHCKjiUahuPV8m9Gki1GQoDXrbdqhwDk0SWRV17GX72T9hc90mFhf1P u95XvbQMxDViqRjqfQ07ss/WRC1htnyVVsIv8jxS9fjLgQMlXZfsZrrFkBftjBKeRB64 dpxQrpsW+u55zgy5V5E9onK2dUM1Yxlo9JrI4xHVydpWO4MGAqp3cbCX35dvP2cj5+4f nkQA== 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-language :content-transfer-encoding; bh=nWEa5b/UQ9o2uP/7Bnjml4bm6JqDAcsvSzAWnY6CLJA=; b=n79yBb65NU7TX4b8sCOdhXcD/YTwIAYXNA1x/eJuHUKkoAq2jf4mjWN67LOQkKWnII B5q/aQZAYcRHOaHeE7D9Zs5M60BoBbnQTigt61BzgH+PQyZx32mPCR6qJpmHI+pBbjN9 69fmHUeEE1oQ3jGiUyDtyrFn92qA3l0zjV9Xf/rEK7I4CS2FEQLCpMJk/Wrsd9+EPJV+ gAb7bHVAfZFPquSjNrpBjRITJlt7JPZ0YVVdH9FpsMUF+kw0NiiTrYJZH63EeQHVLeX9 dU3aOhKdU6T1n0B0Zg1sw//0Gg/Wv8OdiiddsFGwHMtHG2/eXZmvLClVFb1jqCuMchQ4 E8og== X-Gm-Message-State: AKwxytdHUD5CnehnRqCywpcWHk4of3rmUECDW7XKyVObEP6KtDqNiMTK hhoKvZzWDfN2BwDM2dTw+cHZBRWna0CVrgwjOik/R50L2H2Ej47pj0CZm4wqhkUj8dcUYWZCONL R5cWpZO9w3m4iqol2jjJTN0W7Gjq1Fq1EhiNMZQam3DAPcheJ5WHR1DsrLp08fD7poIslcrvPo3 tpENbF6s4= X-Google-Smtp-Source: AH8x225//thstxoZHRBP3rF22B0y6aWt0bB+RSfRpYg51ABgYAcZDw32+WEdLdI4cGuY/kx89ucLQQ== X-Received: by 10.223.134.166 with SMTP id 35mr13404710wrx.10.1517008302526; Fri, 26 Jan 2018 15:11:42 -0800 (PST) Received: from [10.137.2.17] (213.176.broadband18.iol.cz. [109.81.176.213]) by smtp.gmail.com with ESMTPSA id k125sm8999122wmd.48.2018.01.26.15.11.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 15:11:41 -0800 (PST) Subject: Re: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop To: "Todd A. Cook" , pgsql-bugs@postgresql.org References: <20171127185700.1470.20362@wrigleys.postgresql.org> <5d764e7f-269f-7f6d-3885-88295dc9e03d@blackducksoftware.com> From: Tomas Vondra Message-ID: Date: Sat, 27 Jan 2018 00:11:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <5d764e7f-269f-7f6d-3885-88295dc9e03d@blackducksoftware.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/25/2018 11:31 PM, Todd A. Cook wrote: > On 11/27/17 14:17, Tomas Vondra wrote: >> Hi, >> >> On 11/27/2017 07:57 PM, tcook@blackducksoftware.com wrote: >>> The following bug has been logged on the website: >>> >>> Bug reference:      14932 >>> Logged by:          Todd Cook >>> Email address:      tcook@blackducksoftware.com >>> PostgreSQL version: 10.1 >>> Operating system:   CentOS Linux release 7.4.1708 (Core) >>> Description: >>> >>> It hangs on a table with 167834 rows, though it works fine with only >>> 167833 >>> rows.  When it hangs, CTRL-C does not interrupt it, and the backend >>> has to >>> be killed to stop it. >>> >> >> Can you share the query and data, so that we can reproduce the issue? >> >> Based on the stack traces this smells like a bug in the simplehash, >> introduced in PostgreSQL 10. Perhaps somewhere in tuplehash_grow(), >> which gets triggered for 167834 rows (but not for 167833). > > FWIW, changing the guts of hashint8() to > > +       if (val >= INT32_MIN && val <= INT32_MAX) > +               return hash_uint32((uint32) val); > +       else > +               return hash_any((unsigned char *) &val, sizeof(val)); > > allows us to process a full-sized data set of around 900 million rows.  > However, > memory usage seemed to be rather excessive (we can only run 7 of these > jobs in parallel > on a 128GB system before the OOM killer kicked in, rather than the usual > 24); if there's > any interest, I can try to measure exactly how excessive. > I suspect you're right the hash is biased to lohalf bits, as you wrote in the 19/12 message. In fact, I think it's a direct consequence of the requirement that hashint8() needs to produce the same hash for logically equivalent int2 and int4 values. Out of curiosity, could you try replacing the hash_any call in hashint8 with a hash function like murmur3, and see if it improves the behavior? That obviously breaks the hashint8 for cross-type hash joins, but it would be interesting bit of information I think. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services