aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeValuesscan.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-11-10 15:21:09 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2014-11-10 15:21:09 -0500
commitbf7ca15875988a88e97302e012d7c4808bef3ea9 (patch)
treeb3fda5c24a98a2eeb816a87b557fc47ddb16996c /src/backend/executor/nodeValuesscan.c
parent1e0b4365c22c9f8a1bc7a5f8339f770c767b402f (diff)
downloadpostgresql-bf7ca15875988a88e97302e012d7c4808bef3ea9.tar.gz
postgresql-bf7ca15875988a88e97302e012d7c4808bef3ea9.zip
Ensure that RowExprs and whole-row Vars produce the expected column names.
At one time it wasn't terribly important what column names were associated with the fields of a composite Datum, but since the introduction of operations like row_to_json(), it's important that looking up the rowtype ID embedded in the Datum returns the column names that users would expect. That did not work terribly well before this patch: you could get the column names of the underlying table, or column aliases from any level of the query, depending on minor details of the plan tree. You could even get totally empty field names, which is disastrous for cases like row_to_json(). To fix this for whole-row Vars, look to the RTE referenced by the Var, and make sure its column aliases are applied to the rowtype associated with the result Datums. This is a tad scary because we might have to return a transient RECORD type even though the Var is declared as having some named rowtype. In principle it should be all right because the record type will still be physically compatible with the named rowtype; but I had to weaken one Assert in ExecEvalConvertRowtype, and there might be third-party code containing similar assumptions. Similarly, RowExprs have to be willing to override the column names coming from a named composite result type and produce a RECORD when the column aliases visible at the site of the RowExpr differ from the underlying table's column names. In passing, revert the decision made in commit 398f70ec070fe601 to add an alias-list argument to ExecTypeFromExprList: better to provide that functionality in a separate function. This also reverts most of the code changes in d68581483564ec0f, which we don't need because we're no longer depending on the tupdesc found in the child plan node's result slot to be blessed. Back-patch to 9.4, but not earlier, since this solution changes the results in some cases that users might not have realized were buggy. We'll apply a more restricted form of this patch in older branches.
Diffstat (limited to 'src/backend/executor/nodeValuesscan.c')
-rw-r--r--src/backend/executor/nodeValuesscan.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/src/backend/executor/nodeValuesscan.c b/src/backend/executor/nodeValuesscan.c
index 83b1324abc5..d49a4733865 100644
--- a/src/backend/executor/nodeValuesscan.c
+++ b/src/backend/executor/nodeValuesscan.c
@@ -25,7 +25,6 @@
#include "executor/executor.h"
#include "executor/nodeValuesscan.h"
-#include "parser/parsetree.h"
static TupleTableSlot *ValuesNext(ValuesScanState *node);
@@ -189,8 +188,6 @@ ValuesScanState *
ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags)
{
ValuesScanState *scanstate;
- RangeTblEntry *rte = rt_fetch(node->scan.scanrelid,
- estate->es_range_table);
TupleDesc tupdesc;
ListCell *vtl;
int i;
@@ -242,8 +239,7 @@ ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags)
/*
* get info about values list
*/
- tupdesc = ExecTypeFromExprList((List *) linitial(node->values_lists),
- rte->eref->colnames);
+ tupdesc = ExecTypeFromExprList((List *) linitial(node->values_lists));
ExecAssignScanType(&scanstate->ss, tupdesc);