Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ay3xP-0006IF-2G for pgsql-hackers@arkaria.postgresql.org; Wed, 04 May 2016 21:03:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ay3xO-0004yl-GZ for pgsql-hackers@arkaria.postgresql.org; Wed, 04 May 2016 21:03:42 +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 1ay3w3-0003S4-Q3 for pgsql-hackers@postgresql.org; Wed, 04 May 2016 21:02:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ay3w0-0000ew-LF for pgsql-hackers@postgresql.org; Wed, 04 May 2016 21:02:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u44L241S031781; Wed, 4 May 2016 17:02:04 -0400 From: Tom Lane To: Robert Haas cc: David Rowley , Tomas Vondra , Julien Rouhaud , Simon Riggs , Michael Paquier , Stefan Huehner , PostgreSQL mailing lists Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates) In-reply-to: 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> Comments: In-reply-to Robert Haas message dated "Wed, 04 May 2016 16:37:52 -0400" Date: Wed, 04 May 2016 17:02:04 -0400 Message-ID: <31780.1462395724@sss.pgh.pa.us> X-Pg-Spam-Score: -4.0 (----) 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 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. On the whole, that seems like another argument why this needs more time. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers