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: assam258(at)gmail(dot)com
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Subject: Re: [DEPARSE] EXPLAIN prints another ModifyTable's RETURNING aliases in a SubPlan
Date: 2026-10-20 21:37:48
Message-ID: 1524640.1792532268@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Henson Choi <assam258(at)gmail(dot)com> writes:
> The aliases are not stored in the Vars, which only say whether they
> are OLD or NEW (varreturningtype). ruleutils.c keeps the names of
> the ModifyTable it is looking at in the deparse namespace, and
> get_variable() prints them. set_deparse_context_plan(), which
> EXPLAIN calls for each node it prints, set them when that node was a
> ModifyTable. But to print a Param of a SubPlan, get_parameter()
> moves to the ancestor ModifyTable with push_ancestor_plan(), and the
> set_deparse_plan() that it calls left the aliases alone. They were
> still those of the last ModifyTable EXPLAIN had printed, here the
> CTE's.

Yeah, that should be done in set_deparse_plan(). But I think we
can make this tighter: RETURNING variables should only appear in
ModifyTable nodes. So rather than allow the behavior to be
plan-traversal-order-dependent, I made the set_deparse_plan()
addition look like

+ if (IsA(plan, ModifyTable))
+ {
+ dpns->ret_old_alias = ((ModifyTable *) plan)->returningOldAlias;
+ dpns->ret_new_alias = ((ModifyTable *) plan)->returningNewAlias;
+ }
+ else
+ dpns->ret_old_alias = dpns->ret_new_alias = NULL;

and added Asserts in get_variable that when it consults those fields,
it doesn't get a NULL. Pushed with those changes.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-10-20 22:12:20 Re: Reject COPY TO of unlogged relations during recovery
Previous Message Peter Smith 2026-10-20 21:34:13 Re: Publication of same parent table with ONLY-ness mismatch should error