why do we need two snapshots per query? - Mailing list pgsql-hackers

From Robert Haas
Subject why do we need two snapshots per query?
Date
Msg-id CA+TgmoYqKRj9BozjB-+tLQgVkSvzPFWBEzRF4PM2xjPOsmFRdw@mail.gmail.com
Whole thread Raw
Responses Re: why do we need two snapshots per query?
Re: why do we need two snapshots per query?
List 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


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: type privileges and default privileges
Next
From: Stephen Frost
Date:
Subject: Re: type privileges and default privileges