diff options
| author | Tom Lane | 2019-12-11 22:05:18 +0000 |
|---|---|---|
| committer | Tom Lane | 2019-12-11 22:05:18 +0000 |
| commit | 6ef77cf46e81f45716ec981cb08781d426181378 (patch) | |
| tree | 39e28a070288a373431e396c3f92d3e9ebcf14a2 /src/include | |
| parent | ba79cb5dc841104cf4810b5c23af4f881079dbb5 (diff) | |
Further adjust EXPLAIN's choices of table alias names.
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 55a1954da),
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 1cc29fe7c, 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
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/nodes/execnodes.h | 1 | ||||
| -rw-r--r-- | src/include/nodes/pathnodes.h | 2 | ||||
| -rw-r--r-- | src/include/nodes/plannodes.h | 4 | ||||
| -rw-r--r-- | src/include/utils/ruleutils.h | 10 |
4 files changed, 13 insertions, 4 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 692438d6dfd..ea93b769e1d 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -1171,7 +1171,6 @@ typedef struct ModifyTableState List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */ EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ bool fireBSTriggers; /* do we need to fire stmt triggers? */ - List *mt_excludedtlist; /* the excluded pseudo relation's tlist */ /* * Slot for storing tuples in the root partitioned table's rowtype during diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h index 6dab810d68f..31b631cfe0f 100644 --- a/src/include/nodes/pathnodes.h +++ b/src/include/nodes/pathnodes.h @@ -122,6 +122,8 @@ typedef struct PlannerGlobal List *rootResultRelations; /* "flat" list of integer RT indexes */ + List *appendRelations; /* "flat" list of AppendRelInfos */ + List *relationOids; /* OIDs of relations the plan depends on */ List *invalItems; /* other dependencies, as PlanInvalItems */ diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 8e6594e3551..477b4da192c 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -74,6 +74,8 @@ typedef struct PlannedStmt */ List *rootResultRelations; + List *appendRelations; /* list of AppendRelInfo nodes */ + List *subplans; /* Plan trees for SubPlan expressions; note * that some could be NULL */ @@ -249,6 +251,7 @@ struct PartitionPruneInfo; /* forward reference to struct below */ typedef struct Append { Plan plan; + Bitmapset *apprelids; /* RTIs of appendrel(s) formed by this node */ List *appendplans; /* @@ -269,6 +272,7 @@ typedef struct Append typedef struct MergeAppend { Plan plan; + Bitmapset *apprelids; /* RTIs of appendrel(s) formed by this node */ List *mergeplans; /* these fields are just like the sort-key info in struct Sort: */ int numCols; /* number of sort-key columns */ diff --git a/src/include/utils/ruleutils.h b/src/include/utils/ruleutils.h index d34cad2f4b8..ac408905fa8 100644 --- a/src/include/utils/ruleutils.h +++ b/src/include/utils/ruleutils.h @@ -17,6 +17,9 @@ #include "nodes/parsenodes.h" #include "nodes/pg_list.h" +struct Plan; /* avoid including plannodes.h here */ +struct PlannedStmt; + extern char *pg_get_indexdef_string(Oid indexrelid); extern char *pg_get_indexdef_columns(Oid indexrelid, bool pretty); @@ -28,9 +31,10 @@ extern char *pg_get_constraintdef_command(Oid constraintId); extern char *deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit); extern List *deparse_context_for(const char *aliasname, Oid relid); -extern List *deparse_context_for_plan_rtable(List *rtable, List *rtable_names); -extern List *set_deparse_context_planstate(List *dpcontext, - Node *planstate, List *ancestors); +extern List *deparse_context_for_plan_tree(struct PlannedStmt *pstmt, + List *rtable_names); +extern List *set_deparse_context_plan(List *dpcontext, + struct Plan *plan, List *ancestors); extern List *select_rtable_names_for_explain(List *rtable, Bitmapset *rels_used); extern char *generate_collation_name(Oid collid); |
