aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-10-12 17:02:28 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-10-12 17:02:28 +0000
commitfb27f43123e65db1219d296ea3e8bc2f07e9808b (patch)
tree66696071954f5da2d4ec803c043bf79a2aefa80b /src
parent23c64e18ec9136be452ea103190b7dd8561be71a (diff)
downloadpostgresql-fb27f43123e65db1219d296ea3e8bc2f07e9808b.tar.gz
postgresql-fb27f43123e65db1219d296ea3e8bc2f07e9808b.zip
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.
Diffstat (limited to 'src')
-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 b969fdf6de7..06c0d53e2d1 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.98.2.1 2005/11/22 18:23:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.98.2.2 2006/10/12 17:02:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -329,7 +329,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;
- AfterTriggerEndQuery(es->qd->estate);
+ if (es->qd->operation != CMD_SELECT)
+ AfterTriggerEndQuery(es->qd->estate);
ExecutorEnd(es->qd);
}
PG_CATCH();