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+
719721elog (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+
721735if (querytree -> originalQuery )
722736{
723737/* utility statement can override default tag string */
724- ProcessUtility (querytree -> utilityStmt ,dest ,
725- completionTag );
738+ ProcessUtility (utilityStmt ,dest ,completionTag );
726739if (completionTag [0 ])
727740commandTag = completionTag ;
728741}
729742else
730743{
731744/* utility added by rewrite cannot override tag */
732- ProcessUtility (querytree -> utilityStmt ,dest ,NULL );
745+ ProcessUtility (utilityStmt ,dest ,NULL );
733746}
734747}
735748else
@@ -739,14 +752,20 @@ pg_exec_query_string(StringInfo query_string,/* string to execute */
739752 */
740753Plan * 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 */
742764plan = pg_plan_query (querytree );
743765
744766/* if we got a cancel signal whilst planning, quit */
745767CHECK_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)
17011720if (!IsUnderPostmaster )
17021721{
17031722puts ("\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 */
18871906start_xact_command ();
18881907
1908+ /* assume it may need a snapshot */
1909+ SetQuerySnapshot ();
1910+
18891911if (HandleFunctionRequest ()== EOF )
18901912{
18911913/* lost frontend connection during F message input */