Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ay4LQ-0007Wb-4I for pgsql-hackers@arkaria.postgresql.org; Wed, 04 May 2016 21:28:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ay4LP-00028Q-AE for pgsql-hackers@arkaria.postgresql.org; Wed, 04 May 2016 21:28: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 1ay4K4-0000Yu-N0 for pgsql-hackers@postgresql.org; Wed, 04 May 2016 21:27:08 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ay4K1-0001CN-MK for pgsql-hackers@postgresql.org; Wed, 04 May 2016 21:27:07 +0000 Received: by mail-wm0-x22d.google.com with SMTP id a17so116197584wme.0 for ; Wed, 04 May 2016 14:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=gd/u/fMfBVC55HrC4rTQ2sTt6SI+vG1M9le7CyORdKY=; b=ld0pcLHUtf0dt/ssEaSfVJDr3QE1HdqRp7aAbfzUWKDEPmz222XX/voTyOeIH3jeHD LAtU54RnBB3Txqo7vpNDTJAMerxmKXmc5c4T97GXen21DsVDvIdYVXcpJ5H6imM4+cZm m7yZ5ySP7bXgcw3E4WWHS1XobFYSG/cQZbl/xLN3cEKjnBwZJ7VC5yZVAmB8wdi1njzN LBgwCL8bnlBfFGwZRq8mF6WJLrWgh5X7p79aIv3VMIXhg/lNhFQl561pgxdRuPNrfKpg xsmtu5QpX/aHoEWu+RAYM+ltJ9zc7cT/hgsuuUKzO1FN6BYYZ5rLkpUbUppK+fgStTWV Tn4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=gd/u/fMfBVC55HrC4rTQ2sTt6SI+vG1M9le7CyORdKY=; b=SP1zOEdhQREVBJjDKpLJewGS5HlZMHgs/BPed5S/7v9VkspiQDS0AK1TXrYkaMb0IT fNXQTZQriZQR08g8u6qN1vuT/rLVavzEc2s8R6JCkh/8+sgQSFilgcl7+YydbkkKzsHV 24t8Y8QgUlQaFgZSpdbV0nsmXvEgHoGVax0MSeTMTSaBi7mQjF33bAUOJa2VUVZwZNRE 9LLdSTEYFsLQBaYO9GFPYqm8Y3SXB+U2SkZxYu4xH37HH5ehNsO6I79uGzs8U9BaNKTJ arKcYF5fkZgK9hTpYlEa6F9XHqVeIuzV0TacAKfplGII1HxwVGORk1EemOoNBt+LBy8g 5RJw== X-Gm-Message-State: AOPr4FWBSdcQmiHuYyZL7R8EW1yoadtQ/LOpdmQ5SYkEvIt826LTUHKNzS4mKjZfiB5z/gctroLXl0Md8aGTKDcJUFVp0QX6989hVahKxcRSc0J2LK6s+71B2K70ufVAb7j1C9yq22bN9iTSlEwpSMkW25CYQLX0qElyoOMyxTI4aOz6NrjFQzvu4puixSumKaEbzExumumq X-Received: by 10.28.39.196 with SMTP id n187mr11040446wmn.4.1462397223376; Wed, 04 May 2016 14:27:03 -0700 (PDT) Received: from [10.137.2.17] (ip-89-177-44-58.net.upcbroadband.cz. [89.177.44.58]) by smtp.gmail.com with ESMTPSA id cf6sm6301117wjc.12.2016.05.04.14.27.02 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 04 May 2016 14:27:02 -0700 (PDT) Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates) To: Tom Lane , Robert Haas References: <20160429102531.GA13701@huehner.biz> <572384D7.1020602@dalibo.com> <17639.1461945908@sss.pgh.pa.us> <57238E64.8010702@dalibo.com> <22731.1462037712@sss.pgh.pa.us> <8344835e-18af-9d40-aed7-bd2261be9162@2ndquadrant.com> <16807.1462388069@sss.pgh.pa.us> <31780.1462395724@sss.pgh.pa.us> Cc: David Rowley , Julien Rouhaud , Simon Riggs , Michael Paquier , Stefan Huehner , PostgreSQL mailing lists From: Tomas Vondra Message-ID: <48919afc-1993-8ca8-5b42-3949e9166e92@2ndquadrant.com> Date: Wed, 4 May 2016 23:26:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: <31780.1462395724@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, On 05/04/2016 11:02 PM, Tom Lane wrote: > Robert Haas writes: >> On Wed, May 4, 2016 at 2:54 PM, Tom Lane wrote: >>> My other design-level complaint is that basing this on foreign keys is >>> fundamentally the wrong thing. What actually matters is the unique index >>> underlying the FK; that is, if we have "a.x = b.y" and there's a >>> compatible unique index on b.y, we can conclude that no A row will match >>> more than one B row, whether or not an explicit FK relationship has been >>> declared. So we should drive this off unique indexes instead of FKs, >>> first because we will find more cases, and second because the planner >>> already examines indexes and doesn't need any additional catalog lookups >>> to get the required data. (IOW, the relcache additions that were made in >>> this patch series should go away too.) > >> Without prejudice to anything else in this useful and detailed review, >> I have a question about this. A unique index proves that no A row >> will match more than one B row, and I agree that deriving that from >> unique indexes is sensible. However, ISTM that an FK provides >> additional information: we know that, modulo filter conditions on B, >> every A row will match *exactly* one row B row, which can prevent us >> from *underestimating* the size of the join product. A unique index >> can't do that. > > Very good point, but unless I'm missing something, that is not what the > current patch does. I'm not sure offhand whether that's an important > estimation failure mode currently, or if it is whether it would be > sensible to try to implement that rule entirely separately from the "at > most one" aspect, or if it isn't sensible, whether that's a sufficiently > strong reason to confine the "at most one" logic to working only with FKs > and not with bare unique indexes. FWIW it's a real-world problem with multi-column FKs. As David pointed out upthread, a nice example of this issue is Q9 in the TPC-H bench, where the underestimate leads to HashAggregate and then OOM failure. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers