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 1qwh3z-00Dkjo-B8 for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2023 11:01:07 +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 1qwh3x-004A6M-Uk for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Oct 2023 11:01:05 +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 1qwh3x-004A6E-II for pgsql-bugs@lists.postgresql.org; Sat, 28 Oct 2023 11:01:05 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qwh3u-003Lx2-J4 for pgsql-bugs@lists.postgresql.org; Sat, 28 Oct 2023 11:01:04 +0000 Received: from [10.2.1.97] (unknown [49.228.251.218]) (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 8E8E6E203E9; Sat, 28 Oct 2023 14:00:59 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1698490861; bh=u/CDoMk4BFuVCydfj0rbE58AKmenUUMVTqethbV6krI=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=ud7FGkCevClEl6gtLMYsSAZb58H8jvRQlfX9gkOSXfdtVAAQqMo1rcrFlnba4kenb 877fv6x58TDyrspAWkaugsN3dEEf96lwkL5IOS1rik5doLfh4Eppjg2Egklkm1RH8X tAbD7iqIE197AaMrG2VtH6ufJQgj0uv2vLnDixkByz+s2u4HQ9s7zc9ZP9gF4hDW4h l9VvovoEyG/s9cm2t0lJ9DTuoJMQeZXba+FSmT2jGy/44UfpTPuCr7zmiq9OHnVlYd q2KiPD1uPTPQ5Ox4E0Sd1UDFG5Nbof+XswDuH1oZgCqSAjs/0QxsGhU1+Uf8Kq7wP3 ziG1q4L7+gt1Q== Message-ID: Date: Sat, 28 Oct 2023 18:00:55 +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: Alexander Korotkov Cc: Richard Guo , 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> <721542ce-79df-469e-93e9-811fadb5bd0c@postgrespro.ru> <2eb87c2e-7e6f-4002-8df3-8fac3aa6a037@postgrespro.ru> From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: 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 28/10/2023 17:10, Alexander Korotkov wrote: >> >> It is a solution. But does it mask the real problem? In my mind, we copy >> node trees to use somewhere else or probe a conjecture. Here, we have >> two different representations of the same subquery. Keeping aside the >> memory consumption issue, is it correct? >> Make sense to apply both options: switch the groups estimation to >> subroot targetList and keep one version of a subquery. >> In attachment - second (combined) version of the change. Here I added >> assertions to check identity of root->parse and incoming query tree. > > Andrei, did you read the comment just before the groups estimation as > pointed by Tom [1]? Yes, and I am a bit confused. We use here subroot->parse->targetList. The processed_tlist, where we can find the "Varno 0" value, is based on it, but it is different. As I see, forming processed_tlist, we make a new node and don't change the original targetList. Am I wrong? > * XXX you don't really want to know about this: we do the estimation > * using the subquery's original targetlist expressions, not the > * subroot->processed_tlist which might seem more appropriate. The > * reason is that if the subquery is itself a setop, it may return a > * processed_tlist containing "varno 0" Vars generated by > * generate_append_tlist, and those would confuse estimate_num_groups > * mightily. We ought to get rid of the "varno 0" hack, but that > * requires a redesign of the parsetree representation of setops, so > * that there can be an RTE corresponding to each setop's output. > > As I understand, it requires much more work to correctly switch the > groups estimation to subroot targetList. "Varno 0" is quite an irritating problem, which has beaten me a lot before, during the development of the GROUP-BY optimization feature and not only. I'd be glad to redesign this part of the planner. But I didn't find an easy way to implement that yet. -- regards, Andrei Lepikhov Postgres Professional