Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda6a707

Browse files
committed
Fix pg_plan_queries() to restore the previous setting of ActiveSnapshot
(probably NULL) before exiting. Up to now it's just left the variable as itset it, which means that after we're done processing the current clientmessage, ActiveSnapshot is probably pointing at garbage (because this functionis typically run in MessageContext which will get reset). There doesn't seemto have been any code path in which that mattered before 8.3, but now theplancache module might try to use the stale value if the next client messageis a Bind for a prepared statement that is in need of replanning. Per reportfrom Alex Hunsaker.
1 parent0d540b0 commitda6a707

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

‎src/backend/tcop/postgres.c

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.544 2008/03/10 12:55:13 mha Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.545 2008/03/12 23:58:27 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -730,31 +730,49 @@ List *
730730
pg_plan_queries(List*querytrees,intcursorOptions,ParamListInfoboundParams,
731731
boolneedSnapshot)
732732
{
733-
List*stmt_list=NIL;
734-
ListCell*query_list;
733+
List*volatilestmt_list=NIL;
734+
SnapshotsaveActiveSnapshot=ActiveSnapshot;
735735

736-
foreach(query_list,querytrees)
736+
/* PG_TRY to ensure previous ActiveSnapshot is restored on error */
737+
PG_TRY();
737738
{
738-
Query*query= (Query*)lfirst(query_list);
739-
Node*stmt;
739+
SnapshotmySnapshot=NULL;
740+
ListCell*query_list;
740741

741-
if (query->commandType==CMD_UTILITY)
742+
foreach(query_list,querytrees)
742743
{
743-
/* Utility commands have no plans. */
744-
stmt=query->utilityStmt;
745-
}
746-
else
747-
{
748-
if (needSnapshot)
744+
Query*query= (Query*)lfirst(query_list);
745+
Node*stmt;
746+
747+
if (query->commandType==CMD_UTILITY)
748+
{
749+
/* Utility commands have no plans. */
750+
stmt=query->utilityStmt;
751+
}
752+
else
749753
{
750-
ActiveSnapshot=CopySnapshot(GetTransactionSnapshot());
751-
needSnapshot= false;
754+
if (needSnapshot&&mySnapshot==NULL)
755+
{
756+
mySnapshot=CopySnapshot(GetTransactionSnapshot());
757+
ActiveSnapshot=mySnapshot;
758+
}
759+
stmt= (Node*)pg_plan_query(query,cursorOptions,
760+
boundParams);
752761
}
753-
stmt= (Node*)pg_plan_query(query,cursorOptions,boundParams);
762+
763+
stmt_list=lappend(stmt_list,stmt);
754764
}
755765

756-
stmt_list=lappend(stmt_list,stmt);
766+
if (mySnapshot)
767+
FreeSnapshot(mySnapshot);
768+
}
769+
PG_CATCH();
770+
{
771+
ActiveSnapshot=saveActiveSnapshot;
772+
PG_RE_THROW();
757773
}
774+
PG_END_TRY();
775+
ActiveSnapshot=saveActiveSnapshot;
758776

759777
returnstmt_list;
760778
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp