public inbox for [email protected]  
help / color / mirror / Atom feed
From: Richard Guo <[email protected]>
To: Tender Wang <[email protected]>
Cc: Justin Pryzby <[email protected]>
Cc: [email protected]
Cc: Paul Jungwirth <[email protected]>
Cc: Tom Lane <[email protected]>
Subject: Re: pg17: XX000: no relation entry for relid 0
Date: Fri, 10 Apr 2026 23:38:50 +0900
Message-ID: <CAMbWs49Wi81GGO_drC4PJgQUehz4_+ekmxHyO9nvLzP1-mJuCw@mail.gmail.com> (raw)
In-Reply-To: <CAHewXN=_C3apEh4nDndgbOiYnFAYDDuMWAozPP0G3iL=7zQbJg@mail.gmail.com>
References: <adjW8rfPDkplC7lF@pryzbyj2023>
	<CAHewXN=_C3apEh4nDndgbOiYnFAYDDuMWAozPP0G3iL=7zQbJg@mail.gmail.com>

On Fri, Apr 10, 2026 at 9:49 PM Tender Wang <[email protected]> wrote:
> Justin Pryzby <[email protected]> 于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





view thread (6+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: pg17: XX000: no relation entry for relid 0
  In-Reply-To: <CAMbWs49Wi81GGO_drC4PJgQUehz4_+ekmxHyO9nvLzP1-mJuCw@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