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.96) (envelope-from ) id 1w3aro-001NJd-1E for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Mar 2026 14:30:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w3arm-006e8S-2f for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Mar 2026 14:30:23 +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.96) (envelope-from ) id 1w3arm-006e8K-1u for pgsql-bugs@lists.postgresql.org; Fri, 20 Mar 2026 14:30:23 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w3arl-00000000BEk-0uEZ for pgsql-bugs@lists.postgresql.org; Fri, 20 Mar 2026 14:30:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 62KEU6ow1607554; Fri, 20 Mar 2026 10:30:06 -0400 From: Tom Lane To: Alexander Korotkov cc: Andrei Lepikhov , Kirill Reshke , Tender Wang , Fujii Masao , ammmkilo@163.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables In-reply-to: References: <19435-3cc1a87f291129f1@postgresql.org> <5a039d60-d! 13b-4cf0-a807-9c7269f06831@gmail.com> Comments: In-reply-to Alexander Korotkov message dated "Fri, 20 Mar 2026 16:02:10 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1607552.1774017006.1@sss.pgh.pa.us> Date: Fri, 20 Mar 2026 10:30:06 -0400 Message-ID: <1607553.1774017006@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander Korotkov writes: > OK. I've pushed this. I don't love this patch. It fixes the functional problem, but it does nothing to fix the underlying cause of that problem, namely the abysmal under-documentation of the ChangeVarNodesXXX functions. There are very specific assumptions about whether the recursion is starting at a Query or not, and the code will do the wrong thing if invoked at the wrong node level. In particular, imagine that ChangeVarNodes_walker is invoked directly on a Query node, something that ChangeVarNodesExtended is careful not to do. It will increment sublevels_up immediately and thus process the contents of the Query with sublevels_up==1, meaning it will not recognize local Vars as needing adjustment. At the very least we need to add comments, but I wonder if we don't actually need an Assert that ChangeVarNodesWalkExpression is not invoked directly on a Query. It would have done the right thing before this patch, but now it won't. That's an okay tradeoff for fixing the bare-Var case, but not documenting what you did is not okay. regards, tom lane