Multiple call of GetTransactionSnapshot in single flow

Started by Rajeev rastogiabout 11 years ago2 messages
#1Rajeev rastogi
rajeev.rastogi@huawei.com

I have observed in some places like exec_bind_message and exec_simple_query,
Though these two function have already got snapshot but before they call function PortalStart,
current snapshot gets popped off and then they pass InvalidSnapshot as parameter
because of which inside PortalStart again snapshot is taken.

In cases where many transactions are running, taking snapshot multiple times may be very costly.

What is the reason for taking snapshot multiple time:

1. Is this implementation to make sure snapshot is at more granular level ?

2. Is it something do with current command id of the snapshot?

3. Or there is any other specific reason for this, which I am not able visualize?

4. Or am I missing something else?

If it is just reason 1, then maybe we can try to pass the same snapshot to PortalStart as taken in caller, it can enhance the performance in many case.
With this change, I did one small performance test on pgbench with "prepared queries for pgbench select with 16 users and observed performance benefit of 10%".

Please provide your opinion?

Thanks and Regards,
Kumar Rajeev Rastogi

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rajeev rastogi (#1)
Re: Multiple call of GetTransactionSnapshot in single flow

Rajeev rastogi <rajeev.rastogi@huawei.com> writes:

What is the reason for taking snapshot multiple time:

To get the right answer. I believe Robert Haas has been down this rabbit
hole most recently before you: see commits d573e239f and 532994299.
The execution snapshot has to be (at minimum) later than acquisition of
all table locks for the query, and that means it'd better be different
from the snapshot used for parse/plan activities.

The right solution here is not so much to reduce the number of snapshots
as to make them cheaper. Heikki was working on something for that,
but I'm not sure where he is with that patch.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers