Henson Choi <[email protected]> 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