Re: pg17: XX000: no relation entry for relid 0

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: pg17: XX000: no relation entry for relid 0
Date: 2026-04-11 01:31:59
Message-ID: CAHewXNkBL9rh1SqVArtchK3mwq3BXyTk7sArZgQJBnqhQZ=TCw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Richard Guo <guofenglinux(at)gmail(dot)com> 于2026年4月10日周五 22:39写道:
>
> On Fri, Apr 10, 2026 at 9:49 PM Tender Wang <tndrwang(at)gmail(dot)com> wrote:
> > Justin Pryzby <pryzby(at)telsasoft(dot)com> 于2026年4月10日周五 18:54写道:
> > > CREATE VIEW x AS SELECT NULL::int[]
> > > UNION ALL SELECT NULL::int[]
> > > UNION ALL SELECT ARRAY[NULL::bigint];
> > >
> > > SELECT FROM x;
> > > ERROR: XX000: no relation entry for relid 0
>
> Nice catch. It seems that we need at least three branches to
> reproduce this, so that there's a nested UNION ALL whose output type
> doesn't match the parent's expected type. At the outer branch maybe
> we can use NULL::bigint[] instead to be a little simpler.
>
> SELECT NULL::int[] UNION ALL SELECT NULL::int[] UNION ALL SELECT NULL::bigint[];
> ERROR: no relation entry for relid 0

Yes, add it to the test case.

>
> > I didn't think too much at now, a quick fix as below:
> > diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
> > index 4160d2d6e24..ff93fc3ac8a 100644
> > --- a/src/backend/utils/adt/selfuncs.c
> > +++ b/src/backend/utils/adt/selfuncs.c
> > @@ -2265,6 +2265,9 @@ estimate_array_length(PlannerInfo *root, Node *arrayexpr)
> > AttStatsSlot sslot;
> > double nelem = 0;
> >
> > + if (IsA(arrayexpr, Var) && ((Var *) arrayexpr)->varno == 0)
> > + return 10;
> > +
> > examine_variable(root, arrayexpr, 0, &vardata);
> > if (HeapTupleIsValid(vardata.statsTuple))
> > {
> >
> > Any thoughts?
>
> This looks like the right fix to me. We can use some comment here.

comments added.
Please see the attached patch.

--
Thanks,
Tender Wang

Attachment Content-Type Size
0001-Fix-no-relation-entry-for-relid-0-in-nested-UNION-AL.patch application/octet-stream 2.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Haibo Yan 2026-04-11 02:18:07 Re: [PATCH] Fix: Partitioned parent index remains invalid after child indexes are repaired
Previous Message CharSyam 2026-04-11 01:17:07 Re: [PATCH] Use cached hash to skip unnecessary key comparisons in dshash