10
10
*
11
11
*
12
12
* IDENTIFICATION
13
- * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.186 2004/09/06 17:56:04 tgl Exp $
13
+ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.187 2004/09/10 18:39:55 tgl Exp $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
@@ -138,7 +138,6 @@ static void CleanupSubTransaction(void);
138
138
static void StartAbortedSubTransaction (void );
139
139
static void PushTransaction (void );
140
140
static void PopTransaction (void );
141
- static void CommitTransactionToLevel (int level );
142
141
static char * CleanupAbortedSubTransactions (bool returnName );
143
142
144
143
static void AtSubAbort_Memory (void );
@@ -1219,7 +1218,7 @@ StartTransaction(void)
1219
1218
*/
1220
1219
AtStart_Inval ();
1221
1220
AtStart_Cache ();
1222
- DeferredTriggerBeginXact ();
1221
+ AfterTriggerBeginXact ();
1223
1222
1224
1223
/*
1225
1224
* done with start processing, set current transaction state to "in
@@ -1253,7 +1252,7 @@ CommitTransaction(void)
1253
1252
* committed. He'll invoke all trigger deferred until XACT before we
1254
1253
* really start on committing the transaction.
1255
1254
*/
1256
- DeferredTriggerEndXact ();
1255
+ AfterTriggerEndXact ();
1257
1256
1258
1257
/*
1259
1258
* Similarly, let ON COMMIT management do its thing before we start to
@@ -1454,7 +1453,7 @@ AbortTransaction(void)
1454
1453
/*
1455
1454
* do abort processing
1456
1455
*/
1457
- DeferredTriggerAbortXact ();
1456
+ AfterTriggerAbortXact ();
1458
1457
AtAbort_Portals ();
1459
1458
AtEOXact_LargeObject (false); /* 'false' means it's abort */
1460
1459
AtAbort_Notify ();
@@ -1672,12 +1671,6 @@ CommitTransactionCommand(void)
1672
1671
* default state.
1673
1672
*/
1674
1673
case TBLOCK_END :
1675
- /* commit all open subtransactions */
1676
- if (s -> nestingLevel > 1 )
1677
- CommitTransactionToLevel (2 );
1678
- s = CurrentTransactionState ;
1679
- Assert (s -> parent == NULL );
1680
- /* and now the outer transaction */
1681
1674
CommitTransaction ();
1682
1675
s -> blockState = TBLOCK_DEFAULT ;
1683
1676
break ;
@@ -1732,11 +1725,10 @@ CommitTransactionCommand(void)
1732
1725
break ;
1733
1726
1734
1727
/*
1735
- * We were issued a RELEASE command, so we end the current
1736
- * subtransaction and return to the parent transaction.
1737
- *
1738
- * Since RELEASE can exit multiple levels of subtransaction, we
1739
- * must loop here until we get out of all SUBEND'ed levels.
1728
+ * We were issued a COMMIT or RELEASE command, so we end the
1729
+ * current subtransaction and return to the parent transaction.
1730
+ * Lather, rinse, and repeat until we get out of all SUBEND'ed
1731
+ * subtransaction levels.
1740
1732
*/
1741
1733
case TBLOCK_SUBEND :
1742
1734
do
@@ -1745,6 +1737,13 @@ CommitTransactionCommand(void)
1745
1737
PopTransaction ();
1746
1738
s = CurrentTransactionState ; /* changed by pop */
1747
1739
} while (s -> blockState == TBLOCK_SUBEND );
1740
+ /* If we had a COMMIT command, finish off the main xact too */
1741
+ if (s -> blockState == TBLOCK_END )
1742
+ {
1743
+ Assert (s -> parent == NULL );
1744
+ CommitTransaction ();
1745
+ s -> blockState = TBLOCK_DEFAULT ;
1746
+ }
1748
1747
break ;
1749
1748
1750
1749
/*
@@ -2238,7 +2237,6 @@ EndTransactionBlock(void)
2238
2237
* the default state.
2239
2238
*/
2240
2239
case TBLOCK_INPROGRESS :
2241
- case TBLOCK_SUBINPROGRESS :
2242
2240
s -> blockState = TBLOCK_END ;
2243
2241
result = true;
2244
2242
break ;
@@ -2254,6 +2252,22 @@ EndTransactionBlock(void)
2254
2252
s -> blockState = TBLOCK_ENDABORT ;
2255
2253
break ;
2256
2254
2255
+ /*
2256
+ * We are in a live subtransaction block. Set up to subcommit
2257
+ * all open subtransactions and then commit the main transaction.
2258
+ */
2259
+ case TBLOCK_SUBINPROGRESS :
2260
+ while (s -> parent != NULL )
2261
+ {
2262
+ Assert (s -> blockState == TBLOCK_SUBINPROGRESS );
2263
+ s -> blockState = TBLOCK_SUBEND ;
2264
+ s = s -> parent ;
2265
+ }
2266
+ Assert (s -> blockState == TBLOCK_INPROGRESS );
2267
+ s -> blockState = TBLOCK_END ;
2268
+ result = true;
2269
+ break ;
2270
+
2257
2271
/*
2258
2272
* Here we are inside an aborted subtransaction. Go to the
2259
2273
* "abort the whole tree" state so that
@@ -2699,8 +2713,12 @@ ReleaseCurrentSubTransaction(void)
2699
2713
if (s -> blockState != TBLOCK_SUBINPROGRESS )
2700
2714
elog (ERROR , "ReleaseCurrentSubTransaction: unexpected state %s" ,
2701
2715
BlockStateAsString (s -> blockState ));
2716
+ Assert (s -> state == TRANS_INPROGRESS );
2702
2717
MemoryContextSwitchTo (CurTransactionContext );
2703
- CommitTransactionToLevel (GetCurrentTransactionNestLevel ());
2718
+ CommitSubTransaction ();
2719
+ PopTransaction ();
2720
+ s = CurrentTransactionState ; /* changed by pop */
2721
+ Assert (s -> state == TRANS_INPROGRESS );
2704
2722
}
2705
2723
2706
2724
/*
@@ -2827,28 +2845,6 @@ AbortOutOfAnyTransaction(void)
2827
2845
Assert (s -> parent == NULL );
2828
2846
}
2829
2847
2830
- /*
2831
- * CommitTransactionToLevel
2832
- *
2833
- * Commit everything from the current transaction level
2834
- * up to the specified level (inclusive).
2835
- */
2836
- static void
2837
- CommitTransactionToLevel (int level )
2838
- {
2839
- TransactionState s = CurrentTransactionState ;
2840
-
2841
- Assert (s -> state == TRANS_INPROGRESS );
2842
-
2843
- while (s -> nestingLevel >= level )
2844
- {
2845
- CommitSubTransaction ();
2846
- PopTransaction ();
2847
- s = CurrentTransactionState ; /* changed by pop */
2848
- Assert (s -> state == TRANS_INPROGRESS );
2849
- }
2850
- }
2851
-
2852
2848
/*
2853
2849
* IsTransactionBlock --- are we within a transaction block?
2854
2850
*/
@@ -2975,7 +2971,7 @@ StartSubTransaction(void)
2975
2971
*/
2976
2972
AtSubStart_Inval ();
2977
2973
AtSubStart_Notify ();
2978
- DeferredTriggerBeginSubXact ();
2974
+ AfterTriggerBeginSubXact ();
2979
2975
2980
2976
s -> state = TRANS_INPROGRESS ;
2981
2977
@@ -3011,7 +3007,7 @@ CommitSubTransaction(void)
3011
3007
AtSubCommit_childXids ();
3012
3008
3013
3009
/* Post-commit cleanup */
3014
- DeferredTriggerEndSubXact (true);
3010
+ AfterTriggerEndSubXact (true);
3015
3011
AtSubCommit_Portals (s -> parent -> transactionIdData ,
3016
3012
s -> parent -> curTransactionOwner );
3017
3013
AtEOSubXact_LargeObject (true, s -> transactionIdData ,
@@ -3101,7 +3097,7 @@ AbortSubTransaction(void)
3101
3097
*/
3102
3098
AtSubAbort_Memory ();
3103
3099
3104
- DeferredTriggerEndSubXact (false);
3100
+ AfterTriggerEndSubXact (false);
3105
3101
AtSubAbort_Portals (s -> parent -> transactionIdData ,
3106
3102
s -> parent -> curTransactionOwner );
3107
3103
AtEOSubXact_LargeObject (false, s -> transactionIdData ,
0 commit comments