Re: pg17: XX000: no relation entry for relid 0 - Mailing list pgsql-hackers

From Richard Guo
Subject Re: pg17: XX000: no relation entry for relid 0
Date
Msg-id CAMbWs49Wi81GGO_drC4PJgQUehz4_+ekmxHyO9nvLzP1-mJuCw@mail.gmail.com
Whole thread Raw
In response to Re: pg17: XX000: no relation entry for relid 0  (Tender Wang <tndrwang@gmail.com>)
Responses Re: pg17: XX000: no relation entry for relid 0
Re: pg17: XX000: no relation entry for relid 0
List pgsql-hackers
On Fri, Apr 10, 2026 at 9:49 PM Tender Wang <tndrwang@gmail.com> wrote:
> Justin Pryzby <pryzby@telsasoft.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

> 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.

- Richard



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Documenting coding style
Next
From: Andrew Dunstan
Date:
Subject: Re: Documenting coding style