Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pU9QD-00061B-H5 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Feb 2023 16:53:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pU9QC-00035q-6R for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Feb 2023 16:53:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pU9QB-00035h-Sw for pgsql-hackers@lists.postgresql.org; Mon, 20 Feb 2023 16:53:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pU9Q9-00053X-Tj for pgsql-hackers@lists.postgresql.org; Mon, 20 Feb 2023 16:53:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 31KGrhaD3587196; Mon, 20 Feb 2023 11:53:43 -0500 From: Tom Lane To: Alexander Lakhin cc: Richard Guo , pgsql-hackers@lists.postgresql.org Subject: Re: Killing off removed rels properly In-reply-to: <3582657.1676910808@sss.pgh.pa.us> References: <229905.1676062220@sss.pgh.pa.us> <1343881.1676313553@sss.pgh.pa.us> <36bee393-b351-16ac-93b2-d46d83637e45@gmail.com> <3582657.1676910808@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 20 Feb 2023 11:33:28 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3587194.1676912023.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 20 Feb 2023 11:53:43 -0500 Message-ID: <3587195.1676912023@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hmm, there's something else going on here. After getting rid of the assertion failure, I see that the plan looks like # explain MERGE INTO tt USING st ON tt.tid =3D st.sid WHEN NOT MATCHED THE= N INSERT = VALUES (st.sid); QUERY PLAN = ------------------------------------------------------------- Merge on tt (cost=3D0.00..35.50 rows=3D0 width=3D0) -> Seq Scan on st (cost=3D0.00..35.50 rows=3D2550 width=3D10) (2 rows) which is fairly nonsensical and doesn't match v15's plan: Merge on tt (cost=3D0.15..544.88 rows=3D0 width=3D0) Merge on ttp tt_1 -> Nested Loop Left Join (cost=3D0.15..544.88 rows=3D32512 width=3D14= ) -> Seq Scan on st (cost=3D0.00..35.50 rows=3D2550 width=3D4) -> Index Scan using ttp_pkey on ttp tt_1 (cost=3D0.15..0.19 row= s=3D1 widt h=3D14) Index Cond: (tid =3D st.sid) It looks like we're somehow triggering the elide-a-left-join code when we shouldn't? That explains why the target table's RelOptInfo has gone missing and broken make_modifytable's expectations. That code is still unnecessarily fragile so I intend to rearrange it, but there's more to do here. regards, tom lane