Обсуждение: Could GetTransactionSnapshot be deferred till needed.

Поиск
Список
Период
Сортировка

Could GetTransactionSnapshot be deferred till needed.

От
Daniel Wood
Дата:
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?


Re: Could GetTransactionSnapshot be deferred till needed.

От
Tom Lane
Дата:
Daniel Wood <dwood@salesforce.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