Re: BUG #19784: "no relation entry for relid 1" when costing = ANY (<array expr over max(col)>) in a MinMaxAggPath

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: alpkeles99(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, Richard Guo <guofenglinux(at)gmail(dot)com>
Subject: Re: BUG #19784: "no relation entry for relid 1" when costing = ANY (<array expr over max(col)>) in a MinMaxAggPath
Date: 2026-10-23 15:02:19
Message-ID: 2962069.1792767739@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

shihao zhong <zhong950419(at)gmail(dot)com> writes:
>> What is bothering me a bit here is that this is surely not the only
>> estimator routine that calls examine_variable, so why don't we
>> have other problems?

> It does not fix this:

> CREATE TABLE ei (a int4[]);
> CREATE INDEX ON ei
> ((((1 = ANY (a))::int + (2 = ANY (a))::int) <@ int4range(0, 5)));
> SELECT * FROM ei;
> ERROR: no relation entry for relid 1

Yeah, I thought there were probably other cases :-(

> The attached patch on top of yours passes NULL as root to
> cost_qual_eval_node() in find_simplified_clause(), like aba8f61c3 did
> for cost_subplan(). It fixes all the attached cases.

Surely this way madness lies. The change you make here seriously
weakens our estimation abilities in normal cases, and it offers no
particular guarantee that there aren't other code paths (now or in
the future) that can trigger the same problem.

I think the only reasonably bulletproof answer is to change
examine_variable() to tolerate not finding a RelOptInfo.
That allows us to take out the hack from 77d0e82e5, though
I left its test case.

regards, tom lane

Attachment Content-Type Size
allow-examine_variable-before-baserels-are-built.patch text/x-diff 3.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Matheus Alcantara 2026-10-23 15:34:28 Re: BUG #19752: GROUP BY on a constant and a cast to a length-limited array type crashes the server while planning
Previous Message Prashant Kumar 2026-10-23 14:55:54 Re: BUG #19743: pgcrypto crypt(): sha-crypt rounds= silently wraps modulo 2^32