1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-15 03:41:20 +03:00

Backend support for autocommit removed, per recent discussions. The

only remnant of this failed experiment is that the server will take
SET AUTOCOMMIT TO ON.  Still TODO: provide some client-side autocommit
logic in libpq.
This commit is contained in:
Tom Lane
2003-05-14 03:26:03 +00:00
parent d9b679c13a
commit f85f43dfb5
99 changed files with 277 additions and 536 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.147 2003/05/02 20:54:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.148 2003/05/14 03:26:00 tgl Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
@@ -212,15 +212,11 @@ int XactIsoLevel;
bool DefaultXactReadOnly = false;
bool XactReadOnly;
bool autocommit = true;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* number of concurrent xacts needed to
* sleep */
static bool suppressChain = false;
static void (*_RollbackFunc) (void *) = NULL;
static void *_RollbackData = NULL;
@@ -1125,23 +1121,12 @@ CleanupTransaction(void)
/*
* StartTransactionCommand
*
* preventChain, if true, forces autocommit behavior at the next
* CommitTransactionCommand call.
*/
void
StartTransactionCommand(bool preventChain)
StartTransactionCommand(void)
{
TransactionState s = CurrentTransactionState;
/*
* Remember if caller wants to prevent autocommit-off chaining. This
* is only allowed if not already in a transaction block.
*/
suppressChain = preventChain;
if (preventChain && s->blockState != TBLOCK_DEFAULT)
elog(ERROR, "StartTransactionCommand: can't prevent chain");
switch (s->blockState)
{
/*
@@ -1217,44 +1202,20 @@ StartTransactionCommand(bool preventChain)
/*
* CommitTransactionCommand
*
* forceCommit = true forces autocommit behavior even when autocommit is off.
*/
void
CommitTransactionCommand(bool forceCommit)
CommitTransactionCommand(void)
{
TransactionState s = CurrentTransactionState;
switch (s->blockState)
{
/*
* If we aren't in a transaction block, and we are doing
* autocommit, just do our usual transaction commit. But if
* we aren't doing autocommit, start a transaction block
* automatically by switching to INPROGRESS state. (We handle
* this choice here, and not earlier, so that an explicit
* BEGIN issued in autocommit-off mode won't issue strange
* warnings.)
*
* Autocommit mode is forced by either a true forceCommit
* parameter to me, or a true preventChain parameter to the
* preceding StartTransactionCommand call, or a
* PreventTransactionChain call during the transaction.
* (The parameters could be omitted, but it turns out most
* callers of StartTransactionCommand/CommitTransactionCommand
* want to force autocommit, so making them all call
* PreventTransactionChain would just be extra notation.)
* If we aren't in a transaction block, just do our usual
* transaction commit.
*/
case TBLOCK_DEFAULT:
if (autocommit || forceCommit || suppressChain)
CommitTransaction();
else
{
BeginTransactionBlock();
Assert(s->blockState == TBLOCK_INPROGRESS);
/* This code must match the TBLOCK_INPROGRESS case below: */
CommandCounterIncrement();
}
CommitTransaction();
break;
/*
@@ -1323,10 +1284,7 @@ AbortCurrentTransaction(void)
*/
case TBLOCK_DEFAULT:
AbortTransaction();
if (autocommit || suppressChain)
CleanupTransaction();
else
s->blockState = TBLOCK_ABORT;
CleanupTransaction();
break;
/*
@@ -1396,9 +1354,7 @@ AbortCurrentTransaction(void)
* If we have already started a transaction block, issue an error; also issue
* an error if we appear to be running inside a user-defined function (which
* could issue more commands and possibly cause a failure after the statement
* completes). In autocommit-off mode, we allow the statement if a block is
* not already started, and force the statement to be autocommitted despite
* the mode.
* completes).
*
* stmtNode: pointer to parameter block for statement; this is used in
* a very klugy way to determine whether we are inside a function.
@@ -1428,14 +1384,7 @@ PreventTransactionChain(void *stmtNode, const char *stmtType)
/* If we got past IsTransactionBlock test, should be in default state */
if (CurrentTransactionState->blockState != TBLOCK_DEFAULT)
elog(ERROR, "PreventTransactionChain: can't prevent chain");
/* okay to set the flag */
suppressChain = true;
/* If we're in autocommit-off node, generate a notice */
if (!autocommit)
{
/* translator: %s represents an SQL statement name */
elog(NOTICE, "%s will be committed automatically", stmtType);
}
/* all okay */
}
/*
@@ -1470,12 +1419,6 @@ RequireTransactionChain(void *stmtNode, const char *stmtType)
*/
if (!MemoryContextContains(QueryContext, stmtNode))
return;
/*
* If we are in autocommit-off mode then it's okay, because this
* statement will itself start a transaction block.
*/
if (!autocommit && !suppressChain)
return;
/* translator: %s represents an SQL statement name */
elog(ERROR, "%s may only be used in begin/end transaction blocks",
stmtType);
@@ -1507,10 +1450,7 @@ BeginTransactionBlock(void)
s->blockState = TBLOCK_BEGIN;
/*
* do begin processing. NOTE: if you put anything here, check that it
* behaves properly in both autocommit-on and autocommit-off modes. In
* the latter case we will already have done some work in the new
* transaction.
* do begin processing here. Nothing to do at present.
*/
/*

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.55 2002/11/11 22:19:21 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.56 2003/05/14 03:26:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -55,7 +55,7 @@
static void
do_start()
{
StartTransactionCommand(true);
StartTransactionCommand();
elog(DEBUG3, "start transaction");
}
@@ -63,7 +63,7 @@ do_start()
static void
do_end()
{
CommitTransactionCommand(true);
CommitTransactionCommand();
elog(DEBUG3, "commit transaction");
if (isatty(0))
{

View File

@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.156 2003/05/08 14:49:03 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.157 2003/05/14 03:26:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -479,7 +479,7 @@ BootstrapMain(int argc, char *argv[])
SetProcessingMode(BootstrapProcessing);
/* clean up processing */
StartTransactionCommand(true);
StartTransactionCommand();
cleanup();
/* not reached, here to make compiler happy */
@@ -851,7 +851,7 @@ cleanup()
}
if (boot_reldesc != NULL)
closerel(NULL);
CommitTransactionCommand(true);
CommitTransactionCommand();
proc_exit(Warnings);
}

View File

@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.50 2003/04/24 21:16:42 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.51 2003/05/14 03:26:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1711,11 +1711,11 @@ RemoveTempRelationsCallback(void)
{
/* Need to ensure we have a usable transaction. */
AbortOutOfAnyTransaction();
StartTransactionCommand(true);
StartTransactionCommand();
RemoveTempRelations(myTempNamespace);
CommitTransactionCommand(true);
CommitTransactionCommand();
}
}

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.93 2003/04/22 00:08:06 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.94 2003/05/14 03:26:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -399,9 +399,9 @@ Async_UnlistenOnExit(void)
*/
AbortOutOfAnyTransaction();
/* Now we can do the unlisten */
StartTransactionCommand(true);
StartTransactionCommand();
Async_UnlistenAll();
CommitTransactionCommand(true);
CommitTransactionCommand();
}
/*
@@ -769,7 +769,7 @@ ProcessIncomingNotify(void)
notifyInterruptOccurred = 0;
StartTransactionCommand(true);
StartTransactionCommand();
lRel = heap_openr(ListenerRelationName, AccessExclusiveLock);
tdesc = RelationGetDescr(lRel);
@@ -823,7 +823,7 @@ ProcessIncomingNotify(void)
*/
heap_close(lRel, NoLock);
CommitTransactionCommand(true);
CommitTransactionCommand();
/*
* Must flush the notify messages to ensure frontend gets them

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.108 2003/05/02 20:54:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.109 2003/05/14 03:26:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -205,7 +205,7 @@ cluster(ClusterStmt *stmt)
rvs = get_tables_to_cluster(cluster_context);
/* Commit to get out of starting transaction */
CommitTransactionCommand(true);
CommitTransactionCommand();
/* Ok, now that we've got them all, cluster them one by one */
foreach (rv, rvs)
@@ -213,14 +213,14 @@ cluster(ClusterStmt *stmt)
RelToCluster *rvtc = (RelToCluster *) lfirst(rv);
/* Start a new transaction for each relation. */
StartTransactionCommand(true);
StartTransactionCommand();
SetQuerySnapshot(); /* might be needed for functional index */
cluster_rel(rvtc, true);
CommitTransactionCommand(true);
CommitTransactionCommand();
}
/* Start a new transaction for the cleanup work. */
StartTransactionCommand(true);
StartTransactionCommand();
/* Clean up working storage */
MemoryContextDelete(cluster_context);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.98 2003/05/02 20:54:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.99 2003/05/14 03:26:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -769,17 +769,16 @@ ReindexDatabase(const char *dbname, bool force, bool all)
heap_close(relationRelation, AccessShareLock);
/* Now reindex each rel in a separate transaction */
CommitTransactionCommand(true);
CommitTransactionCommand();
for (i = 0; i < relcnt; i++)
{
StartTransactionCommand(true);
StartTransactionCommand();
SetQuerySnapshot(); /* might be needed for functional index */
if (reindex_relation(relids[i], force))
elog(NOTICE, "relation %u was reindexed", relids[i]);
CommitTransactionCommand(true);
CommitTransactionCommand();
}
/* Tell xact.c not to chain the upcoming commit */
StartTransactionCommand(true);
StartTransactionCommand();
MemoryContextDelete(private_context);
}

