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 1ph9CJ-000844-KQ for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Mar 2023 13:17:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ph9CH-00050w-HT for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Mar 2023 13:17:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ph9CH-0004xH-7i for pgsql-hackers@lists.postgresql.org; Tue, 28 Mar 2023 13:17:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ph9CA-0002U1-Vl for pgsql-hackers@lists.postgresql.org; Tue, 28 Mar 2023 13:17:08 +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 32SDH03H3463119; Tue, 28 Mar 2023 09:17:00 -0400 From: Tom Lane To: Alvaro Herrera cc: Pg Hackers Subject: Re: "variable not found in subplan target list" In-reply-to: <3460255.1680008201@sss.pgh.pa.us> References: <20230328112248.6as34mlx5sr4kltg@alvherre.pgsql> <3460255.1680008201@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 28 Mar 2023 08:56:41 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3463117.1680009420.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 28 Mar 2023 09:17:00 -0400 Message-ID: <3463118.1680009420@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > I reduced this down to > MERGE INTO public.target_parted as target_0 > USING public.itest1 as ref_0 > ON target_0.b =3D ref_0.a > WHEN NOT MATCHED > THEN INSERT VALUES (42, 13); > The critical moving part seems to just be that the MERGE target > is a partitioned table ... but surely somebody tested that before? Oh, it's not just any partitioned table: regression=3D# \d+ target_parted Partitioned table "public.target_parted" Column | Type | Collation | Nullable | Default | Storage | Compression= | Stats target | Description = --------+---------+-----------+----------+---------+---------+------------= -+--------------+------------- a | integer | | | | plain | = | | = b | integer | | | | plain | = | | = Partition key: LIST (a) Number of partitions: 0 The planner is reducing the scan of target_parted to a dummy scan, as is reasonable, but it forgets to provide ctid as an output from that scan; then the parent join node is unhappy because it does have a ctid output. So it looks like the problem is some shortcut we take while creating the dummy scan. I suppose that without the planner bug, this'd fail at runtime for lack of a partition to put (42,13) into. Because of that, the case isn't really interesting for production, which may explain the lack of reports. regards, tom lane