public inbox for pgsql-bugs@postgresql.org
help / color / mirror / Atom feedFrom: Tender Wang <tndrwang@gmail.com>
To: Alexander Korotkov <aekorotkov@gmail.com>
Cc: Fujii Masao <masao.fujii@gmail.com>
Cc: ammmkilo@163.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables
Date: Tue, 17 Mar 2026 20:59:04 +0800
Message-ID: <CAHewXNmU3E0oXLgvoOtXw7kfTiAZsKu8La_hQ=pyScgxvP45iw@mail.gmail.com> (raw)
In-Reply-To: <CAPpHfdsDQhDqvqi+-UxvyYRP72ASkdWzCn43e2Hj6WsY15opvA@mail.gmail.com>
References: <19435-3cc1a87f291129f1@postgresql.org>
<CAHGQGwEEHFnH8DsZbwxdZeiHozm2LCRTLSgL8Qn=5MoN4450ZA@mail.gmail.com>
<CAPpHfdsDQhDqvqi+-UxvyYRP72ASkdWzCn43e2Hj6WsY15opvA@mail.gmail.com>
Alexander Korotkov <aekorotkov@gmail.com> 于2026年3月17日周二 20:26写道:
>
> 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.
The error was reported in rebuild_joinclause_attr_needed() when
processing Relid = 1(rtindex =1),
When processing its joininfo" ON tom1.col_bool IS NOT NULL",
(gdb) pgprint rinfo->clause
Var [varno=2 varattno=2 vartype=16
varreturningtype=VAR_RETURNING_DEFAULT varnosyn=2 varattnosyn=2]
The varno=2, rtindex=2(tom1) has been removed. In
add_vars_to_attr_needed(), to find the base_rel, but the
root->simple_rel_array[2] is NULL.
So the error is reporting.
It seems the joininfo should be replaced by rtindex = 3, because the
rtindex=2 would be removed.
--
Thanks,
Tender Wang
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tndrwang@gmail.com, aekorotkov@gmail.com, masao.fujii@gmail.com, 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: <CAHewXNmU3E0oXLgvoOtXw7kfTiAZsKu8La_hQ=pyScgxvP45iw@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox