Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec87efd

Browse files
committed
Simplify parse representation of savepoint commands
Instead of embedding the savepoint name in a list and then requiringcomplex code to unpack it, just add another struct field to store itdirectly.Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
1 parent04700b6 commitec87efd

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(constchar*name)
39123912
{
39133913
TransactionStates=CurrentTransactionState;
39143914
TransactionStatetarget,
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(constchar*name)
40334021
{
40344022
TransactionStates=CurrentTransactionState;
40354023
TransactionStatetarget,
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
returnnewnode;

‎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
|RELEASESAVEPOINTColId
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
|RELEASEColId
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
|ROLLBACKopt_transactionTOSAVEPOINTColId
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
|ROLLBACKopt_transactionTOColId
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
|PREPARETRANSACTIONSconst

‎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
caseTRANS_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
caseTRANS_STMT_RELEASE:
493477
RequireTransactionBlock(isTopLevel,"RELEASE SAVEPOINT");
494-
ReleaseSavepoint(stmt->options);
478+
ReleaseSavepoint(stmt->savepoint_name);
495479
break;
496480

497481
caseTRANS_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
externvoidUserAbortTransactionBlock(void);
355355
externvoidBeginImplicitTransactionBlock(void);
356356
externvoidEndImplicitTransactionBlock(void);
357-
externvoidReleaseSavepoint(List*options);
357+
externvoidReleaseSavepoint(constchar*name);
358358
externvoidDefineSavepoint(constchar*name);
359-
externvoidRollbackToSavepoint(List*options);
359+
externvoidRollbackToSavepoint(constchar*name);
360360
externvoidBeginInternalSubTransaction(constchar*name);
361361
externvoidReleaseCurrentSubTransaction(void);
362362
externvoidRollbackAndReleaseCurrentSubTransaction(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
NodeTagtype;
29682968
TransactionStmtKindkind;/* 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)

[8]ページ先頭

©2009-2025 Movatter.jp