Rename TransactionChain functions
We call this thing a "transaction block" everywhere except in a few functions, where it is mysteriously called a "transaction chain". In the SQL standard, a transaction chain is something different. So rename these functions to match the common terminology. Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
This commit is contained in:
parent
8d47a90862
commit
04700b685f
@ -310,7 +310,7 @@ static void CallSubXactCallbacks(SubXactEvent event,
|
||||
SubTransactionId mySubid,
|
||||
SubTransactionId parentSubid);
|
||||
static void CleanupTransaction(void);
|
||||
static void CheckTransactionChain(bool isTopLevel, bool throwError,
|
||||
static void CheckTransactionBlock(bool isTopLevel, bool throwError,
|
||||
const char *stmtType);
|
||||
static void CommitTransaction(void);
|
||||
static TransactionId RecordTransactionAbort(bool isSubXact);
|
||||
@ -3134,7 +3134,7 @@ AbortCurrentTransaction(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* PreventTransactionChain
|
||||
* PreventInTransactionBlock
|
||||
*
|
||||
* This routine is to be called by statements that must not run inside
|
||||
* a transaction block, typically because they have non-rollback-able
|
||||
@ -3151,7 +3151,7 @@ AbortCurrentTransaction(void)
|
||||
* stmtType: statement type name, for error messages.
|
||||
*/
|
||||
void
|
||||
PreventTransactionChain(bool isTopLevel, const char *stmtType)
|
||||
PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
|
||||
{
|
||||
/*
|
||||
* xact block already started?
|
||||
@ -3190,8 +3190,8 @@ PreventTransactionChain(bool isTopLevel, const char *stmtType)
|
||||
}
|
||||
|
||||
/*
|
||||
* WarnNoTranactionChain
|
||||
* RequireTransactionChain
|
||||
* WarnNoTranactionBlock
|
||||
* RequireTransactionBlock
|
||||
*
|
||||
* These two functions allow for warnings or errors if a command is executed
|
||||
* outside of a transaction block. This is useful for commands that have no
|
||||
@ -3204,29 +3204,29 @@ PreventTransactionChain(bool isTopLevel, const char *stmtType)
|
||||
* If we appear to be running inside a user-defined function, we do not
|
||||
* issue anything, since the function could issue more commands that make
|
||||
* use of the current statement's results. Likewise subtransactions.
|
||||
* Thus these are inverses for PreventTransactionChain.
|
||||
* Thus these are inverses for PreventInTransactionBlock.
|
||||
*
|
||||
* isTopLevel: passed down from ProcessUtility to determine whether we are
|
||||
* inside a function.
|
||||
* stmtType: statement type name, for warning or error messages.
|
||||
*/
|
||||
void
|
||||
WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
|
||||
WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
|
||||
{
|
||||
CheckTransactionChain(isTopLevel, false, stmtType);
|
||||
CheckTransactionBlock(isTopLevel, false, stmtType);
|
||||
}
|
||||
|
||||
void
|
||||
RequireTransactionChain(bool isTopLevel, const char *stmtType)
|
||||
RequireTransactionBlock(bool isTopLevel, const char *stmtType)
|
||||
{
|
||||
CheckTransactionChain(isTopLevel, true, stmtType);
|
||||
CheckTransactionBlock(isTopLevel, true, stmtType);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the implementation of the above two.
|
||||
*/
|
||||
static void
|
||||
CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
|
||||
CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
|
||||
{
|
||||
/*
|
||||
* xact block already started?
|
||||
@ -3255,7 +3255,7 @@ CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
|
||||
}
|
||||
|
||||
/*
|
||||
* IsInTransactionChain
|
||||
* IsInTransactionBlock
|
||||
*
|
||||
* This routine is for statements that need to behave differently inside
|
||||
* a transaction block than when running as single commands. ANALYZE is
|
||||
@ -3265,10 +3265,10 @@ CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
|
||||
* inside a function.
|
||||
*/
|
||||
bool
|
||||
IsInTransactionChain(bool isTopLevel)
|
||||
IsInTransactionBlock(bool isTopLevel)
|
||||
{
|
||||
/*
|
||||
* Return true on same conditions that would make PreventTransactionChain
|
||||
* Return true on same conditions that would make PreventInTransactionBlock
|
||||
* error out
|
||||
*/
|
||||
if (IsTransactionBlock())
|
||||
|
@ -202,7 +202,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
|
||||
* We cannot run this form of CLUSTER inside a user transaction block;
|
||||
* we'd be holding locks way too long.
|
||||
*/
|
||||
PreventTransactionChain(isTopLevel, "CLUSTER");
|
||||
PreventInTransactionBlock(isTopLevel, "CLUSTER");
|
||||
|
||||
/*
|
||||
* Create special memory context for cross-transaction storage.
|
||||
|
@ -1476,7 +1476,7 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
dtablespace->defname),
|
||||
parser_errposition(pstate, dtablespace->location)));
|
||||
/* this case isn't allowed within a transaction block */
|
||||
PreventTransactionChain(isTopLevel, "ALTER DATABASE SET TABLESPACE");
|
||||
PreventInTransactionBlock(isTopLevel, "ALTER DATABASE SET TABLESPACE");
|
||||
movedb(stmt->dbname, defGetString(dtablespace));
|
||||
return InvalidOid;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ DiscardAll(bool isTopLevel)
|
||||
* DISCARD ALL inside a transaction block would leave the transaction
|
||||
* still uncommitted.
|
||||
*/
|
||||
PreventTransactionChain(isTopLevel, "DISCARD ALL");
|
||||
PreventInTransactionBlock(isTopLevel, "DISCARD ALL");
|
||||
|
||||
/* Closing portals might run user-defined code, so do that first. */
|
||||
PortalHashTableDeleteAll();
|
||||
|
@ -63,7 +63,7 @@ PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params,
|
||||
* user-visible effect).
|
||||
*/
|
||||
if (!(cstmt->options & CURSOR_OPT_HOLD))
|
||||
RequireTransactionChain(isTopLevel, "DECLARE CURSOR");
|
||||
RequireTransactionBlock(isTopLevel, "DECLARE CURSOR");
|
||||
|
||||
/*
|
||||
* Parse analysis was done already, but we still have to run the rule
|
||||
|
@ -339,7 +339,7 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
|
||||
* replication slot.
|
||||
*/
|
||||
if (create_slot)
|
||||
PreventTransactionChain(isTopLevel, "CREATE SUBSCRIPTION ... WITH (create_slot = true)");
|
||||
PreventInTransactionBlock(isTopLevel, "CREATE SUBSCRIPTION ... WITH (create_slot = true)");
|
||||
|
||||
if (!superuser())
|
||||
ereport(ERROR,
|
||||
@ -897,7 +897,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
|
||||
* don't have the proper facilities for that.
|
||||
*/
|
||||
if (slotname)
|
||||
PreventTransactionChain(isTopLevel, "DROP SUBSCRIPTION");
|
||||
PreventInTransactionBlock(isTopLevel, "DROP SUBSCRIPTION");
|
||||
|
||||
|
||||
ObjectAddressSet(myself, SubscriptionRelationId, subid);
|
||||
|
@ -1321,7 +1321,7 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
|
||||
!(tup->t_data->t_infomask & HEAP_UPDATED))
|
||||
/* safe to do inside transaction block */ ;
|
||||
else
|
||||
PreventTransactionChain(isTopLevel, "ALTER TYPE ... ADD");
|
||||
PreventInTransactionBlock(isTopLevel, "ALTER TYPE ... ADD");
|
||||
|
||||
AddEnumLabel(enum_type_oid, stmt->newVal,
|
||||
stmt->newValNeighbor, stmt->newValIsAfter,
|
||||
|
@ -186,11 +186,11 @@ vacuum(int options, List *relations, VacuumParams *params,
|
||||
*/
|
||||
if (options & VACOPT_VACUUM)
|
||||
{
|
||||
PreventTransactionChain(isTopLevel, stmttype);
|
||||
PreventInTransactionBlock(isTopLevel, stmttype);
|
||||
in_outer_xact = false;
|
||||
}
|
||||
else
|
||||
in_outer_xact = IsInTransactionChain(isTopLevel);
|
||||
in_outer_xact = IsInTransactionBlock(isTopLevel);
|
||||
|
||||
/*
|
||||
* Due to static variables vac_context, anl_context and vac_strategy,
|
||||
|
@ -1516,7 +1516,7 @@ exec_replication_command(const char *cmd_string)
|
||||
break;
|
||||
|
||||
case T_BaseBackupCmd:
|
||||
PreventTransactionChain(true, "BASE_BACKUP");
|
||||
PreventInTransactionBlock(true, "BASE_BACKUP");
|
||||
SendBaseBackup((BaseBackupCmd *) cmd_node);
|
||||
break;
|
||||
|
||||
@ -1532,7 +1532,7 @@ exec_replication_command(const char *cmd_string)
|
||||
{
|
||||
StartReplicationCmd *cmd = (StartReplicationCmd *) cmd_node;
|
||||
|
||||
PreventTransactionChain(true, "START_REPLICATION");
|
||||
PreventInTransactionBlock(true, "START_REPLICATION");
|
||||
|
||||
if (cmd->kind == REPLICATION_KIND_PHYSICAL)
|
||||
StartReplication(cmd);
|
||||
@ -1542,7 +1542,7 @@ exec_replication_command(const char *cmd_string)
|
||||
}
|
||||
|
||||
case T_TimeLineHistoryCmd:
|
||||
PreventTransactionChain(true, "TIMELINE_HISTORY");
|
||||
PreventInTransactionBlock(true, "TIMELINE_HISTORY");
|
||||
SendTimeLineHistory((TimeLineHistoryCmd *) cmd_node);
|
||||
break;
|
||||
|
||||
|
@ -453,13 +453,13 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
break;
|
||||
|
||||
case TRANS_STMT_COMMIT_PREPARED:
|
||||
PreventTransactionChain(isTopLevel, "COMMIT PREPARED");
|
||||
PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
|
||||
PreventCommandDuringRecovery("COMMIT PREPARED");
|
||||
FinishPreparedTransaction(stmt->gid, true);
|
||||
break;
|
||||
|
||||
case TRANS_STMT_ROLLBACK_PREPARED:
|
||||
PreventTransactionChain(isTopLevel, "ROLLBACK PREPARED");
|
||||
PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
|
||||
PreventCommandDuringRecovery("ROLLBACK PREPARED");
|
||||
FinishPreparedTransaction(stmt->gid, false);
|
||||
break;
|
||||
@ -473,7 +473,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
ListCell *cell;
|
||||
char *name = NULL;
|
||||
|
||||
RequireTransactionChain(isTopLevel, "SAVEPOINT");
|
||||
RequireTransactionBlock(isTopLevel, "SAVEPOINT");
|
||||
|
||||
foreach(cell, stmt->options)
|
||||
{
|
||||
@ -490,12 +490,12 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
break;
|
||||
|
||||
case TRANS_STMT_RELEASE:
|
||||
RequireTransactionChain(isTopLevel, "RELEASE SAVEPOINT");
|
||||
RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
|
||||
ReleaseSavepoint(stmt->options);
|
||||
break;
|
||||
|
||||
case TRANS_STMT_ROLLBACK_TO:
|
||||
RequireTransactionChain(isTopLevel, "ROLLBACK TO SAVEPOINT");
|
||||
RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
|
||||
RollbackToSavepoint(stmt->options);
|
||||
|
||||
/*
|
||||
@ -536,13 +536,13 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
|
||||
case T_CreateTableSpaceStmt:
|
||||
/* no event triggers for global objects */
|
||||
PreventTransactionChain(isTopLevel, "CREATE TABLESPACE");
|
||||
PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
|
||||
CreateTableSpace((CreateTableSpaceStmt *) parsetree);
|
||||
break;
|
||||
|
||||
case T_DropTableSpaceStmt:
|
||||
/* no event triggers for global objects */
|
||||
PreventTransactionChain(isTopLevel, "DROP TABLESPACE");
|
||||
PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
|
||||
DropTableSpace((DropTableSpaceStmt *) parsetree);
|
||||
break;
|
||||
|
||||
@ -592,7 +592,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
|
||||
case T_CreatedbStmt:
|
||||
/* no event triggers for global objects */
|
||||
PreventTransactionChain(isTopLevel, "CREATE DATABASE");
|
||||
PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
|
||||
createdb(pstate, (CreatedbStmt *) parsetree);
|
||||
break;
|
||||
|
||||
@ -611,7 +611,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
DropdbStmt *stmt = (DropdbStmt *) parsetree;
|
||||
|
||||
/* no event triggers for global objects */
|
||||
PreventTransactionChain(isTopLevel, "DROP DATABASE");
|
||||
PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
|
||||
dropdb(stmt->dbname, stmt->missing_ok);
|
||||
}
|
||||
break;
|
||||
@ -690,7 +690,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
break;
|
||||
|
||||
case T_AlterSystemStmt:
|
||||
PreventTransactionChain(isTopLevel, "ALTER SYSTEM");
|
||||
PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
|
||||
AlterSystemSetConfigFile((AlterSystemStmt *) parsetree);
|
||||
break;
|
||||
|
||||
@ -756,13 +756,13 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
* Since the lock would just get dropped immediately, LOCK TABLE
|
||||
* outside a transaction block is presumed to be user error.
|
||||
*/
|
||||
RequireTransactionChain(isTopLevel, "LOCK TABLE");
|
||||
RequireTransactionBlock(isTopLevel, "LOCK TABLE");
|
||||
/* forbidden in parallel mode due to CommandIsReadOnly */
|
||||
LockTableCommand((LockStmt *) parsetree);
|
||||
break;
|
||||
|
||||
case T_ConstraintsSetStmt:
|
||||
WarnNoTransactionChain(isTopLevel, "SET CONSTRAINTS");
|
||||
WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
|
||||
AfterTriggerSetState((ConstraintsSetStmt *) parsetree);
|
||||
break;
|
||||
|
||||
@ -808,7 +808,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
|
||||
* start-transaction-command calls would not have the
|
||||
* intended effect!
|
||||
*/
|
||||
PreventTransactionChain(isTopLevel,
|
||||
PreventInTransactionBlock(isTopLevel,
|
||||
(stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
|
||||
(stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
|
||||
"REINDEX DATABASE");
|
||||
@ -1307,7 +1307,7 @@ ProcessUtilitySlow(ParseState *pstate,
|
||||
List *inheritors = NIL;
|
||||
|
||||
if (stmt->concurrent)
|
||||
PreventTransactionChain(isTopLevel,
|
||||
PreventInTransactionBlock(isTopLevel,
|
||||
"CREATE INDEX CONCURRENTLY");
|
||||
|
||||
/*
|
||||
@ -1715,7 +1715,7 @@ ExecDropStmt(DropStmt *stmt, bool isTopLevel)
|
||||
{
|
||||
case OBJECT_INDEX:
|
||||
if (stmt->concurrent)
|
||||
PreventTransactionChain(isTopLevel,
|
||||
PreventInTransactionBlock(isTopLevel,
|
||||
"DROP INDEX CONCURRENTLY");
|
||||
/* fall through */
|
||||
|
||||
|
@ -7348,7 +7348,7 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
|
||||
case VAR_SET_VALUE:
|
||||
case VAR_SET_CURRENT:
|
||||
if (stmt->is_local)
|
||||
WarnNoTransactionChain(isTopLevel, "SET LOCAL");
|
||||
WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
|
||||
(void) set_config_option(stmt->name,
|
||||
ExtractSetVariableArgs(stmt),
|
||||
(superuser() ? PGC_SUSET : PGC_USERSET),
|
||||
@ -7368,7 +7368,7 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
|
||||
{
|
||||
ListCell *head;
|
||||
|
||||
WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
|
||||
WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
|
||||
|
||||
foreach(head, stmt->args)
|
||||
{
|
||||
@ -7419,7 +7419,7 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
|
||||
|
||||
WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
|
||||
WarnNoTransactionBlock(isTopLevel, "SET TRANSACTION");
|
||||
Assert(nodeTag(&con->val) == T_String);
|
||||
ImportSnapshot(strVal(&con->val));
|
||||
}
|
||||
@ -7429,11 +7429,11 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
|
||||
break;
|
||||
case VAR_SET_DEFAULT:
|
||||
if (stmt->is_local)
|
||||
WarnNoTransactionChain(isTopLevel, "SET LOCAL");
|
||||
WarnNoTransactionBlock(isTopLevel, "SET LOCAL");
|
||||
/* fall through */
|
||||
case VAR_RESET:
|
||||
if (strcmp(stmt->name, "transaction_isolation") == 0)
|
||||
WarnNoTransactionChain(isTopLevel, "RESET TRANSACTION");
|
||||
WarnNoTransactionBlock(isTopLevel, "RESET TRANSACTION");
|
||||
|
||||
(void) set_config_option(stmt->name,
|
||||
NULL,
|
||||
|
@ -1171,7 +1171,7 @@ ExportSnapshot(Snapshot snapshot)
|
||||
char pathtmp[MAXPGPATH];
|
||||
|
||||
/*
|
||||
* It's tempting to call RequireTransactionChain here, since it's not very
|
||||
* It's tempting to call RequireTransactionBlock here, since it's not very
|
||||
* useful to export a snapshot that will disappear immediately afterwards.
|
||||
* However, we haven't got enough information to do that, since we don't
|
||||
* know if we're at top level or not. For example, we could be inside a
|
||||
|
@ -2047,7 +2047,7 @@ command_no_begin(const char *query)
|
||||
|
||||
/*
|
||||
* Commands not allowed within transactions. The statements checked for
|
||||
* here should be exactly those that call PreventTransactionChain() in the
|
||||
* here should be exactly those that call PreventInTransactionBlock() in the
|
||||
* backend.
|
||||
*/
|
||||
if (wordlen == 6 && pg_strncasecmp(query, "vacuum", 6) == 0)
|
||||
|
@ -369,10 +369,10 @@ extern bool IsTransactionBlock(void);
|
||||
extern bool IsTransactionOrTransactionBlock(void);
|
||||
extern char TransactionBlockStatusCode(void);
|
||||
extern void AbortOutOfAnyTransaction(void);
|
||||
extern void PreventTransactionChain(bool isTopLevel, const char *stmtType);
|
||||
extern void RequireTransactionChain(bool isTopLevel, const char *stmtType);
|
||||
extern void WarnNoTransactionChain(bool isTopLevel, const char *stmtType);
|
||||
extern bool IsInTransactionChain(bool isTopLevel);
|
||||
extern void PreventInTransactionBlock(bool isTopLevel, const char *stmtType);
|
||||
extern void RequireTransactionBlock(bool isTopLevel, const char *stmtType);
|
||||
extern void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType);
|
||||
extern bool IsInTransactionBlock(bool isTopLevel);
|
||||
extern void RegisterXactCallback(XactCallback callback, void *arg);
|
||||
extern void UnregisterXactCallback(XactCallback callback, void *arg);
|
||||
extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user