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 1utjIO-00DN9k-R3 for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Sep 2025 08:56:49 +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 1utjIN-008KTd-MS for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Sep 2025 08:56:48 +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 1utjIN-008KS9-Dv for pgsql-bugs@lists.postgresql.org; Wed, 03 Sep 2025 08:56:47 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1utjIL-000Ioc-3A for pgsql-bugs@lists.postgresql.org; Wed, 03 Sep 2025 08:56:46 +0000 Received: from [192.168.15.143] (unknown [80.251.191.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id D12D2608AB; Wed, 3 Sep 2025 11:56:42 +0300 (MSK) Message-ID: Date: Wed, 3 Sep 2025 10:56:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19037: Planner fails on estimating array length with "no relation entry" error To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org, Richard Guo , exclusion@gmail.com References: <19037-3d1c7bb553c7ce84@postgresql.org> <50858.1756590676@sss.pgh.pa.us> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: <50858.1756590676@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/09/03 06:58:00 #27741180 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 30/8/2025 23:51, Tom Lane wrote: > PG Bug reporting form writes: >> The following script: > In some sense the "right" fix would be to do SubPlan generation > later, when we have statistics available for the Vars of the > parent query. But that seems like a rather large task, and > we'd surely not wish to back-patch the results. I'd vote to go this direction in the next version. Implementing memoisation of subplans to reduce the number of subplan evaluations, I encountered the same problem: the number of groups in the parameter set can't be estimated during subplan planning. I resolved this issue by employing upper_paths_hook to decide the addition of Memoise nodes into subplans at the end of upper query planning. But it is not an in-core solution and has a flaw with multi-level references. So, it would be better to prepare as much PlannerInfo's info, as possible (base rels, maybe query tree?) before filling RelOptInfos with potential paths. -- regards, Andrei Lepikhov