|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.542 2008/01/26 19:55:08 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.542.2.1 2008/03/12 23:58:35 tgl Exp $ |
12 | 12 | *
|
13 | 13 | * NOTES
|
14 | 14 | * this is the "main" module of the postgres backend and
|
@@ -729,31 +729,49 @@ List *
|
729 | 729 | pg_plan_queries(List *querytrees, int cursorOptions, ParamListInfo boundParams,
|
730 | 730 | bool needSnapshot)
|
731 | 731 | {
|
732 |
| - List *stmt_list = NIL; |
733 |
| - ListCell *query_list; |
| 732 | + List * volatile stmt_list = NIL; |
| 733 | + Snapshot saveActiveSnapshot = ActiveSnapshot; |
734 | 734 |
|
735 |
| - foreach(query_list, querytrees) |
| 735 | + /* PG_TRY to ensure previous ActiveSnapshot is restored on error */ |
| 736 | + PG_TRY(); |
736 | 737 | {
|
737 |
| - Query *query = (Query *) lfirst(query_list); |
738 |
| - Node *stmt; |
| 738 | + Snapshot mySnapshot = NULL; |
| 739 | + ListCell *query_list; |
739 | 740 |
|
740 |
| - if (query->commandType == CMD_UTILITY) |
| 741 | + foreach(query_list, querytrees) |
741 | 742 | {
|
742 |
| - /* Utility commands have no plans. */ |
743 |
| - stmt = query->utilityStmt; |
744 |
| - } |
745 |
| - else |
746 |
| - { |
747 |
| - if (needSnapshot) |
| 743 | + Query *query = (Query *) lfirst(query_list); |
| 744 | + Node *stmt; |
| 745 | + |
| 746 | + if (query->commandType == CMD_UTILITY) |
| 747 | + { |
| 748 | + /* Utility commands have no plans. */ |
| 749 | + stmt = query->utilityStmt; |
| 750 | + } |
| 751 | + else |
748 | 752 | {
|
749 |
| - ActiveSnapshot = CopySnapshot(GetTransactionSnapshot()); |
750 |
| - needSnapshot = false; |
| 753 | + if (needSnapshot && mySnapshot == NULL) |
| 754 | + { |
| 755 | + mySnapshot = CopySnapshot(GetTransactionSnapshot()); |
| 756 | + ActiveSnapshot = mySnapshot; |
| 757 | + } |
| 758 | + stmt = (Node *) pg_plan_query(query, cursorOptions, |
| 759 | + boundParams); |
751 | 760 | }
|
752 |
| - stmt = (Node *) pg_plan_query(query, cursorOptions, boundParams); |
| 761 | + |
| 762 | + stmt_list = lappend(stmt_list, stmt); |
753 | 763 | }
|
754 | 764 |
|
755 |
| - stmt_list = lappend(stmt_list, stmt); |
| 765 | + if (mySnapshot) |
| 766 | + FreeSnapshot(mySnapshot); |
| 767 | + } |
| 768 | + PG_CATCH(); |
| 769 | + { |
| 770 | + ActiveSnapshot = saveActiveSnapshot; |
| 771 | + PG_RE_THROW(); |
756 | 772 | }
|
| 773 | + PG_END_TRY(); |
| 774 | + ActiveSnapshot = saveActiveSnapshot; |
757 | 775 |
|
758 | 776 | return stmt_list;
|
759 | 777 | }
|
|
0 commit comments