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 1qwGNq-00AgZe-Mx for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Oct 2023 06:31:51 +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 1qwGNp-00Btb1-7d for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Oct 2023 06:31:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qwGNo-00Btat-RP for pgsql-bugs@lists.postgresql.org; Fri, 27 Oct 2023 06:31:48 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qwGNm-0033QK-1q for pgsql-bugs@lists.postgresql.org; Fri, 27 Oct 2023 06:31:48 +0000 Received: from [172.20.10.2] (ppp-49-237-47-201.revip6.asianet.co.th [49.237.47.201]) (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 1EDA5E203E9; Fri, 27 Oct 2023 09:31:41 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1698388304; bh=w8PirDxVXfrVgGeV+svtP6ikSGJ1urc2udozLtUnXnY=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=hJKCTjEL766OTfNAnamv94+kJ8oC/Au7smCxXYOYBciGF/fFI2eem1+OnTe83jEpM 7LG5z9BYCszGwBdUhYz7+VqyJCDhMhPBgz3MwdmZhKxjtKTZ/St3D3TnZq23ueN/Zt hxvOSCGIYCeJEmNTnpQ3UJpj23wTAcqBmmVUNIYZT2yGQ3yI6E8nIG3a6MJSaBcvWn CV3lDeeYa0DSezF6LsIu0kUZnIeG/NFgfpYdYgxwSEtU+mqjf9Umr2vdtTGBUlywcX stS42tyVALlg0AktWeRNCQbkdUj1eTb8sLopbUwggaJUr/vMIj6Q4uuUdYwlN4abyI klm3181iKNXFQ== Message-ID: <011bcae5-7840-42c7-a50c-b406189e2e78@postgrespro.ru> Date: Fri, 27 Oct 2023 13:31:36 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18170: Unexpected error: no relation entry for relid 3 Content-Language: en-US To: Tom Lane , Vik Fearing Cc: zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org, Alexander Korotkov References: <18170-f1d17bf9a0d58b24@postgresql.org> <4ecab120-6be3-4cf6-a2a0-249c73ae91d4@postgresfriends.org> <1189851.1698340331@sss.pgh.pa.us> From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: <1189851.1698340331@sss.pgh.pa.us> 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 27/10/2023 00:12, Tom Lane wrote: > Vik Fearing writes: >> On 10/26/23 16:01, PG Bug reporting form wrote: >>> My fuzzer finds a bug in Postgres, which triggers an unexpected error. > >> This bisects to d3d55ce571369dad6e1d582f1655e5a3fbd8594a, Remove useless >> self-joins. > > I wonder if that new code thinks it can remove ref_2 from the query, > even though ref_2 is used in the targetlist. I'm not seeing > control reach remove_leftjoinrel_from_query, though. As I see, this join can be removed: in the explain you can see that OUTER JOIN is replaced with the INNER JOIN(ref_2, ref_3) ON a key column. In my opinion, the origin of the problem is that the parent_root contains a link to ref_2 in its simple_rte_array[]->subquery->targetList. I am still looking for a general solution right now, but it doesn't look too complicated at first sight. > Also, while nosing around in this, I tried to pprint(root) at the > point of the error, and got Yeah, it is my blunder. Alexander already fixed that, as I see. The only question is whether it is worth making the UniqueRelInfo structure as a node (for debug purposes - I see only one reason) or we should exclude this field from read/write operations at all. -- regards, Andrei Lepikhov Postgres Professional