Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j0qik-0004ZD-C0 for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Feb 2020 17:50:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j0qhj-0005DC-KI for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Feb 2020 17:49:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j0qhj-0005D4-6t for pgsql-bugs@lists.postgresql.org; Sun, 09 Feb 2020 17:49:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j0qhV-00017C-Mc for pgsql-bugs@lists.postgresql.org; Sun, 09 Feb 2020 17:49:09 +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 019HmnM5000468; Sun, 9 Feb 2020 12:48:49 -0500 From: Tom Lane To: Alvaro Herrera cc: Jehan-Guillaume de Rorthais , pgsql-bugs@lists.postgresql.org Subject: Re: Another FK violation when referencing a multi-level partitioned table In-reply-to: <20200207213051.GA32185@alvherre.pgsql> References: <20200207213051.GA32185@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Fri, 07 Feb 2020 18:30:51 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <466.1581270529.1@sss.pgh.pa.us> Date: Sun, 09 Feb 2020 12:48:49 -0500 Message-ID: <467.1581270529@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2020-Feb-06, Jehan-Guillaume de Rorthais wrote: >> Please, find in attachment a proposal patch to fix this FK violation. > You fix looks correct to me, so pushed. I took a minute to apply some > minor corrections to the comments, too. FWIW, I think the test query is too smart for its own good: SELECT fk.fk_a, pk.a FROM fkpart9.fk LEFT JOIN fkpart9.pk ON fk.fk_a = pk.a WHERE fk.fk_a=35; The trouble with this is that the planner would be fully within its rights to conclude that the FK constraint means a pk row must exist for every fk row, and hence strength-reduce the left join to a plain join. That would mask this bug, if it ever reappeared. There's no such optimization today, but people have proposed patches that do that or very similar things, so I have no confidence in the long-term safety of this test case. I'd replace the above SELECT with just SELECT * FROM fkpart9.fk; and maybe also similarly select all of fkpart9.pk, if you wanted to verify that the right thing had happened on that side. regards, tom lane