mirror of https://github.com/postgres/postgres
Invert logic in pg_exec_query_string() so that we set a snapshot for
all utility statement types *except* a short list, per discussion a few days ago. Add missing SetQuerySnapshot calls in VACUUM and REINDEX, and guard against calling REINDEX DATABASE from a function (has same problem as VACUUM).
This commit is contained in:
parent
c1f91a38e2
commit
60992456ed
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.90 2002/09/23 00:42:48 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.91 2002/10/19 20:15:08 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -669,6 +669,10 @@ ReindexDatabase(const char *dbname, bool force, bool all)
|
||||||
if (IsTransactionBlock())
|
if (IsTransactionBlock())
|
||||||
elog(ERROR, "REINDEX DATABASE cannot run inside a BEGIN/END block");
|
elog(ERROR, "REINDEX DATABASE cannot run inside a BEGIN/END block");
|
||||||
|
|
||||||
|
/* Running this from a function would free the function context */
|
||||||
|
if (!MemoryContextContains(QueryContext, (void *) dbname))
|
||||||
|
elog(ERROR, "REINDEX DATABASE cannot be executed from a function");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a memory context that will survive forced transaction
|
* Create a memory context that will survive forced transaction
|
||||||
* commits we do below. Since it is a child of QueryContext, it will
|
* commits we do below. Since it is a child of QueryContext, it will
|
||||||
|
@ -724,6 +728,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
|
||||||
for (i = 0; i < relcnt; i++)
|
for (i = 0; i < relcnt; i++)
|
||||||
{
|
{
|
||||||
StartTransactionCommand(true);
|
StartTransactionCommand(true);
|
||||||
|
SetQuerySnapshot(); /* might be needed for functional index */
|
||||||
if (reindex_relation(relids[i], force))
|
if (reindex_relation(relids[i], force))
|
||||||
elog(NOTICE, "relation %u was reindexed", relids[i]);
|
elog(NOTICE, "relation %u was reindexed", relids[i]);
|
||||||
CommitTransactionCommand(true);
|
CommitTransactionCommand(true);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.241 2002/09/27 20:57:08 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.242 2002/10/19 20:15:09 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -306,7 +306,10 @@ vacuum(VacuumStmt *vacstmt)
|
||||||
* multiple tables).
|
* multiple tables).
|
||||||
*/
|
*/
|
||||||
if (vacstmt->vacuum)
|
if (vacstmt->vacuum)
|
||||||
|
{
|
||||||
StartTransactionCommand(true);
|
StartTransactionCommand(true);
|
||||||
|
SetQuerySnapshot(); /* might be needed for functional index */
|
||||||
|
}
|
||||||
else
|
else
|
||||||
old_context = MemoryContextSwitchTo(anl_context);
|
old_context = MemoryContextSwitchTo(anl_context);
|
||||||
|
|
||||||
|
@ -724,6 +727,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
|
||||||
|
|
||||||
/* Begin a transaction for vacuuming this relation */
|
/* Begin a transaction for vacuuming this relation */
|
||||||
StartTransactionCommand(true);
|
StartTransactionCommand(true);
|
||||||
|
SetQuerySnapshot(); /* might be needed for functional index */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for user-requested abort. Note we want this to be inside a
|
* Check for user-requested abort. Note we want this to be inside a
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.304 2002/10/18 22:05:35 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.305 2002/10/19 20:15:09 tgl Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* this is the "main" module of the postgres backend and
|
* this is the "main" module of the postgres backend and
|
||||||
|
@ -756,16 +756,30 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
|
||||||
|
|
||||||
elog(DEBUG2, "ProcessUtility");
|
elog(DEBUG2, "ProcessUtility");
|
||||||
|
|
||||||
/* set snapshot if utility stmt needs one */
|
/*
|
||||||
/* XXX maybe cleaner to list those that shouldn't set one? */
|
* Set snapshot if utility stmt needs one. Most reliable
|
||||||
if (IsA(utilityStmt, AlterTableStmt) ||
|
* way to do this seems to be to enumerate those that do not
|
||||||
IsA(utilityStmt, ClusterStmt) ||
|
* need one; this is a short list. Transaction control,
|
||||||
IsA(utilityStmt, CopyStmt) ||
|
* LOCK, and SET must *not* set a snapshot since they need
|
||||||
IsA(utilityStmt, ExecuteStmt) ||
|
* to be executable at the start of a serializable transaction
|
||||||
IsA(utilityStmt, ExplainStmt) ||
|
* without freezing a snapshot. By extension we allow SHOW
|
||||||
IsA(utilityStmt, IndexStmt) ||
|
* not to set a snapshot. The other stmts listed are just
|
||||||
IsA(utilityStmt, PrepareStmt) ||
|
* efficiency hacks. Beware of listing anything that can
|
||||||
IsA(utilityStmt, ReindexStmt))
|
* modify the database --- if, say, it has to update a
|
||||||
|
* functional index, then it had better have a snapshot.
|
||||||
|
*/
|
||||||
|
if (! (IsA(utilityStmt, TransactionStmt) ||
|
||||||
|
IsA(utilityStmt, LockStmt) ||
|
||||||
|
IsA(utilityStmt, VariableSetStmt) ||
|
||||||
|
IsA(utilityStmt, VariableShowStmt) ||
|
||||||
|
IsA(utilityStmt, VariableResetStmt) ||
|
||||||
|
IsA(utilityStmt, ConstraintsSetStmt) ||
|
||||||
|
/* efficiency hacks from here down */
|
||||||
|
IsA(utilityStmt, FetchStmt) ||
|
||||||
|
IsA(utilityStmt, ListenStmt) ||
|
||||||
|
IsA(utilityStmt, NotifyStmt) ||
|
||||||
|
IsA(utilityStmt, UnlistenStmt) ||
|
||||||
|
IsA(utilityStmt, CheckPointStmt)))
|
||||||
SetQuerySnapshot();
|
SetQuerySnapshot();
|
||||||
|
|
||||||
/* end transaction block if transaction or variable stmt */
|
/* end transaction block if transaction or variable stmt */
|
||||||
|
@ -1769,7 +1783,7 @@ PostgresMain(int argc, char *argv[], const char *username)
|
||||||
if (!IsUnderPostmaster)
|
if (!IsUnderPostmaster)
|
||||||
{
|
{
|
||||||
puts("\nPOSTGRES backend interactive interface ");
|
puts("\nPOSTGRES backend interactive interface ");
|
||||||
puts("$Revision: 1.304 $ $Date: 2002/10/18 22:05:35 $\n");
|
puts("$Revision: 1.305 $ $Date: 2002/10/19 20:15:09 $\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue