Re: why do we need two snapshots per query?

From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Florian Pflug <fgp(at)phlo(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: why do we need two snapshots per query?
Date: 2011-11-26 19:50:46
Message-ID: m2ehwu7je1.fsf@2ndQuadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Sun, Nov 13, 2011 at 8:57 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> In the -M extended case, we take a snapshot from exec_parse_message(),
>> and the same two in the exec_bind_message() call that are taken in the
>> -M prepared case.  So reducing the prepared case from two snapshots to
>> one will reduce the extended case from three snapshots to two, thus
>> saving one snapshot per query regardless of how it's executed.

I like the idea and I think it's better semantics to use the same
snapshot for planning and executing in the simple query case.

I didn't try to reproduce the performance benefits seen by Robert here,
nor did I tried to double check to compilation warnings etc. I guess
that reviewing a commiter's patch allows for being not as thorough :)

> + /* Done with the snapshot used for parameter I/O and parsing/planning */
> + if (snapshot_set)
> + PopActiveSnapshot();

This comment needs adjusting.

> diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
> index 466727b..c41272b 100644
> --- a/src/backend/tcop/pquery.c
> +++ b/src/backend/tcop/pquery.c
> @@ -455,7 +455,7 @@ FetchStatementTargetList(Node *stmt)
> * tupdesc (if any) is known.
> */
> void
> -PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot)
> +PortalStart(Portal portal, ParamListInfo params, bool use_active_snapshot)

You need to be editing the comments for this function. To be specific
you didn't update this text:

* The caller can optionally pass a snapshot to be used; pass InvalidSnapshot
* for the normal behavior of setting a new snapshot. This parameter is
* presently ignored for non-PORTAL_ONE_SELECT portals (it's only intended
* to be used for cursors).

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Shulgin 2011-11-26 20:07:21 Re: Notes on implementing URI syntax for libpq
Previous Message Alexander Shulgin 2011-11-26 19:46:32 Re: Notes on implementing URI syntax for libpq