summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/var.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-02-14 17:34:19 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-02-14 17:34:56 -0500
commit398f70ec070fe60151584eaa448f04708aa77892 (patch)
tree508ae6812ca581b5e39e11bb80206aa87e115046 /src/backend/optimizer/util/var.c
parentc1d9df4fa227781b31be44a5a3024865a7f48049 (diff)
Preserve column names in the execution-time tupledesc for a RowExpr.
The hstore and json datatypes both have record-conversion functions that pay attention to column names in the composite values they're handed. We used to not worry about inserting correct field names into tuple descriptors generated at runtime, but given these examples it seems useful to do so. Observe the nicer-looking results in the regression tests whose results changed. catversion bump because there is a subtle change in requirements for stored rule parsetrees: RowExprs from ROW() constructs now have to include field names. Andrew Dunstan and Tom Lane
Diffstat (limited to 'src/backend/optimizer/util/var.c')
-rw-r--r--src/backend/optimizer/util/var.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/backend/optimizer/util/var.c b/src/backend/optimizer/util/var.c
index 475299daddd..2bffb0a651e 100644
--- a/src/backend/optimizer/util/var.c
+++ b/src/backend/optimizer/util/var.c
@@ -783,13 +783,16 @@ flatten_join_alias_vars_mutator(Node *node,
/* Must expand whole-row reference */
RowExpr *rowexpr;
List *fields = NIL;
+ List *colnames = NIL;
AttrNumber attnum;
- ListCell *l;
+ ListCell *lv;
+ ListCell *ln;
attnum = 0;
- foreach(l, rte->joinaliasvars)
+ Assert(list_length(rte->joinaliasvars) == list_length(rte->eref->colnames));
+ forboth(lv, rte->joinaliasvars, ln, rte->eref->colnames)
{
- newvar = (Node *) lfirst(l);
+ newvar = (Node *) lfirst(lv);
attnum++;
/* Ignore dropped columns */
if (IsA(newvar, Const))
@@ -809,12 +812,14 @@ flatten_join_alias_vars_mutator(Node *node,
/* (also takes care of setting inserted_sublink if needed) */
newvar = flatten_join_alias_vars_mutator(newvar, context);
fields = lappend(fields, newvar);
+ /* We need the names of non-dropped columns, too */
+ colnames = lappend(colnames, copyObject((Node *) lfirst(ln)));
}
rowexpr = makeNode(RowExpr);
rowexpr->args = fields;
rowexpr->row_typeid = var->vartype;
rowexpr->row_format = COERCE_IMPLICIT_CAST;
- rowexpr->colnames = NIL;
+ rowexpr->colnames = colnames;
rowexpr->location = var->location;
return (Node *) rowexpr;