• Tom Lane's avatar
    Further adjust EXPLAIN's choices of table alias names. · 6ef77cf4
    Tom Lane authored
    This patch causes EXPLAIN to always assign a separate table alias to the
    parent RTE of an append relation (inheritance set); before, such RTEs
    were ignored if not actually scanned by the plan.  Since the child RTEs
    now always have that same alias to start with (cf. commit 55a1954d),
    the net effect is that the parent RTE usually gets the alias used or
    implied by the query text, and the children all get that alias with "_N"
    appended.  (The exception to "usually" is if there are duplicate aliases
    in different subtrees of the original query; then some of those original
    RTEs will also have "_N" appended.)
    
    This results in more uniform output for partitioned-table plans than
    we had before: the partitioned table itself gets the original alias,
    and all child tables have aliases with "_N", rather than the previous
    behavior where one of the children would get an alias without "_N".
    
    The reason for giving the parent RTE an alias, even if it isn't scanned
    by the plan, is that we now use the parent's alias to qualify Vars that
    refer to an appendrel output column and appear above the Append or
    MergeAppend that computes the appendrel.  But below the append, Vars
    refer to some one of the child relations, and are displayed that way.
    This seems clearer than the old behavior where a Var that could carry
    values from any child relation was displayed as if it referred to only
    one of them.
    
    While at it, change ruleutils.c so that the code paths used by EXPLAIN
    deal in Plan trees not PlanState trees.  This effectively reverts a
    decision made in commit 1cc29fe7, which seemed like a good idea at
    the time to make ruleutils.c consistent with explain.c.  However,
    it's problematic because we'd really like to allow executor startup
    pruning to remove all the children of an append node when possible,
    leaving no child PlanState to resolve Vars against.  (That's not done
    here, but will be in the next patch.)  This requires different handling
    of subplans and initplans than before, but is otherwise a pretty
    straightforward change.
    
    Discussion: https://postgr.es/m/001001d4f44b$2a2cca50$7e865ef0$@lab.ntt.co.jp
    6ef77cf4
outfuncs.c 101 KB