diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2009-12-29 17:40:59 +0000 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2009-12-29 17:40:59 +0000 |
commit | 84d723b6cefcf25b8c800f8aa6cf3c9538a546b4 (patch) | |
tree | fa91ab7b2bc60f3d602a330bc68b78ae8beab69b /src/backend/commands/prepare.c | |
parent | 50ef9f7b0612c755097bbddd7f2985237030c31a (diff) | |
download | postgresql-84d723b6cefcf25b8c800f8aa6cf3c9538a546b4.tar.gz postgresql-84d723b6cefcf25b8c800f8aa6cf3c9538a546b4.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.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 021c2daf26d..8df3b4be41c 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -10,7 +10,7 @@ * Copyright (c) 2002-2009, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.100 2009/11/04 22:26:05 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.101 2009/12/29 17:40:59 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -779,6 +779,9 @@ pg_prepared_statement(PG_FUNCTION_ARGS) tuplestore_begin_heap(rsinfo->allowedModes & SFRM_Materialize_Random, false, work_mem); + /* generate junk in short-term context */ + MemoryContextSwitchTo(oldcontext); + /* hash table might be uninitialized */ if (prepared_queries) { @@ -791,9 +794,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] = CStringGetTextDatum(prep_stmt->stmt_name); @@ -803,8 +803,6 @@ pg_prepared_statement(PG_FUNCTION_ARGS) prep_stmt->plansource->num_params); values[4] = BoolGetDatum(prep_stmt->from_sql); - /* switch to appropriate context while storing the tuple */ - MemoryContextSwitchTo(per_query_ctx); tuplestore_putvalues(tupstore, tupdesc, values, nulls); } } @@ -812,8 +810,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; |