aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-06-03 18:07:14 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-06-03 18:07:14 -0400
commit8355897ff296a3634f6b9c3da444622a02adda9c (patch)
treeb07cf5bbe57ec17b9834f4b000c627d9fc71a759 /src/backend/executor
parenta102f98e26bc7d21eb5246fd345f8e3ab31be109 (diff)
downloadpostgresql-8355897ff296a3634f6b9c3da444622a02adda9c.tar.gz
postgresql-8355897ff296a3634f6b9c3da444622a02adda9c.zip
Mark read/write expanded values as read-only in ValuesNext(), too.
Further thought about bug #14174 motivated me to try the case of a R/W datum being returned from a VALUES list, and sure enough it was broken. Fix that. Also add a regression test case exercising the same scenario for FunctionScan. That's not broken right now, because the function's result will get shoved into a tuplestore between generation and use; but it could easily become broken whenever we get around to optimizing FunctionScan better. There don't seem to be any other places where we put the result of expression evaluation into a virtual tuple slot that could then be the source for Vars of further expression evaluation, so I think this is the end of this bug.
Diffstat (limited to 'src/backend/executor')
-rw-r--r--src/backend/executor/nodeValuesscan.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/executor/nodeValuesscan.c b/src/backend/executor/nodeValuesscan.c
index a39695a0c5f..0e9cb11cf3e 100644
--- a/src/backend/executor/nodeValuesscan.c
+++ b/src/backend/executor/nodeValuesscan.c
@@ -25,6 +25,7 @@
#include "executor/executor.h"
#include "executor/nodeValuesscan.h"
+#include "utils/expandeddatum.h"
static TupleTableSlot *ValuesNext(ValuesScanState *node);
@@ -94,6 +95,7 @@ ValuesNext(ValuesScanState *node)
List *exprstatelist;
Datum *values;
bool *isnull;
+ Form_pg_attribute *att;
ListCell *lc;
int resind;
@@ -129,6 +131,7 @@ ValuesNext(ValuesScanState *node)
*/
values = slot->tts_values;
isnull = slot->tts_isnull;
+ att = slot->tts_tupleDescriptor->attrs;
resind = 0;
foreach(lc, exprstatelist)
@@ -139,6 +142,17 @@ ValuesNext(ValuesScanState *node)
econtext,
&isnull[resind],
NULL);
+
+ /*
+ * We must force any R/W expanded datums to read-only state, in
+ * case they are multiply referenced in the plan node's output
+ * expressions, or in case we skip the output projection and the
+ * output column is multiply referenced in higher plan nodes.
+ */
+ values[resind] = MakeExpandedObjectReadOnly(values[resind],
+ isnull[resind],
+ att[resind]->attlen);
+
resind++;
}