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>
This commit is contained in:
parent
04700b685f
commit
ec87efde8d
|
@ -3908,13 +3908,11 @@ DefineSavepoint(const char *name)
|
|||
* As above, we don't actually do anything here except change blockState.
|
||||
*/
|
||||
void
|
||||
ReleaseSavepoint(List *options)
|
||||
ReleaseSavepoint(const char *name)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
TransactionState target,
|
||||
xact;
|
||||
ListCell *cell;
|
||||
char *name = NULL;
|
||||
|
||||
/*
|
||||
* Workers synchronize transaction state at the beginning of each parallel
|
||||
|
@ -3978,16 +3976,6 @@ ReleaseSavepoint(List *options)
|
|||
break;
|
||||
}
|
||||
|
||||
foreach(cell, options)
|
||||
{
|
||||
DefElem *elem = lfirst(cell);
|
||||
|
||||
if (strcmp(elem->defname, "savepoint_name") == 0)
|
||||
name = strVal(elem->arg);
|
||||
}
|
||||
|
||||
Assert(PointerIsValid(name));
|
||||
|
||||
for (target = s; PointerIsValid(target); target = target->parent)
|
||||
{
|
||||
if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
|
||||
|
@ -4029,13 +4017,11 @@ ReleaseSavepoint(List *options)
|
|||
* As above, we don't actually do anything here except change blockState.
|
||||
*/
|
||||
void
|
||||
RollbackToSavepoint(List *options)
|
||||
RollbackToSavepoint(const char *name)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
TransactionState target,
|
||||
xact;
|
||||
ListCell *cell;
|
||||
char *name = NULL;
|
||||
|
||||
/*
|
||||
* Workers synchronize transaction state at the beginning of each parallel
|
||||
|
@ -4099,16 +4085,6 @@ RollbackToSavepoint(List *options)
|
|||
break;
|
||||
}
|
||||
|
||||
foreach(cell, options)
|
||||
{
|
||||
DefElem *elem = lfirst(cell);
|
||||
|
||||
if (strcmp(elem->defname, "savepoint_name") == 0)
|
||||
name = strVal(elem->arg);
|
||||
}
|
||||
|
||||
Assert(PointerIsValid(name));
|
||||
|
||||
for (target = s; PointerIsValid(target); target = target->parent)
|
||||
{
|
||||
if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
|
||||
|
|
|
@ -3602,6 +3602,7 @@ _copyTransactionStmt(const TransactionStmt *from)
|
|||
|
||||
COPY_SCALAR_FIELD(kind);
|
||||
COPY_NODE_FIELD(options);
|
||||
COPY_STRING_FIELD(savepoint_name);
|
||||
COPY_STRING_FIELD(gid);
|
||||
|
||||
return newnode;
|
||||
|
|
|
@ -1513,6 +1513,7 @@ _equalTransactionStmt(const TransactionStmt *a, const TransactionStmt *b)
|
|||
{
|
||||
COMPARE_SCALAR_FIELD(kind);
|
||||
COMPARE_NODE_FIELD(options);
|
||||
COMPARE_STRING_FIELD(savepoint_name);
|
||||
COMPARE_STRING_FIELD(gid);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -9876,40 +9876,35 @@ TransactionStmt:
|
|||
{
|
||||
TransactionStmt *n = makeNode(TransactionStmt);
|
||||
n->kind = TRANS_STMT_SAVEPOINT;
|
||||
n->options = list_make1(makeDefElem("savepoint_name",
|
||||
(Node *)makeString($2), @1));
|
||||
n->savepoint_name = $2;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| RELEASE SAVEPOINT ColId
|
||||
{
|
||||
TransactionStmt *n = makeNode(TransactionStmt);
|
||||
n->kind = TRANS_STMT_RELEASE;
|
||||
n->options = list_make1(makeDefElem("savepoint_name",
|
||||
(Node *)makeString($3), @1));
|
||||
n->savepoint_name = $3;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| RELEASE ColId
|
||||
{
|
||||
TransactionStmt *n = makeNode(TransactionStmt);
|
||||
n->kind = TRANS_STMT_RELEASE;
|
||||
n->options = list_make1(makeDefElem("savepoint_name",
|
||||
(Node *)makeString($2), @1));
|
||||
n->savepoint_name = $2;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| ROLLBACK opt_transaction TO SAVEPOINT ColId
|
||||
{
|
||||
TransactionStmt *n = makeNode(TransactionStmt);
|
||||
n->kind = TRANS_STMT_ROLLBACK_TO;
|
||||
n->options = list_make1(makeDefElem("savepoint_name",
|
||||
(Node *)makeString($5), @1));
|
||||
n->savepoint_name = $5;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| ROLLBACK opt_transaction TO ColId
|
||||
{
|
||||
TransactionStmt *n = makeNode(TransactionStmt);
|
||||
n->kind = TRANS_STMT_ROLLBACK_TO;
|
||||
n->options = list_make1(makeDefElem("savepoint_name",
|
||||
(Node *)makeString($4), @1));
|
||||
n->savepoint_name = $4;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| PREPARE TRANSACTION Sconst
|
||||
|
|
|
@ -469,34 +469,18 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
|||
break;
|
||||
|
||||
case TRANS_STMT_SAVEPOINT:
|
||||
{
|
||||
ListCell *cell;
|
||||
char *name = NULL;
|
||||
|
||||
RequireTransactionBlock(isTopLevel, "SAVEPOINT");
|
||||
|
||||
foreach(cell, stmt->options)
|
||||
{
|
||||
DefElem *elem = lfirst(cell);
|
||||
|
||||
if (strcmp(elem->defname, "savepoint_name") == 0)
|
||||
name = strVal(elem->arg);
|
||||
}
|
||||
|
||||
Assert(PointerIsValid(name));
|
||||
|
||||
DefineSavepoint(name);
|
||||
}
|
||||
DefineSavepoint(stmt->savepoint_name);
|
||||
break;
|
||||
|
||||
case TRANS_STMT_RELEASE:
|
||||
RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
|
||||
ReleaseSavepoint(stmt->options);
|
||||
ReleaseSavepoint(stmt->savepoint_name);
|
||||
break;
|
||||
|
||||
case TRANS_STMT_ROLLBACK_TO:
|
||||
RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
|
||||
RollbackToSavepoint(stmt->options);
|
||||
RollbackToSavepoint(stmt->savepoint_name);
|
||||
|
||||
/*
|
||||
* CommitTransactionCommand is in charge of
|
||||
|
|
|
@ -354,9 +354,9 @@ extern bool PrepareTransactionBlock(const char *gid);
|
|||
extern void UserAbortTransactionBlock(void);
|
||||
extern void BeginImplicitTransactionBlock(void);
|
||||
extern void EndImplicitTransactionBlock(void);
|
||||
extern void ReleaseSavepoint(List *options);
|
||||
extern void ReleaseSavepoint(const char *name);
|
||||
extern void DefineSavepoint(const char *name);
|
||||
extern void RollbackToSavepoint(List *options);
|
||||
extern void RollbackToSavepoint(const char *name);
|
||||
extern void BeginInternalSubTransaction(const char *name);
|
||||
extern void ReleaseCurrentSubTransaction(void);
|
||||
extern void RollbackAndReleaseCurrentSubTransaction(void);
|
||||
|
|
|
@ -2966,7 +2966,8 @@ typedef struct TransactionStmt
|
|||
{
|
||||
NodeTag type;
|
||||
TransactionStmtKind kind; /* see above */
|
||||
List *options; /* for BEGIN/START and savepoint commands */
|
||||
List *options; /* for BEGIN/START commands */
|
||||
char *savepoint_name; /* for savepoint commands */
|
||||
char *gid; /* for two-phase-commit related commands */
|
||||
} TransactionStmt;
|
||||
|
||||
|
|
Loading…
Reference in New Issue