View File

@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.252 2003/05/02 20:54:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.253 2003/05/14 03:26:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -275,7 +275,7 @@ vacuum(VacuumStmt *vacstmt)
}
/* matches the StartTransaction in PostgresMain() */
CommitTransactionCommand(true);
CommitTransactionCommand();
}
/*
@@ -303,7 +303,7 @@ vacuum(VacuumStmt *vacstmt)
*/
if (vacstmt->vacuum)
{
StartTransactionCommand(true);
StartTransactionCommand();
SetQuerySnapshot(); /* might be needed for functional index */
}
else
@@ -312,7 +312,7 @@ vacuum(VacuumStmt *vacstmt)
analyze_rel(relid, vacstmt);
if (vacstmt->vacuum)
CommitTransactionCommand(true);
CommitTransactionCommand();
else
{
MemoryContextSwitchTo(old_context);
@@ -330,11 +330,9 @@ vacuum(VacuumStmt *vacstmt)
/*
* This matches the CommitTransaction waiting for us in
* PostgresMain(). We tell xact.c not to chain the upcoming
* commit, so that a VACUUM doesn't start a transaction block,
* even when autocommit is off.
* PostgresMain().
*/
StartTransactionCommand(true);
StartTransactionCommand();
/*
* If it was a database-wide VACUUM, print FSM usage statistics
@@ -729,7 +727,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
bool result;
/* Begin a transaction for vacuuming this relation */
StartTransactionCommand(true);
StartTransactionCommand();
SetQuerySnapshot(); /* might be needed for functional index */
/*
@@ -746,7 +744,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
ObjectIdGetDatum(relid),
0, 0, 0))
{
CommitTransactionCommand(true);
CommitTransactionCommand();
return true; /* okay 'cause no data there */
}
@@ -778,7 +776,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
elog(WARNING, "Skipping \"%s\" --- only table or database owner can VACUUM it",
RelationGetRelationName(onerel));
relation_close(onerel, lmode);
CommitTransactionCommand(true);
CommitTransactionCommand();
return false;
}
@@ -791,7 +789,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
elog(WARNING, "Skipping \"%s\" --- can not process indexes, views or special system tables",
RelationGetRelationName(onerel));
relation_close(onerel, lmode);
CommitTransactionCommand(true);
CommitTransactionCommand();
return false;
}
@@ -805,7 +803,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
if (isOtherTempNamespace(RelationGetNamespace(onerel)))
{
relation_close(onerel, lmode);
CommitTransactionCommand(true);
CommitTransactionCommand();
return true; /* assume no long-lived data in temp tables */
}
@@ -843,7 +841,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
/*
* Complete the transaction and free all temporary memory used.
*/
CommitTransactionCommand(true);
CommitTransactionCommand();
/*
* If the relation has a secondary toast rel, vacuum that too while we

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.343 2003/05/12 16:48:17 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.344 2003/05/14 03:26:01 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -85,8 +85,6 @@ sigjmp_buf Warn_restart;
bool Warn_restart_ready = false;
bool InError = false;
extern bool autocommit;
/*
* Flags for expensive function optimization -- JMH 3/9/92
*/
@@ -148,7 +146,7 @@ static int InteractiveBackend(StringInfo inBuf);
static int SocketBackend(StringInfo inBuf);
static int ReadCommand(StringInfo inBuf);
static void start_xact_command(void);
static void finish_xact_command(bool forceCommit);
static void finish_xact_command(void);
static void SigHupHandler(SIGNAL_ARGS);
static void FloatExceptionHandler(SIGNAL_ARGS);
@@ -861,20 +859,15 @@ exec_simple_query(const char *query_string)
PortalDrop(portal, false);
if (IsA(parsetree, TransactionStmt) ||
IsA(parsetree, VariableSetStmt) ||
IsA(parsetree, VariableShowStmt) ||
IsA(parsetree, VariableResetStmt))
if (IsA(parsetree, TransactionStmt))
{
/*
* If this was a transaction control statement or a variable
* set/show/reset statement, commit it. We will start a
* new xact command for the next command (if any).
* If this was a transaction control statement, commit it.
* We will start a new xact command for the next command (if any).
*/
finish_xact_command(true);
finish_xact_command();
}
else if (lnext(parsetree_item) == NIL || !autocommit)
else if (lnext(parsetree_item) == NIL)
{
/*
* If this is the last parsetree of the query string, close down
@@ -886,7 +879,7 @@ exec_simple_query(const char *query_string)
* historical Postgres behavior, we do not force a transaction
* boundary between queries appearing in a single query string.
*/
finish_xact_command(false);
finish_xact_command();
}
else
{
@@ -907,6 +900,11 @@ exec_simple_query(const char *query_string)
EndCommand(completionTag, dest);
} /* end loop over parsetrees */
/*
* Close down transaction statement, if one is open.
*/
finish_xact_command();
/*
* If there were no parsetrees, return EmptyQueryResponse message.
*/
@@ -915,11 +913,6 @@ exec_simple_query(const char *query_string)
QueryContext = NULL;
/*
* Close down transaction statement, if one is open.
*/
finish_xact_command(false);
/*
* Finish up monitoring.
*/
@@ -1531,7 +1524,7 @@ exec_execute_message(const char *portal_name, long max_rows)
* If this was a transaction control statement, commit it. We will
* start a new xact command for the next command (if any).
*/
finish_xact_command(true);
finish_xact_command();
}
else
{
@@ -1657,7 +1650,7 @@ start_xact_command(void)
if (!xact_started)
{
elog(DEBUG2, "StartTransactionCommand");
StartTransactionCommand(false);
StartTransactionCommand();
/* Set statement timeout running, if any */
if (StatementTimeout > 0)
@@ -1668,7 +1661,7 @@ start_xact_command(void)
}
static void
finish_xact_command(bool forceCommit)
finish_xact_command(void)
{
if (xact_started)
{
@@ -1681,7 +1674,7 @@ finish_xact_command(bool forceCommit)
/* Now commit the command */
elog(DEBUG2, "CommitTransactionCommand");
CommitTransactionCommand(forceCommit);
CommitTransactionCommand();
#ifdef SHOW_MEMORY_STATS
/* Print mem stats at each commit for leak tracking */
@@ -2532,7 +2525,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.343 $ $Date: 2003/05/12 16:48:17 $\n");
puts("$Revision: 1.344 $ $Date: 2003/05/14 03:26:01 $\n");
}
/*
@@ -2810,7 +2803,7 @@ PostgresMain(int argc, char *argv[], const char *username)
}
/* commit the function-invocation transaction */
finish_xact_command(false);
finish_xact_command();
send_rfq = true;
break;
@@ -2894,7 +2887,7 @@ PostgresMain(int argc, char *argv[], const char *username)
case 'S': /* sync */
pq_getmsgend(input_message);
finish_xact_command(false);
finish_xact_command();
send_rfq = true;
break;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.120 2003/04/25 19:45:08 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.121 2003/05/14 03:26:02 tgl Exp $
*
*
*-------------------------------------------------------------------------
@@ -334,7 +334,7 @@ InitPostgres(const char *dbname, const char *username)
/* start a new transaction here before access to db */
if (!bootstrap)
StartTransactionCommand(true);
StartTransactionCommand();
/*
* It's now possible to do real access to the system catalogs.
@@ -420,7 +420,7 @@ InitPostgres(const char *dbname, const char *username)
/* close the transaction we started above */
if (!bootstrap)
CommitTransactionCommand(true);
CommitTransactionCommand();
}
/*

View File

@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.123 2003/05/06 20:26:27 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.124 2003/05/14 03:26:02 tgl Exp $
*
*--------------------------------------------------------------------
*/
@@ -69,7 +69,6 @@ extern bool Log_connections;
extern int PreAuthDelay;
extern int AuthenticationTimeout;
extern int CheckPointTimeout;
extern bool autocommit;
extern int CommitDelay;
extern int CommitSiblings;
extern char *preload_libraries_string;
@@ -92,6 +91,7 @@ static const char *assign_min_error_statement(const char *newval, bool doit,
bool interactive);
static const char *assign_msglvl(int *var, const char *newval,
bool doit, bool interactive);
static bool assign_phony_autocommit(bool newval, bool doit, bool interactive);
/*
@@ -134,6 +134,7 @@ int client_min_messages = NOTICE;
static char *log_min_error_statement_str;
static char *log_min_messages_str;
static char *client_min_messages_str;
static bool phony_autocommit;
static double phony_random_seed;
static char *client_encoding_string;
static char *datestyle_string;
@@ -526,8 +527,12 @@ static struct config_bool
false, NULL, NULL
},
{
{"autocommit", PGC_USERSET}, &autocommit,
true, NULL, NULL
/*
* This var doesn't do anything; it's just here so that we won't
* choke on SET AUTOCOMMIT TO ON from 7.3-vintage clients.
*/
{"autocommit", PGC_USERSET, GUC_NO_SHOW_ALL}, &phony_autocommit,
true, assign_phony_autocommit, NULL
},
{
{"default_transaction_read_only", PGC_USERSET}, &DefaultXactReadOnly,
@@ -3429,6 +3434,18 @@ assign_msglvl(int *var, const char *newval, bool doit, bool interactive)
return newval; /* OK */
}
static bool
assign_phony_autocommit(bool newval, bool doit, bool interactive)
{
if (!newval)
{
if (doit && interactive)
elog(ERROR, "SET AUTOCOMMIT TO OFF is no longer supported");
return false;
}
return true;
}
#include "guc-file.c"

View File

@@ -198,7 +198,6 @@
#
# Misc
#
#autocommit = true
#dynamic_library_path = '$libdir'
#search_path = '$user,public' # schema names
#datestyle = 'iso, us'