diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-12-02 18:05:29 -0500 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-12-02 18:05:29 -0500 |
| commit | ce76c0ba53e4bd0daf3db7a703671b27797b7244 (patch) | |
| tree | 920ca4a5cc36e169181e12cc3880f2295f28e17a /src/backend/optimizer/prep | |
| parent | 4526951d564a7eed512b4a0ac3b5893e0a115690 (diff) | |
Add a reverse-translation column number array to struct AppendRelInfo.
This provides for cheaper mapping of child columns back to parent
columns. The one existing use-case in examine_simple_variable()
would hardly justify this by itself; but an upcoming bug fix will
make use of this array in a mainstream code path, and it seems
likely that we'll find other uses for it as we continue to build
out the partitioning infrastructure.
Discussion: https://postgr.es/m/12424.1575168015@sss.pgh.pa.us
Diffstat (limited to 'src/backend/optimizer/prep')
| -rw-r--r-- | src/backend/optimizer/prep/prepjointree.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index f489f140e37..db25bcf441f 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -81,7 +81,7 @@ static void pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root, int parentRTindex, Query *setOpQuery, int childRToffset); static void make_setop_translation_list(Query *query, Index newvarno, - List **translated_vars); + AppendRelInfo *appinfo); static bool is_simple_subquery(Query *subquery, RangeTblEntry *rte, JoinExpr *lowest_outer_join); static Node *pull_up_simple_values(PlannerInfo *root, Node *jtnode, @@ -1313,8 +1313,7 @@ pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root, int parentRTindex, appinfo->child_relid = childRTindex; appinfo->parent_reltype = InvalidOid; appinfo->child_reltype = InvalidOid; - make_setop_translation_list(setOpQuery, childRTindex, - &appinfo->translated_vars); + make_setop_translation_list(setOpQuery, childRTindex, appinfo); appinfo->parent_reloid = InvalidOid; root->append_rel_list = lappend(root->append_rel_list, appinfo); @@ -1356,14 +1355,22 @@ pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root, int parentRTindex, * a UNION ALL member. (At this point it's just a simple list of * referencing Vars, but if we succeed in pulling up the member * subquery, the Vars will get replaced by pulled-up expressions.) + * Also create the rather trivial reverse-translation array. */ static void make_setop_translation_list(Query *query, Index newvarno, - List **translated_vars) + AppendRelInfo *appinfo) { List *vars = NIL; + AttrNumber *pcolnos; ListCell *l; + /* Initialize reverse-translation array with all entries zero */ + /* (entries for resjunk columns will stay that way) */ + appinfo->num_child_cols = list_length(query->targetList); + appinfo->parent_colnos = pcolnos = + (AttrNumber *) palloc0(appinfo->num_child_cols * sizeof(AttrNumber)); + foreach(l, query->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(l); @@ -1372,9 +1379,10 @@ make_setop_translation_list(Query *query, Index newvarno, continue; vars = lappend(vars, makeVarFromTargetEntry(newvarno, tle)); + pcolnos[tle->resno - 1] = tle->resno; } - *translated_vars = vars; + appinfo->translated_vars = vars; } /* |
