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 1r5d2L-00EHkj-RD for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Nov 2023 02:32:22 +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 1r5d2K-0044tV-7W for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Nov 2023 02:32:20 +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 1r5d2J-0044tN-Qq for pgsql-bugs@lists.postgresql.org; Wed, 22 Nov 2023 02:32:19 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5d2F-006jrx-Kl for pgsql-bugs@lists.postgresql.org; Wed, 22 Nov 2023 02:32:18 +0000 Received: from [10.10.20.70] (node-68p.pool-101-109.dynamic.totinternet.net [101.109.31.153]) (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 DA95FE20E5F; Wed, 22 Nov 2023 05:32:09 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1700620331; bh=yL1imOe9JkJtSXVE5jhSQmZyuCY/hSZYkeLE1LlCGjg=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=MOLghP/Bt5CVu+i5oRQQ+ctMS1MUVrKRQfBNxcy9SMHU00UXtekktenblW1HBOJ/5 z3vQgNkEeQVSTV2jdSjG9te8lXOP+3svs2DbK5UoE7c3rioe4n2Mt/ry2H+HS27P5k ShS9+T6TvAQfz3jDiPS3LZz1vS/qVASBSF5maObF2aUyvEE7+wqLyTTIcdDX2/LcZI 4WPuavy0vtV3eNNc5VnZbIVzETv7xRLLQ8eNVe0UiepAJYf4EHfgDDd2v/mI4uWAPy nX8jPOlBzX54H+3eL6fs+HwbgkeTU1L0xK6sytaNlZBk1mhhmHFwSmayuay8bu9sZl YR7hbElBSj0GQ== Message-ID: Date: Wed, 22 Nov 2023 09:32:06 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18187: Unexpected error: "variable not found in subplan target lists" triggered by JOIN Content-Language: en-US To: Richard Guo , Alexander Korotkov Cc: zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org, PG Bug reporting form , Tom Lane References: <18187-831da249cbd2ff8e@postgresql.org> <491881ef-f1c7-4a86-b5dd-dcad55a88ab4@postgrespro.ru> 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 20/11/2023 15:49, Richard Guo wrote: > I'm wondering if we can relax this restriction because it seems to me > that a PHV evaluated/needed at or below the self join should not have > problem if we remove the self join. > > > After some more thought, I think PHVs should not impose any constraints > on removing self joins.  If the removed rel is contained in the relids > that a PHV is evaluated/needed at or laterally references, it can just > be replaced with the rel that is kept. > > Attached is a patch to remove such constraints.  Any comments or > feedback are welcome. Carrying out excavations, I found that it was Teodor Sigaev who added this limitation in v.20 of the patch in an earlier stage of the development. I also had analyzed this part of code and came to the conclusion that it doesn't needed. Only a paranoid approach and the absence of an alternative opinion are the reasons why this code is still exists. Your patch is ok. I think the comment, 'PHVs should not impose ...' looks redundant. It may be enough to have it in the commit comment. -- regards, Andrei Lepikhov Postgres Professional