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 1egLXE-0008Mf-Qz for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jan 2018 02:20:32 +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 1egLXD-0000fT-Um for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jan 2018 02:20:31 +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 1egLU9-00077z-AV for pgsql-bugs@lists.postgresql.org; Tue, 30 Jan 2018 02:17:21 +0000 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1egLU5-00085s-Rw for pgsql-bugs@postgresql.org; Tue, 30 Jan 2018 02:17:19 +0000 Received: by mail-wr0-x22e.google.com with SMTP id i56so9374934wra.7 for ; Mon, 29 Jan 2018 18:17:17 -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=jK51qS6PNL2NI5qMd7GAHyImmVOAPXRBS7O6KXenm6g=; b=NmjmO2KkpAn6VGeUDNr5wtTkIPqsIUuXoxXRMvOlRokSMGCcyupGZT6SUuNFz6qVKI JZF14gZJK6eY+nQPeqrFD4/b+XxBJNgL1hVwjG7WwR7lonO9LRCgIw/FPWPNr/gYKud8 32nVR25SW1A1wdHNqMlP07zW5JxFluISneGiuyz3Fuc7vObqJ7JJe7vJDLwtHr+eWSra rPH1fdyM2sFVAqdTYY3hdBEtQFDUXPd5TldHagz9kyHvzqIi33GOpY4tsRqfoM3hG9OX Cl2lOkk7cgT4jWT1gzrB9tVGTaxN3Yq4WXEJs82xZmC/zbvM/zw3h0sgPT50Jnb//lo1 GPPA== 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=jK51qS6PNL2NI5qMd7GAHyImmVOAPXRBS7O6KXenm6g=; b=K5ZfOkJwujkZjoRYCskC/9MDY2cy5bv01W3+vV2j+mZIBOCdS6o2tU8nU6SaR0NN9J kwMt8hKyY+1K7oPClnRJiIiJiS3NdgLljrdhl3+jTxlejBCWHb1WK6gv1I7bhNb+HYwO H4/QUSA0PQCNXZQtj7e+pacG8vJU/i1Oam1+vTXaI7tJceeSVpmMojETtIbJPGFGNPni 04xw0PWRVZHPEiDOGBCoNkr0F2+yzTzYMHRoNCPBfkZCp0yAGxqgk/8KoYQJvELxnB4c AmoOAZ/lEzOwZMxZyTaa671QhdFb4teAQD+Jagt7HY4kXAePPaIunWFqKNy9hAwhqryv WzLQ== X-Gm-Message-State: AKwxytdgGKY76OZUzcNnW6sFewBk92pAEnwxJGgASahNpKXlXeJkcDWo i85imF5wGAjsCNegr9yHO5TOIZPU/8Kj96xs5bdZGcfTB964FBlLXix470v82t/Z9gJ+1Cqvdsc mBiBliIhsWubfz2GVbkA17A0/ERmY8yDlWSpE/t5+LSvIQWm7ed/yi8iNIhzYzBpIHayoTHg4R1 akfHiK X-Google-Smtp-Source: AH8x225HZRQJbvgqekt3EOPABqy0PO46W4np67Y+s8jGTSMbs5azQ4tUInymf2E04KZkotT5IWEqnw== X-Received: by 10.223.170.11 with SMTP id p11mr20739078wrd.26.1517278635612; Mon, 29 Jan 2018 18:17:15 -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 b11sm13093392wrf.23.2018.01.29.18.17.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jan 2018 18:17:14 -0800 (PST) Subject: Re: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop To: Tom Lane , Andres Freund Cc: "Todd A. Cook" , Thomas Munro , PostgreSQL Bugs References: <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> <20180129010213.rt3nu73ilff756f6@alap3.anarazel.de> <5429.1517250335@sss.pgh.pa.us> <20180129183049.xqoejgs52x37xnyr@alap3.anarazel.de> <6340.1517251510@sss.pgh.pa.us> <7425.1517253086@sss.pgh.pa.us> From: Tomas Vondra Message-ID: Date: Tue, 30 Jan 2018 03:17:12 +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: <7425.1517253086@sss.pgh.pa.us> 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 01/29/2018 08:11 PM, Tom Lane wrote: > One other point here is that it's not really clear to me what a > randomly varying IV is supposed to accomplish. Surely we're not > intending that it prevents somebody from crafting a data set that > causes bad hash performance. If a user with DB access wants to cause > a performance problem, there are and always will be plenty of other > avenues to making that happen. While I'm not sure the random IV is something we want/need, I don't think "There are other ways to harm the database," is a convincing argument. I agree it's fairly easy to set work_mem to an insane value, or craft a query that eats all memory (many sorts using work_mem each, hashagg used for data with many groups, ...). Basically, if you don't know how to crash the database, you're not a senior DBA/engineer. But not all attacks are equal. All those examples I named require direct database connection, ability to construct SQL queries, etc. The case discussed in this thread does not require that - it's enough to control the data input, say by uploading a CSV file with crafted data to some web application (as Greg mentions). Of course, you need to make some assumptions while crafting the data (that it's using Postgres, and that it'll use hash aggregate on the data), but that's about it. > If the idea is that for a data set that otherwise would have bad hash > performance, choosing a different IV would (almost always) fix it, > that sounds good but you're ignoring the inverse case: for a data > set that works fine, there would be some choices of IV that create a > problem where there was none before. I see no reason to think that > the probability of the former kind of situation is higher than the > latter. I don't think this thread is really about randomly generated data sets, but about something that is generated in a way that increases the number of collisions - either intentionally or unintentionally. That's certainly the case of my data set, which was designed to trigger one of the issues in the code. I agree we need to check if the randomization might cause more harm than good by causing random failures. But my feeling is the probability will be very low. > So I'm on board with using the extended hash functions when > available, but I'm not convinced that a varying IV buys us anything > but trouble. I don't have a clear opinion on the random IV yet. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services