Re: [DEPARSE] EXPLAIN prints another ModifyTable's RETURNING aliases in a SubPlan

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, assam258(at)gmail(dot)com, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [DEPARSE] EXPLAIN prints another ModifyTable's RETURNING aliases in a SubPlan
Date: 2026-10-21 21:03:14
Message-ID: 2234675.1792616594@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> writes:
> On Wed, 21 Oct 2026 at 23:30, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> This makes me think it is probably possible to construct scenarios
>> where a plan contains both VAR_RETURNING Vars that originated inside
>> a rule and some that originated from the calling query, in which
>> case using either level's aliases across-the-board would be wrong.
>> But we don't have a lot of choice, because that mixing happens in
>> the rewriter and its output format doesn't support recording multiple
>> sets of aliases (or does it? maybe the two sets of Vars will have
>> different varlevelsup?).

> AFAICS no, both come out at varlevelsup 0 with the same varno. E.g.
> if the rule does RETURNING WITH (OLD AS o) o.a, t.b, an outer
> UPDATE v ... RETURNING old.b shows up as o.b in EXPLAIN

Yeah. I am thinking that the VAR_RETURNING representation was done
wrong, and that a superior solution would have involved adding more
dummy RTEs to the rtable and making these Vars reference those by
varno instead of having a separate marker field. Then this problem
would be addressed by existing (I think) logic for merging the rule
and query rtables, and the plan-node aliasname fields probably go away
in favor of RTE indexes for the special RTEs. I'm not volunteering to
rewrite all that, though.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2026-10-21 21:05:36 Re: [DEPARSE] EXPLAIN prints another ModifyTable's RETURNING aliases in a SubPlan
Previous Message Ayush Tiwari 2026-10-21 20:47:26 Re: [DEPARSE] EXPLAIN prints another ModifyTable's RETURNING aliases in a SubPlan