Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9xUR-0002wV-Vm for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 16:35:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b9xUR-0001m4-IY for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 16:34:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b9xUQ-0001lL-G1 for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 16:34:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b9xUH-0005V5-3S for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 16:34:57 +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 u56GYgD1024069; Mon, 6 Jun 2016 12:34:42 -0400 From: Tom Lane To: Tomas Vondra cc: Robert Haas , Noah Misch , Simon Riggs , David Rowley , Julien Rouhaud , 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: <23385.1465229755@sss.pgh.pa.us> References: <57238E64.8010702@dalibo.com> <22731.1462037712@sss.pgh.pa.us> <8344835e-18af-9d40-aed7-bd2261be9162@2ndquadrant.com> <16807.1462388069@sss.pgh.pa.us> <20160529053601.GE496776@tornado.leadboat.com> <20160602012954.GA619629@tornado.leadboat.com> <28109.1465064127@sss.pgh.pa.us> <039fca3d-890a-d09a-e0df-e045187eb69e@2ndquadrant.com> <23385.1465229755@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 06 Jun 2016 12:15:55 -0400" Date: Mon, 06 Jun 2016 12:34:42 -0400 Message-ID: <24068.1465230882@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) 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 ... BTW, another thought occurred to me yesterday: it seems like the existing code hasn't thought through its behavior for multiple foreign keys very carefully. That is, suppose we have both "A.J references B.K" and "A.X references B.Y", as separate FKs not a single multicolumn FK. The current code goes to some lengths to decide that one of these is better than the other and then ignore the other. Why? Seems to me that in such a case you want to behave more nearly as you would for a multicolumn FK, that is discard all the join quals matched to either FK in favor of a single selectivity estimate based on the number of rows in the referenced table. Discarding only the A.J = B.K clause and then multiplying by the independent selectivity of A.X = B.Y is surely just as wrong as what we've historically done for multicolumn FKs. (Correcting for nulls would take a bit of thought, but I wouldn't be surprised if it ends up being the same as for the multicolumn-FK case, at least to within the precision we can hope to get with the available stats for nulls.) 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