Re: Could GetTransactionSnapshot be deferred till needed.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniel Wood <dwood(at)salesforce(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Could GetTransactionSnapshot be deferred till needed.
Date: 2013-04-25 04:50:33
Message-ID: 13447.1366865433@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Daniel Wood <dwood(at)salesforce(dot)com> writes:
> Just as a permanent XID is allocate only when needed, is there any way
> to defer the acquisition of a snapshot till it is needed such that
> statements like "if x = 1 ..." and "x := 1" don't acquire snapshots just
> because they are in a non-read only function? Could this be delayed
> till the start of any select/update/delete/insert, DDL, etc?

As noted in the comment there,

* We have to do some of the things SPI_execute_plan would do, in
* particular advance the snapshot if we are in a non-read-only function.
* Without this, stable functions within the expression would fail to see
* updates made so far by our own function.

You could possibly make such an optimization if you could be sure that
the expression being evaluated didn't examine database contents, or if
you knew that the current function hadn't yet changed anything.
The former seems a bit more practical --- you could check whether the
expression contains only immutable functions, which is a stronger test
than necessary but would probably admit most cases of practical
interest.

(This seems a bit out of scope for pgsql-novice, btw.)

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message i2013 2013-04-26 11:41:14 Re: How to Recover iPhone Contacts You Lost Somehow?
Previous Message Daniel Wood 2013-04-24 21:42:48 Could GetTransactionSnapshot be deferred till needed.