Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6099245

Browse files
committed
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).
1 parent c1f91a3 commit 6099245

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

src/backend/commands/indexcmds.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.90 2002/09/23 00:42:48 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.91 2002/10/19 20:15:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -669,6 +669,10 @@ ReindexDatabase(const char *dbname, bool force, bool all)
669669
if (IsTransactionBlock())
670670
elog(ERROR, "REINDEX DATABASE cannot run inside a BEGIN/END block");
671671

672+
/* Running this from a function would free the function context */
673+
if (!MemoryContextContains(QueryContext, (void *) dbname))
674+
elog(ERROR, "REINDEX DATABASE cannot be executed from a function");
675+
672676
/*
673677
* Create a memory context that will survive forced transaction
674678
* 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)
724728
for (i = 0; i < relcnt; i++)
725729
{
726730
StartTransactionCommand(true);
731+
SetQuerySnapshot(); /* might be needed for functional index */
727732
if (reindex_relation(relids[i], force))
728733
elog(NOTICE, "relation %u was reindexed", relids[i]);
729734
CommitTransactionCommand(true);

src/backend/commands/vacuum.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.241 2002/09/27 20:57:08 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.242 2002/10/19 20:15:09 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -306,7 +306,10 @@ vacuum(VacuumStmt *vacstmt)
306306
* multiple tables).
307307
*/
308308
if (vacstmt->vacuum)
309+
{
309310
StartTransactionCommand(true);
311+
SetQuerySnapshot(); /* might be needed for functional index */
312+
}
310313
else
311314
old_context = MemoryContextSwitchTo(anl_context);
312315

@@ -724,6 +727,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
724727

725728
/* Begin a transaction for vacuuming this relation */
726729
StartTransactionCommand(true);
730+
SetQuerySnapshot(); /* might be needed for functional index */
727731

728732
/*
729733
* Check for user-requested abort. Note we want this to be inside a

src/backend/tcop/postgres.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.304 2002/10/18 22:05:35 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.305 2002/10/19 20:15:09 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -756,16 +756,30 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
756756

757757
elog(DEBUG2, "ProcessUtility");
758758

759-
/* set snapshot if utility stmt needs one */
760-
/* XXX maybe cleaner to list those that shouldn't set one? */
761-
if (IsA(utilityStmt, AlterTableStmt) ||
762-
IsA(utilityStmt, ClusterStmt) ||
763-
IsA(utilityStmt, CopyStmt) ||
764-
IsA(utilityStmt, ExecuteStmt) ||
765-
IsA(utilityStmt, ExplainStmt) ||
766-
IsA(utilityStmt, IndexStmt) ||
767-
IsA(utilityStmt, PrepareStmt) ||
768-
IsA(utilityStmt, ReindexStmt))
759+
/*
760+
* Set snapshot if utility stmt needs one. Most reliable
761+
* way to do this seems to be to enumerate those that do not
762+
* need one; this is a short list. Transaction control,
763+
* LOCK, and SET must *not* set a snapshot since they need
764+
* to be executable at the start of a serializable transaction
765+
* without freezing a snapshot. By extension we allow SHOW
766+
* not to set a snapshot. The other stmts listed are just
767+
* efficiency hacks. Beware of listing anything that can
768+
* modify the database --- if, say, it has to update a
769+
* functional index, then it had better have a snapshot.
770+
*/
771+
if (! (IsA(utilityStmt, TransactionStmt) ||
772+
IsA(utilityStmt, LockStmt) ||
773+
IsA(utilityStmt, VariableSetStmt) ||
774+
IsA(utilityStmt, VariableShowStmt) ||
775+
IsA(utilityStmt, VariableResetStmt) ||
776+
IsA(utilityStmt, ConstraintsSetStmt) ||
777+
/* efficiency hacks from here down */
778+
IsA(utilityStmt, FetchStmt) ||
779+
IsA(utilityStmt, ListenStmt) ||
780+
IsA(utilityStmt, NotifyStmt) ||
781+
IsA(utilityStmt, UnlistenStmt) ||
782+
IsA(utilityStmt, CheckPointStmt)))
769783
SetQuerySnapshot();
770784

771785
/* end transaction block if transaction or variable stmt */
@@ -1769,7 +1783,7 @@ PostgresMain(int argc, char *argv[], const char *username)
17691783
if (!IsUnderPostmaster)
17701784
{
17711785
puts("\nPOSTGRES backend interactive interface ");
1772-
puts("$Revision: 1.304 $ $Date: 2002/10/18 22:05:35 $\n");
1786+
puts("$Revision: 1.305 $ $Date: 2002/10/19 20:15:09 $\n");
17731787
}
17741788

17751789
/*

0 commit comments

Comments
 (0)