Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r0khH-007cCA-Ul for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Nov 2023 15:42:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r0khF-0054Rb-Kx for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Nov 2023 15:42:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r0khF-0054RT-80 for pgsql-bugs@lists.postgresql.org; Wed, 08 Nov 2023 15:42:25 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r0khB-004aMg-Mx for pgsql-bugs@lists.postgresql.org; Wed, 08 Nov 2023 15:42:23 +0000 Received: from [192.168.1.33] (cm-27-145-170-65.revip12.asianet.co.th [27.145.170.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 05DA5E20F08; Wed, 8 Nov 2023 18:42:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1699458137; bh=t4rtIjRPx63lUOr/NJB5N+6C/pekowudrOD28H5njBI=; h=Message-ID:Date:User-Agent:Subject:To:References:From:In-Reply-To: From; b=x0RHTtOYkMH5PgFkelQUcNNsCQZHHc3WE1HUJHevnq5l1DgDko0fR3qybcx8hvPIb rIRydkOojuEwtTN7OrduuRWCv/zydCWduMyE8WsVVT5uNSRZKq3X1DnrVOixEJyKEM CHcIdLV9fvfUzh/eblnKDPp56A2L8PoGdGO3iieG430kSCrN4h7tVRNQUG+83pDDYF WsXRoGdNmx6KmGJdgDygeXT59SG9w4sSnm2fW45fcp/3Yrg4M52ojxpVt5VZdxKGOt dFgpaEuBmRxJp6Xbw4uEKOrMyXb4f2GqmDyQK3aBBQ/zKXuG548FX3IByoLi09BZ6O f8qnvArHfqa3Q== Message-ID: <491881ef-f1c7-4a86-b5dd-dcad55a88ab4@postgrespro.ru> Date: Wed, 8 Nov 2023 22:42:10 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18187: Unexpected error: "variable not found in subplan target lists" triggered by JOIN To: zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <18187-831da249cbd2ff8e@postgresql.org> Content-Language: en-US From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: <18187-831da249cbd2ff8e@postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/11/2023 00:04, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 18187 > Logged by: Zuming Jiang > Email address: zuming.jiang@inf.ethz.ch > PostgreSQL version: 16.0 > Operating system: Ubuntu 20.04 > Description: > > My fuzzer finds a bug in Postgres 17devel, which triggers an unexpected > error. > > --- Set up database --- > create table t2 (vkey int4, c9 text, primary key(vkey)); > create view t4 as select 1 as c_2, 1 as c_3; > create view t5 as > select > 1 as c_0, > case when '1' ~<=~ ref_0.c9 then 1 else 1 end as c_3 > from > ((t2 as ref_0 > inner join t2 as ref_1 > on (ref_0.vkey = ref_1.vkey)) > right outer join t2 as ref_2 > on (ref_1.vkey = ref_2.vkey )); > ------------------------ > > The fuzzer generates a test case: > > --- Test case --- > select > ref_5.c_3 > from > (((select ref_1.c_3 as c_0 from t4 as ref_1) as subq_0 > right outer join t5 as ref_5 > on (subq_0.c_0 = ref_5.c_0)) > right outer join t4 as ref_6 > on (subq_0.c_0 = ref_6.c_2)); > ------------------------ > > --- Expected behavior --- > The test case should not trigger any error. > > --- Actual behavior --- > The test case trigger an error: > > ERROR: variable not found in subplan target lists > > --- Postgres version --- > Github commit: 3c551ebede46194237f82062b54b92e474b5c743 > Version: PostgreSQL 17devel on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu > 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit > > --- Platform information --- > Platform: Ubuntu 20.04 > Kernel: Linux 5.4.0-147-generic > Great, I would like to have such fuzzer at the stage of development ;) The issue looks like previous one, related to new SJE feature. Reduced case: CREATE TABLE t2 (vkey int4, c9 text, primary key(vkey)); SELECT * FROM ( SELECT CASE WHEN '1' = ref_0.c9 THEN 1 ELSE 1 END AS c_3 FROM t2 as ref_0 JOIN t2 AS ref_1 ON ref_0.vkey = ref_1.vkey RIGHT OUTER JOIN t2 AS ref_2 ON ref_1.vkey = ref_2.vkey) AS t5 RIGHT OUTER JOIN (SELECT 1 AS c_2) AS t4 ON t4.c_2 IS NOT NULL; The key problem lies in the 'CASE' statement. -- regards, Andrei Lepikhov Postgres Professional