summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-10-12 17:02:34 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-10-12 17:02:34 +0000
commit9a0271bd31a36e96db24fae47749243243ad082b (patch)
treede95c49020888cc2f0368592d2c979741ab242fa
parentb6a71905d3eedd7b5dcc52d5fccaa86d6b686cf4 (diff)
downloadpostgresql-9a0271bd31a36e96db24fae47749243243ad082b.tar.gz
Fix mishandling of after-trigger state when a SQL function returns multiple
rows --- if the surrounding query queued any trigger events between the rows, the events would be fired at the wrong time, leading to bizarre behavior. Per report from Merlin Moncure. This is a simple patch that should solve the problem fully in the back branches, but in HEAD we also need to consider the possibility of queries with RETURNING clauses. Will look into a fix for that separately.
-rw-r--r--src/backend/executor/functions.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index ae6a0fc537..d08955163e 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.91.4.1 2005/04/10 18:04:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.91.4.2 2006/10/12 17:02:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -328,7 +328,14 @@ postquel_start(execution_state *es, SQLFunctionCachePtr fcache)
/* Utility commands don't need Executor. */
if (es->qd->operation != CMD_UTILITY)
{
- AfterTriggerBeginQuery();
+ /*
+ * Only set up to collect queued triggers if it's not a SELECT.
+ * This isn't just an optimization, but is necessary in case a SELECT
+ * returns multiple rows to caller --- we mustn't exit from the
+ * function execution with a stacked AfterTrigger level still active.
+ */
+ if (es->qd->operation != CMD_SELECT)
+ AfterTriggerBeginQuery();
ExecutorStart(es->qd, false);
}
@@ -401,7 +408,8 @@ postquel_end(execution_state *es)
ActiveSnapshot = es->qd->snapshot;
ExecutorEnd(es->qd);
- AfterTriggerEndQuery();
+ if (es->qd->operation != CMD_SELECT)
+ AfterTriggerEndQuery();
}
PG_CATCH();
{