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 1qxgwv-002nmf-N8 for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Oct 2023 05:05:58 +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 1qxgwt-000Ukh-Ll for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Oct 2023 05:05:55 +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 1qxgwt-000UkZ-94 for pgsql-bugs@lists.postgresql.org; Tue, 31 Oct 2023 05:05:55 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qxgwq-003w4N-7T for pgsql-bugs@lists.postgresql.org; Tue, 31 Oct 2023 05:05:54 +0000 Received: from [172.20.10.2] (ppp-49-237-201-226.revip6.asianet.co.th [49.237.201.226]) (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 23BB1E20423; Tue, 31 Oct 2023 08:05:45 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1698728751; bh=RzrlZG8/ec0nFy3B/348GjuhVIu7rMOBcWw6HkxeswM=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=KONe6kf0UZjCzL/Yr412/ILX6ZgcJvRCqhmdi2u1RmFM/gFP4nMikF+pKiPAXk1JV i5Rsnte7l+3x5lTOprBN8M93+MGSTJK6ksKT0LBHS2t6xGtIgi7QxRjfCmKXx0Z073 PeNARW0dRnRGpDbK2RMM49W9qgrqaIjquop7G49MrnKbIofyyJgyzdK22slzbjfAJs Q6LvfPO8suVomsBLx1RbaO74pzOOpXY8gwwc4FP7HG0VNOksmZ3D6wwC/hkDENBlGN SXFR920DvKkKW8B3H75oIWzx2xyumZ9AVHcUt1MpGvydV/CKxGmqUtepfBA8JQ5AZT CyJf7CishChDQ== Message-ID: <7332bc61-a9fa-464b-b5a4-4e8e0f764a64@postgrespro.ru> Date: Tue, 31 Oct 2023 12:05:35 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18170: Unexpected error: no relation entry for relid 3 To: Richard Guo Cc: Tom Lane , Alexander Korotkov , 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> <721542ce-79df-469e-93e9-811fadb5bd0c@postgrespro.ru> <2eb87c2e-7e6f-4002-8df3-8fac3aa6a037@postgrespro.ru> <2141583.1698595016@sss.pgh.pa.us> 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 30/10/2023 13:24, Richard Guo wrote: > > On Mon, Oct 30, 2023 at 10:47 AM Andrei Lepikhov > > wrote: > > On 30/10/2023 09:24, Richard Guo wrote: > > I also have some concerns about this patch.  It requires that > > root->parse remains unchanged during the whole subquery_planner() in > > order to work, which is an implicit constraint we did not have > before. > > It is not about unchanged; it is about referencing the same query at > the > parent and child query blocks. Am I missing something? > > > Yeah, that's what I meant.  We need to ensure that root->parse > references the same Query structure during the whole subquery_planner() > for this patch to work, which seems hacky, and error-prone for future > development.  If we really want to do so, at least we need to emphasize > this point in the comment of subquery_planner(). Okay, let's go another way and try to imagine what additional opportunities it will give us in the future? I mean, save unchanged a rte->subquery tree and, simultaneously, have some transformed version in the subroot->parse field. I can imagine kind of a subquery replanning procedure in the case we realized during higher-level query planning that the underlying subquery is not optimal. Such a picture makes sense, and I can agree with your words. From this point of view, all links to the subquery must reference the subroot structures, and the patch you have proposed is the best solution. And the SJE feature works correctly. If we don't imagine the picture I have drawn above, it is reasonable to save memory and not alter the parse tree while removing unneeded joins. I think, in that case, we can use the walker procedure instead of a mutator. -- regards, Andrei Lepikhov Postgres Professional