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 1qyNAY-007wZu-Qw for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Nov 2023 02:10: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 1qyNAX-00AMff-EF for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Nov 2023 02:10: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 1qyNAX-00AMfW-1R for pgsql-bugs@lists.postgresql.org; Thu, 02 Nov 2023 02:10:49 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qyNAU-004Fkm-NJ for pgsql-bugs@lists.postgresql.org; Thu, 02 Nov 2023 02:10:48 +0000 Received: from [192.168.1.33] (cm-171-100-250-93.revip10.asianet.co.th [171.100.250.93]) (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 1DF9DE20E9E; Thu, 2 Nov 2023 05:10:42 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1698891045; bh=z9Jfwy3b/voV6wIlV5040sgYSXKmeKtxp0S7v41zBRw=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=BHXLEdToxOHroNzbqz4aiSzsT3CEWONsszI7QQVEWbLAQwkjxmQaTCJyZYqggpxgw V/A5D/TbYfwjA8HzlzMtQ31xw8JPq+hbG0TTWL2nNWaERdGJKm8dnA4HzddEJDc0xU e2+ABcImgO6B3ks5B4g2ldNcNyk7rvilJSXBKjyJ8qfXZKscdWxv0TbBgTyPiu1pnd Sbgvpson5/cqKyU6EH12M66Pbza5nK3+qMRfn2fRtUoE8GbDON2zwHkf33pyBa2K1b R7pTbEmL7RbOAoDLxgwlyioUbGzPBH0bLw3o4ZyXCtxckxxUzut4xn1zbyg4JjUYn3 ERQPrcCV8/81w== Message-ID: Date: Thu, 2 Nov 2023 09:10:40 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18170: Unexpected error: no relation entry for relid 3 To: Alexander Korotkov , Tom Lane Cc: Richard Guo , 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> <1551957.1698417686@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 2/11/2023 05:29, Alexander Korotkov wrote: > On Wed, Nov 1, 2023 at 12:29 PM Alexander Korotkov wrote: >> On Sat, Oct 28, 2023 at 12:12 AM Alexander Korotkov >> wrote: >>> >>> On Fri, Oct 27, 2023 at 5:41 PM Tom Lane wrote: >>>> Richard Guo writes: >>>>> Alternatively, can we look at subroot->parse->targetList instead of >>>>> subquery->targetList where we call estimate_num_groups on the output of >>>>> the subquery? >>>> >>>> Please read the comment just above that. >>> >>> Thank you, Tom, This is clear. >> >> >> Hmm... I just found that I wasn't attentive enough. The proposed >> change is to use subroot->parse->targetList, not >> subroot->processed_tlist. I don't know what could be the problem >> here. > > My proposal is to use the attached patch as a hotfix for the bug considered. Looks good, no objections. > > And for future I propose to consider two questions (each should > probably go to its own thread): > 1) Getting rid of having two distinct copies of parse tree (have one > copy instead). +1. It can be done somewhere near the beta release. Or, in the next release, with the sake of finding other issues (like fixing with the patch proposed), if they have a place in the planner's code. > 2) Introduce relation aliases to simplify self-join removal. In my opinion, it should be another type of RelOptInfo, not a simple reference to the entry that has been kept. And we need to invent a kind of relid translation procedure. Would it be worth it? I'm not sure, but it can make implementation of optimizations of that type simpler. -- regards, Andrei Lepikhov Postgres Professional