Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables
Alexander Korotkov <aekorotkov@gmail.com>
From: Alexander Korotkov <aekorotkov@gmail.com>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: ammmkilo@163.com, pgsql-bugs@lists.postgresql.org
Date: 2026-03-17T12:26:12Z
Lists: pgsql-bugs
On Tue, Mar 17, 2026 at 2:14 PM Fujii Masao <masao.fujii@gmail.com> wrote: > > On Tue, Mar 17, 2026 at 7:34 PM PG Bug reporting form > <noreply@postgresql.org> wrote: > > > > The following bug has been logged on the website: > > > > Bug reference: 19435 > > Logged by: Hang ammmkilo > > Email address: ammmkilo@163.com > > PostgreSQL version: 18.3 > > Operating system: Ubuntu 22.04 > > Description: > > > > A user encountered an error when attempting to execute a query involving > > multiple RIGHT JOIN operations and a NATURAL JOIN on the same table > > (pg_table_a). The error message returned was: > > [XX000]ERROR: no relation entry for relid 2 > > This error seems to be an internal one and should not be triggered by users. > > It might be a bug. > > ```sql > > DROP TABLE IF EXISTS pg_table_a; > > > > CREATE TABLE pg_table_a ( > > id INTEGER PRIMARY KEY, > > col_bool BOOLEAN > > ); > > > > INSERT INTO pg_table_a (id, col_bool) > > VALUES (5, TRUE); > > > > SELECT 1 AS c1 > > FROM ( > > pg_table_a AS tom0 > > RIGHT JOIN ( > > (pg_table_a AS tom1 NATURAL JOIN pg_table_a AS tom2) > > RIGHT JOIN pg_table_a AS tom3 > > ON tom1.col_bool IS NOT NULL > > ) > > ON tom1.col_bool > > ); > > ``` > > Thanks for the report! > > I was able to reproduce this issue on the master. git bisect that I ran pointed > to commit fc069a3a631 as the likely cause. So I've CC'd its committer, > Alexander, on this thread. Thank you for adding me to the thread. I'm lookin at this. ------ Regards, Alexander Korotkov Supabase
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