aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-11-27 22:27:32 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-11-27 22:27:32 -0500
commit0702c86a13e6c644c32cf773af0a3a76e425ec50 (patch)
tree5ec9f1e30d78a0589f95706c835dd0682f78260c /src/backend/parser/parse_expr.c
parentbcba9acf0d56d3fd5aa37c4ba6b24b6084032e58 (diff)
downloadpostgresql-0702c86a13e6c644c32cf773af0a3a76e425ec50.tar.gz
postgresql-0702c86a13e6c644c32cf773af0a3a76e425ec50.zip
Ensure that whole-row junk Vars are always of composite type.
The EvalPlanQual machinery assumes that whole-row Vars generated for the outputs of non-table RTEs will be of composite types. However, for the case where the RTE is a function call returning a scalar type, we were doing the wrong thing, as a result of sharing code with a parser case where the function's scalar output is wanted. (Or at least, that's what that case has done historically; it does seem a bit inconsistent.) To fix, extend makeWholeRowVar's API so that it can support both use-cases. This fixes Belinda Cussen's report of crashes during concurrent execution of UPDATEs involving joins to the result of UNNEST() --- in READ COMMITTED mode, we'd run the EvalPlanQual machinery after a conflicting row update commits, and it was expecting to get a HeapTuple not a scalar datum from the "wholerowN" variable referencing the function RTE. Back-patch to 9.0 where the current EvalPlanQual implementation appeared. In 9.1 and up, this patch also fixes failure to attach the correct collation to the Var generated for a scalar-result case. An example: regression=# select upper(x.*) from textcat('ab', 'cd') x; ERROR: could not determine which collation to use for upper() function
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 79328c99797..75236c76a1f 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -2059,8 +2059,15 @@ transformWholeRowRef(ParseState *pstate, RangeTblEntry *rte, int location)
/* Find the RTE's rangetable location */
vnum = RTERangeTablePosn(pstate, rte, &sublevels_up);
- /* Build the appropriate referencing node */
- result = makeWholeRowVar(rte, vnum, sublevels_up);
+ /*
+ * Build the appropriate referencing node. Note that if the RTE is a
+ * function returning scalar, we create just a plain reference to the
+ * function value, not a composite containing a single column. This is
+ * pretty inconsistent at first sight, but it's what we've done
+ * historically. One argument for it is that "rel" and "rel.*" mean the
+ * same thing for composite relations, so why not for scalar functions...
+ */
+ result = makeWholeRowVar(rte, vnum, sublevels_up, true);
/* location is not filled in by makeWholeRowVar */
result->location = location;