From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <dgrowleyml@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs
Date: Sat, 04 Oct 2025 11:43:48 -0400
Message-ID: <1507624.1759592628@sss.pgh.pa.us> (raw)
In-Reply-To: <CAApHDvrUASy9sfULMEsM2udvZJP6AoBRCZvHYXYxZTy2tX9FYw@mail.gmail.com>
References: <CAApHDvri53PPF76c3M94_QNWbJfXjyCnjXuj_2=LYM-0m8WZtw@mail.gmail.com>
<976130.1759375308@sss.pgh.pa.us>
<CAApHDvpk88w3MrzgZShROjQw3NPK54YKr_hOi0++0QKGwTq+-g@mail.gmail.com>
<1064547.1759418336@sss.pgh.pa.us>
<CAApHDvpVYC43mi8atZ2Q39emK45xh7AaXetMJE9gJyV6sge_mg@mail.gmail.com>
<1196118.1759438964@sss.pgh.pa.us>
<CAApHDvrUASy9sfULMEsM2udvZJP6AoBRCZvHYXYxZTy2tX9FYw@mail.gmail.com>
David Rowley <dgrowleyml@gmail.com> writes:
> I'm just considering the best fix and can think of two options:
> 1) Move away from using varno==0 in generate_append_tlist(). Use varno==1, or;
> 2) Add handling in setrefs.c for T_Result to adjust varno==0 Vars to
> use varno==1 vars.
> The attached v4-0001 does #2, but wondering if #1 should be explored first.
I don't recall the details ATM, but if you poke around you will find
multiple comments complaining about how that varno-zero convention is
problematic or requires code to do something unusual. So I'd be in
favor of trying to get rid of it, but I'm not entirely sure what to do
instead, and the ramifications might be wider than you realize.
In particular it's not clear to me why varno==1 is better? As best
I can recall without diving into code, the fundamental mismatch is
that varno zero doesn't correspond to any RTE. It would be better
if the Vars matched the subquery RTEs that are at the base of the
set-operation nest, so that there were a useful referent as to where
a Var came from. Arbitrarily setting varno=1 sounds like the worst
case: we could neither identify a Var with a source subquery
accurately, nor realize that its varno is phony.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, dgrowleyml@gmail.com
Subject: Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs
In-Reply-To: <1507624.1759592628@sss.pgh.pa.us>
References: <CAApHDvri53PPF76c3M94_QNWbJfXjyCnjXuj_2=LYM-0m8WZtw@mail.gmail.com> <976130.1759375308@sss.pgh.pa.us> <CAApHDvpk88w3MrzgZShROjQw3NPK54YKr_hOi0++0QKGwTq+-g@mail.gmail.com> <1064547.1759418336@sss.pgh.pa.us> <CAApHDvpVYC43mi8atZ2Q39emK45xh7AaXetMJE9gJyV6sge_mg@mail.gmail.com> <1196118.1759438964@sss.pgh.pa.us> <CAApHDvrUASy9sfULMEsM2udvZJP6AoBRCZvHYXYxZTy2tX9FYw@mail.gmail.com> <1507624.1759592628@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox