Skip to content

Commit ec87efd

Browse files
committed
Simplify parse representation of savepoint commands
Instead of embedding the savepoint name in a list and then requiring complex code to unpack it, just add another struct field to store it directly. Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
1 parent 04700b6 commit ec87efd

File tree

7 files changed

+17
-59
lines changed

7 files changed

+17
-59
lines changed

src/backend/access/transam/xact.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,13 +3908,11 @@ DefineSavepoint(const char *name)
39083908
* As above, we don't actually do anything here except change blockState.
39093909
*/
39103910
void
3911-
ReleaseSavepoint(List *options)
3911+
ReleaseSavepoint(const char *name)
39123912
{
39133913
TransactionState s = CurrentTransactionState;
39143914
TransactionState target,
39153915
xact;
3916-
ListCell *cell;
3917-
char *name = NULL;
39183916

39193917
/*
39203918
* Workers synchronize transaction state at the beginning of each parallel
@@ -3978,16 +3976,6 @@ ReleaseSavepoint(List *options)
39783976
break;
39793977
}
39803978

3981-
foreach(cell, options)
3982-
{
3983-
DefElem *elem = lfirst(cell);
3984-
3985-
if (strcmp(elem->defname, "savepoint_name") == 0)
3986-
name = strVal(elem->arg);
3987-
}
3988-
3989-
Assert(PointerIsValid(name));
3990-
39913979
for (target = s; PointerIsValid(target); target = target->parent)
39923980
{
39933981
if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
@@ -4029,13 +4017,11 @@ ReleaseSavepoint(List *options)
40294017
* As above, we don't actually do anything here except change blockState.
40304018
*/
40314019
void
4032-
RollbackToSavepoint(List *options)
4020+
RollbackToSavepoint(const char *name)
40334021
{
40344022
TransactionState s = CurrentTransactionState;
40354023
TransactionState target,
40364024
xact;
4037-
ListCell *cell;
4038-
char *name = NULL;
40394025

40404026
/*
40414027
* Workers synchronize transaction state at the beginning of each parallel
@@ -4099,16 +4085,6 @@ RollbackToSavepoint(List *options)
40994085
break;
41004086
}
41014087

4102-
foreach(cell, options)
4103-
{
4104-
DefElem *elem = lfirst(cell);
4105-
4106-
if (strcmp(elem->defname, "savepoint_name") == 0)
4107-
name = strVal(elem->arg);
4108-
}
4109-
4110-
Assert(PointerIsValid(name));
4111-
41124088
for (target = s; PointerIsValid(target); target = target->parent)
41134089
{
41144090
if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)

src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,6 +3602,7 @@ _copyTransactionStmt(const TransactionStmt *from)
36023602

36033603
COPY_SCALAR_FIELD(kind);
36043604
COPY_NODE_FIELD(options);
3605+
COPY_STRING_FIELD(savepoint_name);
36053606
COPY_STRING_FIELD(gid);
36063607

36073608
return newnode;

src/backend/nodes/equalfuncs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ _equalTransactionStmt(const TransactionStmt *a, const TransactionStmt *b)
15131513
{
15141514
COMPARE_SCALAR_FIELD(kind);
15151515
COMPARE_NODE_FIELD(options);
1516+
COMPARE_STRING_FIELD(savepoint_name);
15161517
COMPARE_STRING_FIELD(gid);
15171518

15181519
return true;

src/backend/parser/gram.y

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9876,40 +9876,35 @@ TransactionStmt:
98769876
{
98779877
TransactionStmt *n = makeNode(TransactionStmt);
98789878
n->kind = TRANS_STMT_SAVEPOINT;
9879-
n->options = list_make1(makeDefElem("savepoint_name",
9880-
(Node *)makeString($2), @1));
9879+
n->savepoint_name = $2;
98819880
$$ = (Node *)n;
98829881
}
98839882
| RELEASE SAVEPOINT ColId
98849883
{
98859884
TransactionStmt *n = makeNode(TransactionStmt);
98869885
n->kind = TRANS_STMT_RELEASE;
9887-
n->options = list_make1(makeDefElem("savepoint_name",
9888-
(Node *)makeString($3), @1));
9886+
n->savepoint_name = $3;
98899887
$$ = (Node *)n;
98909888
}
98919889
| RELEASE ColId
98929890
{
98939891
TransactionStmt *n = makeNode(TransactionStmt);
98949892
n->kind = TRANS_STMT_RELEASE;
9895-
n->options = list_make1(makeDefElem("savepoint_name",
9896-
(Node *)makeString($2), @1));
9893+
n->savepoint_name = $2;
98979894
$$ = (Node *)n;
98989895
}
98999896
| ROLLBACK opt_transaction TO SAVEPOINT ColId
99009897
{
99019898
TransactionStmt *n = makeNode(TransactionStmt);
99029899
n->kind = TRANS_STMT_ROLLBACK_TO;
9903-
n->options = list_make1(makeDefElem("savepoint_name",
9904-
(Node *)makeString($5), @1));
9900+
n->savepoint_name = $5;
99059901
$$ = (Node *)n;
99069902
}
99079903
| ROLLBACK opt_transaction TO ColId
99089904
{
99099905
TransactionStmt *n = makeNode(TransactionStmt);
99109906
n->kind = TRANS_STMT_ROLLBACK_TO;
9911-
n->options = list_make1(makeDefElem("savepoint_name",
9912-
(Node *)makeString($4), @1));
9907+
n->savepoint_name = $4;
99139908
$$ = (Node *)n;
99149909
}
99159910
| PREPARE TRANSACTION Sconst

src/backend/tcop/utility.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -469,34 +469,18 @@ standard_ProcessUtility(PlannedStmt *pstmt,
469469
break;
470470

471471
case TRANS_STMT_SAVEPOINT:
472-
{
473-
ListCell *cell;
474-
char *name = NULL;
475-
476-
RequireTransactionBlock(isTopLevel, "SAVEPOINT");
477-
478-
foreach(cell, stmt->options)
479-
{
480-
DefElem *elem = lfirst(cell);
481-
482-
if (strcmp(elem->defname, "savepoint_name") == 0)
483-
name = strVal(elem->arg);
484-
}
485-
486-
Assert(PointerIsValid(name));
487-
488-
DefineSavepoint(name);
489-
}
472+
RequireTransactionBlock(isTopLevel, "SAVEPOINT");
473+
DefineSavepoint(stmt->savepoint_name);
490474
break;
491475

492476
case TRANS_STMT_RELEASE:
493477
RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
494-
ReleaseSavepoint(stmt->options);
478+
ReleaseSavepoint(stmt->savepoint_name);
495479
break;
496480

497481
case TRANS_STMT_ROLLBACK_TO:
498482
RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
499-
RollbackToSavepoint(stmt->options);
483+
RollbackToSavepoint(stmt->savepoint_name);
500484

501485
/*
502486
* CommitTransactionCommand is in charge of

src/include/access/xact.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ extern bool PrepareTransactionBlock(const char *gid);
354354
extern void UserAbortTransactionBlock(void);
355355
extern void BeginImplicitTransactionBlock(void);
356356
extern void EndImplicitTransactionBlock(void);
357-
extern void ReleaseSavepoint(List *options);
357+
extern void ReleaseSavepoint(const char *name);
358358
extern void DefineSavepoint(const char *name);
359-
extern void RollbackToSavepoint(List *options);
359+
extern void RollbackToSavepoint(const char *name);
360360
extern void BeginInternalSubTransaction(const char *name);
361361
extern void ReleaseCurrentSubTransaction(void);
362362
extern void RollbackAndReleaseCurrentSubTransaction(void);

src/include/nodes/parsenodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,8 @@ typedef struct TransactionStmt
29662966
{
29672967
NodeTag type;
29682968
TransactionStmtKind kind; /* see above */
2969-
List *options; /* for BEGIN/START and savepoint commands */
2969+
List *options; /* for BEGIN/START commands */
2970+
char *savepoint_name; /* for savepoint commands */
29702971
char *gid; /* for two-phase-commit related commands */
29712972
} TransactionStmt;
29722973

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy