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 1r7tOy-007K07-JK for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2023 08:25:05 +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 1r7tOx-003Pca-8L for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2023 08:25:03 +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 1r7tOw-003PcS-Rp for pgsql-bugs@lists.postgresql.org; Tue, 28 Nov 2023 08:25:03 +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 1r7tOu-007juP-06 for pgsql-bugs@lists.postgresql.org; Tue, 28 Nov 2023 08:25:01 +0000 Received: from [10.10.20.89] (node-794.pool-101-109.dynamic.totinternet.net [101.109.36.184]) (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 E2C80E20E4A; Tue, 28 Nov 2023 11:24:54 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1701159896; bh=wxbYtKkvqibXNTfOi0XSbgeRlKN1nbcawyUTuAENbLU=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=chY4kNV/JChicCMZacNPmH91yY3OhD+KFoaJhcS77Nm1p+t5RUnR83n3JjXGVvTwA ufLjpVMrX4gvioS3RMKhsozxWN5gd0qSLFxTsXCuywe2fHc5EIIp+rzpNmadeEokfL nj0P/F/97pA01hnAR3sOHcvZcycgr4zsZwsFhSHFvtj2rsa/XuFm9dxPVWc2JZR/Sq Fi6Q+HIo1lg7zvUcxRhSaCdIdM7deio5c71/kXMr+1NVpDZZzPpLwFgcLC7uUehf5s h4/PB6SUEosmkUiXQ1diTWKOPnLZ4k4C+Q86g0ML5dPov/EVDEimZkiN6d32ibsbFj 1HWLiaivC8b7w== Message-ID: <17673e5f-6f68-4be7-a4f9-608f5bb58e9a@postgrespro.ru> Date: Tue, 28 Nov 2023 15:24:51 +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 To: Richard Guo , Tom Lane Cc: Alexander Korotkov , zuming.jiang@inf.ethz.ch, pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <18187-831da249cbd2ff8e@postgresql.org> <491881ef-f1c7-4a86-b5dd-dcad55a88ab4@postgrespro.ru> <3883031.1701106936@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 28/11/2023 15:03, Richard Guo wrote: > On Tue, Nov 28, 2023 at 3:03 PM Richard Guo > wrote: > On Tue, Nov 28, 2023 at 1:42 AM Tom Lane > wrote: > BTW, why is it that it seems to prefer to remove the first of > the two self-joined rels, rather than the second?  That seems > jarringly bizarre. > Hmm, I'm not sure either.  Alexander and Andrei, could you please share > your insights? I was thinking about that choice and, in earlier versions, removed outer relations. I did not find a difference in removing a specific side of the JOIN. Rewriting the patch right before the commit, I found out that remove_useless_joins removed the inner join and chose to do the same, like a convention. > BTW, while reading the codes, I noticed this commit of > remove_self_joins_recurse. > > * ... To avoid complexity, limit the max power of this set by a GUC. > > But where is the GUC?   I guess that it refers to > self_join_search_limit, which has been removed during development. > > So we should revise this commit to at least remove any mention of the > GUC.  Maybe it'd better to add a new commit explaining why we are not > concerned about cases where the number of self joins is too large. Maybe. But actually, we just did some benchmarking to see the influence. Moreover, Alexander's code on preliminary sorting the relations and the fact that inheritance isn't still expanded were reasons we aren't afraid of significant degradation in practical cases. -- regards, Andrei Lepikhov Postgres Professional