Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMgst-0007jS-AW for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Dec 2017 21:05:39 +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 1eMgsr-0003R5-GC for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Dec 2017 21:05:37 +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 1eMgsr-0003Qu-7W for pgsql-bugs@lists.postgresql.org; Wed, 06 Dec 2017 21:05:37 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eMgsj-0008B3-GF for pgsql-bugs@postgresql.org; Wed, 06 Dec 2017 21:05:35 +0000 Received: by mail-wm0-x233.google.com with SMTP id f140so9402576wmd.2 for ; Wed, 06 Dec 2017 13:05:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/KZkazi3p+c+T4Jbr6Pmcfv1FTL7MLm6s0s1yJd/FGk=; b=dnoThhi2IczlD98q4pjeJvYSSTYFDaVFnVghZiKSFb1MW+672W8TGXuKn9ECVqfNgi QcTweAjmvh/y/R7Exgz5bDMrN40q6SWa/k6sxyXxrmurF5n3NvtI5YEUnU5RQQLvLX/v beJpunZwhKWwzLX3aBz8XM0Zs5eZ0GNxtkHTHBVItQQB32kSpK0xkrbay9EOHmXzJTgu whaEgm+YLXVy5IVXmbMGbuXd4xMk0VRWnVDK01SVHPkR9mx+QiQBxs1o+sMd6UjUmziT v6b/fxRDgMU2NRwdAb+JRsU7KmTU3hBHg28C0EB/pW4CcriHcSrhP7dIO6nmaMd0DN7+ V0ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/KZkazi3p+c+T4Jbr6Pmcfv1FTL7MLm6s0s1yJd/FGk=; b=Wnveu/j0oHbFchVqB8oO+B41+pgyMjx+gLgMvEkQ4CUa1VV2ScICsY+TOUcPe99Nc/ jlQVLohGMuOLkwjgbz1r0BMb0xuZOlUwXmR9FEFvrRiF3zbgnlNt5nATcW1fRtFBwbn0 501E2G5MNw/4DZaa1au/qIhbIxvq87RCQlhU6oxY0UiKHxofT6g6Ks0FBFkcbP3MQI+v Flc4BFbHO6Q6BN5VRV6BtkelDmyzW4UfjOFDEHGHvVbTJ+Dq00zxnu4RsFWd2PNOFItH 3gCr3jKHfuLTfBE9GDAtApmcSrVQu+SAVadf3g/GhDOyq27QJRf31w23HITXy5Uub05G +o9Q== X-Gm-Message-State: AJaThX6fudqmaCdkIPVXJzZcyVofdIwplj7GLsRzdD+ydnordwlNV+ma Fpp7cjm3ISGDb/6W6LdUKVAfSab47bLrpSFbrETb/45KNUXcbM0qk09mG7Vx5E9YEPD1pctmWha AgDXX4UZUzBmRa7xeMy0tcpDz0BbUDZ9qQA/7tu/SWwO5iNPj3OygT6pTIdQJXwvnNnH6qehurt CZuryX X-Google-Smtp-Source: AGs4zMbXmAa2aISoPLuDDWftx57KSweQ4s2sGQ/7IxFliMEPR6t7u1gw0DW59cHif6fsLWExTYEvbA== X-Received: by 10.28.9.146 with SMTP id 140mr15863666wmj.117.1512594326368; Wed, 06 Dec 2017 13:05:26 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id q2sm3930822wma.19.2017.12.06.13.05.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Dec 2017 13:05:25 -0800 (PST) Subject: Re: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop To: Andres Freund Cc: "Todd A. Cook" , Tom Lane , Thomas Munro , PostgreSQL Bugs References: <20171127221041.mezzysc4zcfsqkyc@alap3.anarazel.de> <17357.1511841783@sss.pgh.pa.us> <9cd29b81-7ba1-91a2-f491-9014f4ac87e6@blackducksoftware.com> <2a76784c-06cb-46ec-35be-9895d144b839@2ndquadrant.com> <263b03b1-3e1c-49ca-165a-8ac6751419c4@2ndquadrant.com> <20171206193545.3imvbfwjgrmuho3s@alap3.anarazel.de> <790BC80E-D8E5-499B-A1E3-8EE0752B53ED@anarazel.de> <06523583-b9c5-1424-ef0a-1fc8063e9ed7@2ndquadrant.com> <20171206204616.wcect35fuj5gjde2@alap3.anarazel.de> From: Tomas Vondra Message-ID: <67e5af9b-f509-7b9e-f7a1-e01112f6c18d@2ndquadrant.com> Date: Wed, 6 Dec 2017 22:05:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171206204616.wcect35fuj5gjde2@alap3.anarazel.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/06/2017 09:46 PM, Andres Freund wrote: > On 2017-12-06 21:38:42 +0100, Tomas Vondra wrote: >> It's one thing when the hash table takes longer to lookup something or > > longer aka "forever". > Not necessarily. The datasets I shared are somewhat extreme in the sense that there are many contiguous sequences of hash values, but it only takes one such sequence with at least SH_GROW_MAX_MOVE values to trigger the issue. So the hash table may still be perfectly fine for most keys, and only slightly slower for the keys in the sequence. > >> when it consumes a bit more memory. Say, ~2x more than needed, give or >> take. I'm perfectly fine with that, particularly when it's a worst-case >> evil data set like this one. > > I think the way to prevent that kind of attack is to add randomization. > By randomization you mean universal hashing [1], or something else? [1] https://en.wikipedia.org/wiki/Universal_hashing In any case, randomization should make it much harder (or pretty much impossible) to construct datasets that are guaranteed to cause failures of this kind. No problem with that (although if someone hits the issue, it will be more difficult to reproduce). It would still be possible to hit it by chance, but that should be very unlikely (OTOH the current code assumes the same thing about collisions and sequences, and here we are.) > >> FWIW I've constructed the data sets for two reasons - to convince myself >> that my understanding of the simplehash code is correct, and to provide >> a data set triggering the other growth condition in simplehash code. My >> understanding is that if we stop growing the table after the load factor >> drops below some threshold (as TL proposed earlier in this thread), it >> should address both of these cases. > > Yea, I'm not adverse to adding a few stopgaps that break in a less > annoying manner. WAll I'm saying is that I don't think we need to be > super concerned about this specific way of breaking things. > OK, understood. cheers -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services