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 1qwIov-00Axh8-CD for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Oct 2023 09:07:57 +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 1qwIot-00Dx9F-R8 for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Oct 2023 09:07:55 +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 1qwIot-00Dx96-J3 for pgsql-bugs@lists.postgresql.org; Fri, 27 Oct 2023 09:07:55 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qwIoq-002Xx0-9a for pgsql-bugs@lists.postgresql.org; Fri, 27 Oct 2023 09:07:54 +0000 Received: from [10.10.20.35] (node-bpd.pool-113-53.dynamic.totinternet.net [113.53.59.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 4C357E203E9; Fri, 27 Oct 2023 12:07:47 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1698397669; bh=6ooeGmQH9aizRThljdLgvZpJkBMzRdAdSfS65/jZCvk=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=m66nvpcmpwE9SG4XpjFYTFmOGJt64LRu8+CAAVXOI8KaDiO1WktYNCtmP+ZupISKg Cxlpv2V/J2/bklsSNDGN1MSkMSkyKwnjSPAooa3NyC8WKxKKMarOUn8wS2kX3t30bp +P0bpl13cmkdGJN7NbgyocvmfddkXgPcaClcs1yuQIoTAzoYMoESbUKWqzSQ1om/Iq bAlzxUBTC2L1R6RpE5cxZmiXzNKJcXDVpBnd736B/otZhgpyyKVM6t/j9ToygabrGV 1PDGmAqgo4smV8oItPQs9lDZbpu1O6sJPk63G1YTWRN+4e3LzEf5VbXqAzKUDXDo7K r6CNyWVd6knrg== Message-ID: <721542ce-79df-469e-93e9-811fadb5bd0c@postgrespro.ru> Date: Fri, 27 Oct 2023 16:07:44 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18170: Unexpected error: no relation entry for relid 3 To: Alexander Korotkov Cc: Tom Lane , Vik Fearing , 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> <011bcae5-7840-42c7-a50c-b406189e2e78@postgrespro.ru> Content-Language: en-US From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 27/10/2023 15:17, Alexander Korotkov wrote: > On Fri, Oct 27, 2023 at 9:31 AM Andrei Lepikhov > wrote: >> 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. > > Yes, I came to the same conclusion. We process root->parse. But I > didn't get why parent_root->simple_rte_array[]->subquery is not the > same as root->parse. They look the same, but they are distinct > copies. If they were the same pointers, there would be no problem. As I see, the copy of the parse tree is induced by the same feature as usual in the last few months: 2489d76. It introduced remove_nulling_relids, and it altered our parse tree. Right now, I don't have an answer: it should be fixed in SJE, or this is a more general issue just discovered by the SJE. -- regards, Andrei Lepikhov Postgres Professional