77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.93 2001/06/22 19:16:21 wieck Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.94 2001/08/02 15:59:28 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -1499,7 +1499,7 @@ deferredTriggerInvokeEvents(bool immediate_only)
14991499per_tuple_context =
15001500AllocSetContextCreate (CurrentMemoryContext ,
15011501"DeferredTriggerTupleContext" ,
1502- 0 ,
1502+ ALLOCSET_DEFAULT_MINSIZE ,
15031503ALLOCSET_DEFAULT_INITSIZE ,
15041504ALLOCSET_DEFAULT_MAXSIZE );
15051505
@@ -1594,9 +1594,13 @@ deferredTriggerInvokeEvents(bool immediate_only)
15941594void
15951595DeferredTriggerInit (void )
15961596{
1597+ /*
1598+ * Since this context will never be reset, give it a minsize of 0.
1599+ * This avoids using any memory if the session never stores anything.
1600+ */
15971601deftrig_gcxt = AllocSetContextCreate (TopMemoryContext ,
15981602"DeferredTriggerSession" ,
1599- ALLOCSET_DEFAULT_MINSIZE ,
1603+ 0 ,
16001604ALLOCSET_DEFAULT_INITSIZE ,
16011605ALLOCSET_DEFAULT_MAXSIZE );
16021606}
@@ -1623,11 +1627,12 @@ DeferredTriggerBeginXact(void)
16231627
16241628/*
16251629 * Create the per transaction memory context and copy all states from
1626- * the per session context to here.
1630+ * the per session context to here. Set the minsize to 0 to avoid
1631+ * wasting memory if there is no deferred trigger data.
16271632 */
16281633deftrig_cxt = AllocSetContextCreate (TopTransactionContext ,
16291634"DeferredTriggerXact" ,
1630- ALLOCSET_DEFAULT_MINSIZE ,
1635+ 0 ,
16311636ALLOCSET_DEFAULT_INITSIZE ,
16321637ALLOCSET_DEFAULT_MAXSIZE );
16331638oldcxt = MemoryContextSwitchTo (deftrig_cxt );
@@ -1911,7 +1916,6 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
19111916
19121917if (!IsTransactionBlock ())
19131918{
1914-
19151919/*
19161920 * Outside of a transaction block set the trigger states of
19171921 * individual triggers on session level.
@@ -1949,7 +1953,6 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt)
19491953}
19501954else
19511955{
1952-
19531956/*
19541957 * Inside of a transaction block set the trigger states of
19551958 * individual triggers on transaction level.