[PATCH] Comments related to "Take fewer snapshots" and "Revert patch for taking fewer snapshots"

Started by Michail Nikolaevalmost 6 years ago2 messages
#1Michail Nikolaev
michail.nikolaev@gmail.com
1 attachment(s)

Hello, hackers.

Yesterday I have noticed that in simple protocol mode snapshot is
taken twice - first time for parsing/analyze and later for execution.

I was thinking it is a great idea to reuse the same snapshot. After
some time (not short) I was able to find this thread from 2011 with
exactly same idea (of course after I already got few % of performance
in POC):

/messages/by-id/CA+TgmoYqKRj9BozjB-+tLQgVkSvzPFWBEzRF4PM2xjPOsmFRdw@mail.gmail.com

And it was even merged: "Take fewer snapshots" (
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=d573e239f03506920938bf0be56c868d9c3416da
)

But where is optimisation in the HEAD?

It absent because was reverted later in 2012 because of tricky reasons
( /messages/by-id/5075D8DF.6050500@fuzzy.cz
) in commit "Revert patch for taking fewer snapshots." (
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=532994299e2ff208a58376134fab75f5ae471e41
)

I think it is good idea to add few comments to code related to the
topic in order to safe time for a next guy.

Comments-only patch attached.

Thanks,
Michail.

Attachments:

comments.patchtext/plain; charset=US-ASCII; name=comments.patchDownload
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 0a6f80963b..81880ddbba 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -1155,7 +1155,13 @@ exec_simple_query(const char *query_string)
 		plantree_list = pg_plan_queries(querytree_list,
 										CURSOR_OPT_PARALLEL_OK, NULL);
 
-		/* Done with the snapshot used for parsing/planning */
+		/* Done with the snapshot used for parsing/planning.
+		 *
+		 * While it is looks promising to reuse snapshot for query execution (at least for simple protocol)
+		 * but unfortunately it caused execution to use a snapshot that had been acquired before
+		 * locking any of the tables mentioned in the query.
+		 * This created user-visible anomalies that were not present in any prior release.
+		 */
 		if (snapshot_set)
 			PopActiveSnapshot();
 
#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Michail Nikolaev (#1)
Re: [PATCH] Comments related to "Take fewer snapshots" and "Revert patch for taking fewer snapshots"

On 2020-Feb-10, Michail Nikolaev wrote:

I think it is good idea to add few comments to code related to the
topic in order to safe time for a next guy.

Applied, thanks.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services