Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: ammmkilo(at)163(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Subject: Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables
Date: 2026-03-17 12:14:44
Message-ID: CAHGQGwEEHFnH8DsZbwxdZeiHozm2LCRTLSgL8Qn=5MoN4450ZA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Mar 17, 2026 at 7:34 PM PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 19435
> Logged by: Hang ammmkilo
> Email address: ammmkilo(at)163(dot)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.

Regards,

--
Fujii Masao

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander Korotkov 2026-03-17 12:26:12 Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables
Previous Message surya poondla 2026-03-16 22:09:06 Re: BUG #19382: Server crash at __nss_database_lookup