why do we need two snapshots per query?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: why do we need two snapshots per query?
Date: 2011-11-11 14:07:33
Message-ID: CA+TgmoYqKRj9BozjB-+tLQgVkSvzPFWBEzRF4PM2xjPOsmFRdw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I noticed while playing around this morning that, in read committed
mode, the following query - or any other straightforward query - calls
GetSnapshotData() twice:

SELECT 1;

What happens is this:

exec_simple_query() calls analyze_requires_snapshot() on the query.
Since the query is a SELECT, this returns true, whereupon
exec_simple_query() takes a snapshot for parse analysis / planning. It
then plans the query and releases the snapshot. exec_simple_query()
then calls CreatePortal(), PortalDefineQuery(), and PortalStart(), the
last of which takes a new snapshot to run the query.

Considering that GetSnapshotData() is the number-one consumer of CPU
time on many profiling runs I've done, this seems needlessly
inefficient. Can't we arrange to retain the snapshot used for parse
analysis / planning and reuse it for the portal that we create just
afterwards? Off the top of my head, I'm not exactly sure how to do
that cleanly, but it seems like it should work.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2011-11-11 14:39:47 Re: type privileges and default privileges
Previous Message Robert Haas 2011-11-11 13:40:10 Re: type privileges and default privileges