aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/prepare.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-12-29 17:41:26 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-12-29 17:41:26 +0000
commit31c88772c80cf3863ac538d96187640d41f18884 (patch)
tree8ad9d7f345744afa05ee5228806e7aed8dfdf4f0 /src/backend/commands/prepare.c
parent6b922abf6024bb0896249d34423c8b70ed9c4f19 (diff)
downloadpostgresql-31c88772c80cf3863ac538d96187640d41f18884.tar.gz
postgresql-31c88772c80cf3863ac538d96187640d41f18884.zip
Previous fix for temporary file management broke returning a set from
PL/pgSQL function within an exception handler. Make sure we use the right resource owner when we create the tuplestore to hold returned tuples. Simplify tuplestore API so that the caller doesn't need to be in the right memory context when calling tuplestore_put* functions. tuplestore.c automatically switches to the memory context used when the tuplestore was created. Tuplesort was already modified like this earlier. This patch also removes the now useless MemoryContextSwitch calls from callers. Report by Aleksei on pgsql-bugs on Dec 22 2009. Backpatch to 8.1, like the previous patch that broke this.
Diffstat (limited to 'src/backend/commands/prepare.c')
-rw-r--r--src/backend/commands/prepare.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index d5ec457732a..03035cf7b47 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -10,7 +10,7 @@
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.66.2.1 2007/04/26 23:24:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.66.2.2 2009/12/29 17:41:25 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -717,6 +717,9 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
*/
tupstore = tuplestore_begin_heap(true, false, work_mem);
+ /* generate junk in short-term context */
+ MemoryContextSwitchTo(oldcontext);
+
/* hash table might be uninitialized */
if (prepared_queries)
{
@@ -730,9 +733,6 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
Datum values[5];
bool nulls[5];
- /* generate junk in short-term context */
- MemoryContextSwitchTo(oldcontext);
-
MemSet(nulls, 0, sizeof(nulls));
values[0] = DirectFunctionCall1(textin,
@@ -749,9 +749,6 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
values[4] = BoolGetDatum(prep_stmt->from_sql);
tuple = heap_form_tuple(tupdesc, values, nulls);
-
- /* switch to appropriate context while storing the tuple */
- MemoryContextSwitchTo(per_query_ctx);
tuplestore_puttuple(tupstore, tuple);
}
}
@@ -759,8 +756,6 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);
- MemoryContextSwitchTo(oldcontext);
-
rsinfo->returnMode = SFRM_Materialize;
rsinfo->setResult = tupstore;
rsinfo->setDesc = tupdesc;