Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexander Korotkov <aekorotkov@gmail.com>
Cc: Andrei Lepikhov <lepihov@gmail.com>,
Kirill Reshke <reshkekirill@gmail.com>,
Tender Wang <tndrwang@gmail.com>, Fujii Masao <masao.fujii@gmail.com>,
ammmkilo@163.com, pgsql-bugs@lists.postgresql.org
Date: 2026-03-20T20:26:13Z
Lists: pgsql-bugs
Attachments
- improve-ChangeVarNodesWalkExpression-comments.patch (text/x-diff) patch
I wrote: > 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. After further contemplation I've decided that an Assert would be wrong, because it's not impossible that a callback would want to invoke this on a sub-Query --- for instance, if it wanted to short-circuit ChangeVarNodes's processing of a SubLink node, it would need to do that. The key point is that if we do see a Query node here, we will treat it as a sub-query not a top-level query, which also justifies skipping the work that ChangeVarNodesExtended does on a top-level Query. So we just need a comment explaining that. I'm thinking about the attached. (BTW, by this reasoning the previous implementation of ChangeVarNodesWalkExpression was doubly wrong, since it would have done the wrong thing at a Query node as well as a Var node.) regards, tom lane
Commits
-
Further improve commentary about ChangeVarNodesWalkExpression()
- 6888658516a2 19 (unreleased) landed
- 8c73ab9da9f1 18.4 landed
-
Improve commentary about ChangeVarNodesWalkExpression().
- a0e0b3cc685a 18.4 landed
- 360dd6f7b4c5 19 (unreleased) landed
-
Fix self-join removal to update bare Var references in join clauses
- e8b9d6497469 18.4 landed
- 07b7a964d368 19 (unreleased) landed
-
Implement Self-Join Elimination
- fc069a3a6319 18.0 cited