Skip to content

Commit 56ece37

Browse files
committed
Move responsibility for setting QuerySnapshot for utility statements
into postgres.c; make sure it happens for all cases that seem to need it. Perhaps it would be better to explicitly exclude just a few utility statement types from setting a snapshot?
1 parent 5fc32fb commit 56ece37

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

src/backend/tcop/postgres.c

Lines changed: 30 additions & 8 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.298 2002/10/06 03:56:03 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.299 2002/10/08 17:17:19 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -716,20 +716,33 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
716716
/*
717717
* process utility functions (create, destroy, etc..)
718718
*/
719+
Node *utilityStmt = querytree->utilityStmt;
720+
719721
elog(DEBUG2, "ProcessUtility");
720722

723+
/* set snapshot if utility stmt needs one */
724+
/* XXX maybe cleaner to list those that shouldn't set one? */
725+
if (IsA(utilityStmt, AlterTableStmt) ||
726+
IsA(utilityStmt, ClusterStmt) ||
727+
IsA(utilityStmt, CopyStmt) ||
728+
IsA(utilityStmt, ExecuteStmt) ||
729+
IsA(utilityStmt, ExplainStmt) ||
730+
IsA(utilityStmt, IndexStmt) ||
731+
IsA(utilityStmt, PrepareStmt) ||
732+
IsA(utilityStmt, ReindexStmt))
733+
SetQuerySnapshot();
734+
721735
if (querytree->originalQuery)
722736
{
723737
/* utility statement can override default tag string */
724-
ProcessUtility(querytree->utilityStmt, dest,
725-
completionTag);
738+
ProcessUtility(utilityStmt, dest, completionTag);
726739
if (completionTag[0])
727740
commandTag = completionTag;
728741
}
729742
else
730743
{
731744
/* utility added by rewrite cannot override tag */
732-
ProcessUtility(querytree->utilityStmt, dest, NULL);
745+
ProcessUtility(utilityStmt, dest, NULL);
733746
}
734747
}
735748
else
@@ -739,14 +752,20 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
739752
*/
740753
Plan *plan;
741754

755+
/*
756+
* Initialize snapshot state for query. This has to
757+
* be done before running the planner, because it might
758+
* try to evaluate immutable or stable functions, which
759+
* in turn might run queries.
760+
*/
761+
SetQuerySnapshot();
762+
763+
/* Make the plan */
742764
plan = pg_plan_query(querytree);
743765

744766
/* if we got a cancel signal whilst planning, quit */
745767
CHECK_FOR_INTERRUPTS();
746768

747-
/* Initialize snapshot state for query */
748-
SetQuerySnapshot();
749-
750769
/*
751770
* execute the plan
752771
*/
@@ -1701,7 +1720,7 @@ PostgresMain(int argc, char *argv[], const char *username)
17011720
if (!IsUnderPostmaster)
17021721
{
17031722
puts("\nPOSTGRES backend interactive interface ");
1704-
puts("$Revision: 1.298 $ $Date: 2002/10/06 03:56:03 $\n");
1723+
puts("$Revision: 1.299 $ $Date: 2002/10/08 17:17:19 $\n");
17051724
}
17061725

17071726
/*
@@ -1886,6 +1905,9 @@ PostgresMain(int argc, char *argv[], const char *username)
18861905
/* start an xact for this function invocation */
18871906
start_xact_command();
18881907

1908+
/* assume it may need a snapshot */
1909+
SetQuerySnapshot();
1910+
18891911
if (HandleFunctionRequest() == EOF)
18901912
{
18911913
/* lost frontend connection during F message input */

src/backend/tcop/utility.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.178 2002/09/26 22:58:33 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.179 2002/10/08 17:17:19 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -380,14 +380,7 @@ ProcessUtility(Node *parsetree,
380380
break;
381381

382382
case T_CopyStmt:
383-
{
384-
CopyStmt *stmt = (CopyStmt *) parsetree;
385-
386-
if (!stmt->is_from)
387-
SetQuerySnapshot();
388-
389-
DoCopy(stmt);
390-
}
383+
DoCopy((CopyStmt *) parsetree);
391384
break;
392385

393386
case T_PrepareStmt:

src/backend/utils/time/tqual.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Portions Copyright (c) 1994, Regents of the University of California
1717
*
1818
* IDENTIFICATION
19-
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.60 2002/09/04 20:31:33 momjian Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.61 2002/10/08 17:17:19 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -977,8 +977,8 @@ CopyQuerySnapshot(void)
977977
{
978978
Snapshot snapshot;
979979

980-
if (QuerySnapshot == NULL) /* should be set already, but... */
981-
SetQuerySnapshot();
980+
if (QuerySnapshot == NULL) /* should be set beforehand */
981+
elog(ERROR, "CopyQuerySnapshot: no snapshot has been set");
982982

983983
snapshot = (Snapshot) palloc(sizeof(SnapshotData));
984984
memcpy(snapshot, QuerySnapshot, sizeof(SnapshotData));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy