Subject: [PATCH v1] Remove useless savepoint level

From: Japin Li <[email-masked]>
Date: Mon, 24 Oct 2022 14:54:03 +0800

---
 src/backend/access/transam/xact.c | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index fd5103a78e..e8a90a3a30 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -190,7 +190,6 @@ typedef struct TransactionStateData
 	FullTransactionId fullTransactionId;	/* my FullTransactionId */
 	SubTransactionId subTransactionId;	/* my subxact ID */
 	char	   *name;			/* savepoint name, if any */
-	int			savepointLevel; /* savepoint level */
 	TransState	state;			/* low-level state */
 	TBlockState blockState;		/* high-level state */
 	int			nestingLevel;	/* transaction nesting depth */
@@ -3234,12 +3233,10 @@ CommitTransactionCommand(void)
 		case TBLOCK_SUBRESTART:
 			{
 				char	   *name;
-				int			savepointLevel;
 
 				/* save name and keep Cleanup from freeing it */
 				name = s->name;
 				s->name = NULL;
-				savepointLevel = s->savepointLevel;
 
 				AbortSubTransaction();
 				CleanupSubTransaction();
@@ -3247,7 +3244,6 @@ CommitTransactionCommand(void)
 				DefineSavepoint(NULL);
 				s = CurrentTransactionState;	/* changed by push */
 				s->name = name;
-				s->savepointLevel = savepointLevel;
 
 				/* This is the same as TBLOCK_SUBBEGIN case */
 				AssertState(s->blockState == TBLOCK_SUBBEGIN);
@@ -3263,19 +3259,16 @@ CommitTransactionCommand(void)
 		case TBLOCK_SUBABORT_RESTART:
 			{
 				char	   *name;
-				int			savepointLevel;
 
 				/* save name and keep Cleanup from freeing it */
 				name = s->name;
 				s->name = NULL;
-				savepointLevel = s->savepointLevel;
 
 				CleanupSubTransaction();
 
 				DefineSavepoint(NULL);
 				s = CurrentTransactionState;	/* changed by push */
 				s->name = name;
-				s->savepointLevel = savepointLevel;
 
 				/* This is the same as TBLOCK_SUBBEGIN case */
 				AssertState(s->blockState == TBLOCK_SUBBEGIN);
@@ -4352,11 +4345,6 @@ ReleaseSavepoint(const char *name)
 				(errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
 				 errmsg("savepoint \"%s\" does not exist", name)));
 
-	/* disallow crossing savepoint level boundaries */
-	if (target->savepointLevel != s->savepointLevel)
-		ereport(ERROR,
-				(errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
-				 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
 
 	/*
 	 * Mark "commit pending" all subtransactions up to the target
@@ -4461,11 +4449,6 @@ RollbackToSavepoint(const char *name)
 				(errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
 				 errmsg("savepoint \"%s\" does not exist", name)));
 
-	/* disallow crossing savepoint level boundaries */
-	if (target->savepointLevel != s->savepointLevel)
-		ereport(ERROR,
-				(errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
-				 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
 
 	/*
 	 * Mark "abort pending" all subtransactions up to the target
@@ -5253,7 +5236,6 @@ PushTransaction(void)
 	s->parent = p;
 	s->nestingLevel = p->nestingLevel + 1;
 	s->gucNestLevel = NewGUCNestLevel();
-	s->savepointLevel = p->savepointLevel;
 	s->state = TRANS_DEFAULT;
 	s->blockState = TBLOCK_SUBBEGIN;
 	GetUserIdAndSecContext(&s->prevUser, &s->prevSecContext);
-- 
2.25.1

--=-=-=--