mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Fire non-deferred AFTER triggers immediately upon query completion,
rather than when returning to the idle loop. This makes no particular difference for interactively-issued queries, but it makes a big difference for queries issued within functions: trigger execution now occurs before the calling function is allowed to proceed. This responds to numerous complaints about nonintuitive behavior of foreign key checking, such as http://archives.postgresql.org/pgsql-bugs/2004-09/msg00020.php, and appears to be required by the SQL99 spec. Also take the opportunity to simplify the data structures used for the pending-trigger list, rename them for more clarity, and squeeze out a bit of space.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.230 2004/08/29 05:06:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.231 2004/09/10 18:39:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1610,6 +1610,11 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare to catch AFTER triggers.
|
||||
*/
|
||||
AfterTriggerBeginQuery();
|
||||
|
||||
/*
|
||||
* Check BEFORE STATEMENT insertion triggers. It's debateable whether
|
||||
* we should do this for COPY, since it's not really an "INSERT"
|
||||
@@ -1974,6 +1979,11 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
*/
|
||||
ExecASInsertTriggers(estate, resultRelInfo);
|
||||
|
||||
/*
|
||||
* Handle queued AFTER triggers
|
||||
*/
|
||||
AfterTriggerEndQuery();
|
||||
|
||||
pfree(values);
|
||||
pfree(nulls);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994-5, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.124 2004/08/29 05:06:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.125 2004/09/10 18:39:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/explain.h"
|
||||
#include "commands/prepare.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "executor/executor.h"
|
||||
#include "executor/instrument.h"
|
||||
#include "lib/stringinfo.h"
|
||||
@@ -206,6 +207,10 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
|
||||
|
||||
gettimeofday(&starttime, NULL);
|
||||
|
||||
/* If analyzing, we need to cope with queued triggers */
|
||||
if (stmt->analyze)
|
||||
AfterTriggerBeginQuery();
|
||||
|
||||
/* call ExecutorStart to prepare the plan for execution */
|
||||
ExecutorStart(queryDesc, false, !stmt->analyze);
|
||||
|
||||
@@ -255,12 +260,16 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
|
||||
}
|
||||
|
||||
/*
|
||||
* Close down the query and free resources. Include time for this in
|
||||
* the total runtime.
|
||||
* Close down the query and free resources; also run any queued
|
||||
* AFTER triggers. Include time for this in the total runtime.
|
||||
*/
|
||||
gettimeofday(&starttime, NULL);
|
||||
|
||||
ExecutorEnd(queryDesc);
|
||||
|
||||
if (stmt->analyze)
|
||||
AfterTriggerEndQuery();
|
||||
|
||||
FreeQueryDesc(queryDesc);
|
||||
|
||||
CommandCounterIncrement();
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.33 2004/08/29 05:06:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.34 2004/09/10 18:39:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -273,6 +273,7 @@ PortalCleanup(Portal portal)
|
||||
{
|
||||
CurrentResourceOwner = portal->resowner;
|
||||
ExecutorEnd(queryDesc);
|
||||
/* we do not need AfterTriggerEndQuery() here */
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
@@ -373,6 +374,7 @@ PersistHoldablePortal(Portal portal)
|
||||
*/
|
||||
portal->queryDesc = NULL; /* prevent double shutdown */
|
||||
ExecutorEnd(queryDesc);
|
||||
/* we do not need AfterTriggerEndQuery() here */
|
||||
|
||||
/*
|
||||
* Reset the position in the result set: ideally, this could be
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user