mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
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.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.107 2006/10/04 00:29:52 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.108 2006/10/12 17:02:24 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -327,6 +327,13 @@ postquel_start(execution_state *es, SQLFunctionCachePtr fcache)
|
|||||||
/* Utility commands don't need Executor. */
|
/* Utility commands don't need Executor. */
|
||||||
if (es->qd->operation != CMD_UTILITY)
|
if (es->qd->operation != CMD_UTILITY)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* 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();
|
AfterTriggerBeginQuery();
|
||||||
ExecutorStart(es->qd, 0);
|
ExecutorStart(es->qd, 0);
|
||||||
}
|
}
|
||||||
@ -401,6 +408,7 @@ postquel_end(execution_state *es)
|
|||||||
{
|
{
|
||||||
ActiveSnapshot = es->qd->snapshot;
|
ActiveSnapshot = es->qd->snapshot;
|
||||||
|
|
||||||
|
if (es->qd->operation != CMD_SELECT)
|
||||||
AfterTriggerEndQuery(es->qd->estate);
|
AfterTriggerEndQuery(es->qd->estate);
|
||||||
ExecutorEnd(es->qd);
|
ExecutorEnd(es->qd);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user