Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1efxq7-00064c-EW for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Jan 2018 01:02:27 +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 1efxq6-0007bj-0j for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Jan 2018 01:02:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1efxq5-0007bY-5G for pgsql-bugs@lists.postgresql.org; Mon, 29 Jan 2018 01:02:25 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1efxpx-0007tZ-2i for pgsql-bugs@postgresql.org; Mon, 29 Jan 2018 01:02:23 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 572FA20991; Sun, 28 Jan 2018 20:02:15 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Sun, 28 Jan 2018 20:02:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=z1b/1efp6C3BoXSFbtx53nKZjb9z2 f9wxqYPyM1cYYo=; b=gN7PMZcqlqLjrsFliZcVii2pysNe0TvR1aL554rKy2Lut slJdUnOPbM9s35O7jK8komUuBvzZUegzi0ot+h4FzxI8lJRipflrvvEaDw+u10eH cq0mvKZSVSzlOrncZrX1gjjrune8a6vQ2WTnT/W96DkggAu9loonKhy1lbIsAq65 yPJlHS/Wp7BQ64gWznO8lajLoGrW7agS5/yrgL3O+TeaXdR1pHCyax3+ld4DgTpy Fxk6HVdG5VRO5axPO6BWOxUwowMizX6siycEWFFcD857VzdxK3cCLnyTRwcGc6vB qlrCmJCET8jUYciJQTwm5uU30cZjzLP3F9+Kk6LFw== X-ME-Sender: Received: from intern.anarazel.de (unknown [136.24.76.189]) by mail.messagingengine.com (Postfix) with ESMTPA id A16D524608; Sun, 28 Jan 2018 20:02:14 -0500 (EST) Date: Sun, 28 Jan 2018 17:02:13 -0800 From: Andres Freund To: Tom Lane Cc: Tomas Vondra , "Todd A. Cook" , Thomas Munro , PostgreSQL Bugs Subject: Re: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop Message-ID: <20180129010213.rt3nu73ilff756f6@alap3.anarazel.de> References: <9cd29b81-7ba1-91a2-f491-9014f4ac87e6@blackducksoftware.com> <2a76784c-06cb-46ec-35be-9895d144b839@2ndquadrant.com> <219b37b2-d740-d04a-203a-49ae422028f7@blackducksoftware.com> <1773c302-2fb1-749f-8ccc-62b23617c5ac@blackducksoftware.com> <25629.1512580464@sss.pgh.pa.us> <20171206171923.dg7phzfh7nb4lou3@alap3.anarazel.de> <7de4b2d6-b119-7d15-04d8-4c0fcb29cbc3@2ndquadrant.com> <20180126234537.dyu6jwnqz7snpq7n@alap3.anarazel.de> <14184.1517010515@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="erogdy2pp7ibjmmn" Content-Disposition: inline In-Reply-To: <14184.1517010515@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --erogdy2pp7ibjmmn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2018-01-26 18:48:35 -0500, Tom Lane wrote: > Andres Freund writes: > > On 2017-12-10 23:09:42 +0100, Tomas Vondra wrote: > >> FWIW I do agree the data sets shared in this thread are pretty extreme > >> and it doesn't make much sense to slow the regular cases. I'll be > >> perfectly happy if we stop the OOM, making those cases fast is a bonus. > > > Yea, agreed on that. I'm kinda inclined to go for stop-growing in 10, > > and so something better in 11. And then later possibly backpatch if > > we've grown some confidence? > > +1. I'd like to see some response to this included in 10.2, and time > grows short for that. Here are two patches that I think we want for 10.2, and the start of one that I think we want for master. 0002 is needed because otherwise the lack of extra growth leads to noticeably worse performance when filling an underestimated a coordinator hash table from the workers - turns out our hash combine (and most hash combines) let a lot of clustering survive. By adding a final hashing round the bit perturbation is near perfect. The commit messages need to be polished a bit, but other than that I think these are reasonable fixes. Plan to push by Monday evening at the latest. The third patch is a version of the random IV discussed in this thread. I do think we want to add usage of the extended hash functions, as prototyped by Tomas, as that actually helps to fix issues with actual hash conflicts. But we additionally need a fallback path for types without extended hashtables, and the random IV is a good idea nonetheless. There's no ABI difference in my patch, so I think this is actually something we could backpatch. But I don't think it's urgent, so I'm not planning to do that for 10.2. The one thing that could confuse people is that it can lead to output order changes from run to run - I think that's actually good, nobody should rely on hashagg etc output being stable, but it might be a bit much in a stable release? In my tests this solves the worst performance issues in Todd's case, Tomas's, Thomas's and still does ok performancwith with a TPC-H Q18 (which showcases the underestimated worker hashtable into leader hashtable issue). Greetings, Andres Freund --erogdy2pp7ibjmmn Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Prevent-growth-of-simplehash-tables-when-they-re-too.patch"