@@ -269,7 +269,7 @@ static TransactionId RecordTransactionAbort(bool isSubXact);
269
269
static void StartTransaction (void );
270
270
271
271
static void StartSubTransaction (void );
272
- static void CommitSubTransaction (bool isTopLevel );
272
+ static void CommitSubTransaction (void );
273
273
static void AbortSubTransaction (void );
274
274
static void CleanupSubTransaction (void );
275
275
static void PushTransaction (void );
@@ -2578,7 +2578,7 @@ CommitTransactionCommand(void)
2578
2578
case TBLOCK_SUBRELEASE :
2579
2579
do
2580
2580
{
2581
- CommitSubTransaction (false );
2581
+ CommitSubTransaction ();
2582
2582
s = CurrentTransactionState ; /* changed by pop */
2583
2583
} while (s -> blockState == TBLOCK_SUBRELEASE );
2584
2584
@@ -2588,12 +2588,17 @@ CommitTransactionCommand(void)
2588
2588
2589
2589
/*
2590
2590
* We were issued a COMMIT, so we end the current subtransaction
2591
- * hierarchy and perform final commit.
2591
+ * hierarchy and perform final commit. We do this by rolling up
2592
+ * any subtransactions into their parent, which leads to O(N^2)
2593
+ * operations with respect to resource owners - this isn't that
2594
+ * bad until we approach a thousands of savepoints but is necessary
2595
+ * for correctness should after triggers create new resource
2596
+ * owners.
2592
2597
*/
2593
2598
case TBLOCK_SUBCOMMIT :
2594
2599
do
2595
2600
{
2596
- CommitSubTransaction (true );
2601
+ CommitSubTransaction ();
2597
2602
s = CurrentTransactionState ; /* changed by pop */
2598
2603
} while (s -> blockState == TBLOCK_SUBCOMMIT );
2599
2604
/* If we had a COMMIT command, finish off the main xact too */
@@ -3745,7 +3750,7 @@ ReleaseCurrentSubTransaction(void)
3745
3750
BlockStateAsString (s -> blockState ));
3746
3751
Assert (s -> state == TRANS_INPROGRESS );
3747
3752
MemoryContextSwitchTo (CurTransactionContext );
3748
- CommitSubTransaction (false );
3753
+ CommitSubTransaction ();
3749
3754
s = CurrentTransactionState ; /* changed by pop */
3750
3755
Assert (s -> state == TRANS_INPROGRESS );
3751
3756
}
@@ -4009,13 +4014,9 @@ StartSubTransaction(void)
4009
4014
*
4010
4015
* The caller has to make sure to always reassign CurrentTransactionState
4011
4016
* if it has a local pointer to it after calling this function.
4012
- *
4013
- * isTopLevel means that this CommitSubTransaction() is being issued as a
4014
- * sequence of actions leading directly to a main transaction commit
4015
- * allowing some actions to be optimised.
4016
4017
*/
4017
4018
static void
4018
- CommitSubTransaction (bool isTopLevel )
4019
+ CommitSubTransaction (void )
4019
4020
{
4020
4021
TransactionState s = CurrentTransactionState ;
4021
4022
@@ -4069,14 +4070,10 @@ CommitSubTransaction(bool isTopLevel)
4069
4070
4070
4071
/*
4071
4072
* Other locks should get transferred to their parent resource owner.
4072
- * Doing that is an O(N^2) operation, so if isTopLevel then we can just
4073
- * leave the lock records as they are, knowing they will all get released
4074
- * by the top level commit using ProcReleaseLocks(). We only optimize
4075
- * this for commit; aborts may need to do other cleanup.
4076
4073
*/
4077
4074
ResourceOwnerRelease (s -> curTransactionOwner ,
4078
4075
RESOURCE_RELEASE_LOCKS ,
4079
- true, isTopLevel );
4076
+ true, false );
4080
4077
ResourceOwnerRelease (s -> curTransactionOwner ,
4081
4078
RESOURCE_RELEASE_AFTER_LOCKS ,
4082
4079
true, false);
0 commit comments