Thread: [PATCH] Proposed: Have SPI_connect fail if there is no current snapshot

[PATCH] Proposed: Have SPI_connect fail if there is no current snapshot

From
Martijn van Oosterhout
Date:
[Please CC any replies]

Hi,

As per discussion on -hackers, type input functions can be called prior
to there being a current snapshot, causing any queries you execute to
fail with the "no snapshot has been set" error. So I propose to simply
have SPI_connect fail right off the bat and document that to avoid
future surprises. At least until the issue of non-immutable type input
functions has been sorted out.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment
Martijn van Oosterhout <kleptog@svana.org> writes:
> As per discussion on -hackers, type input functions can be called prior
> to there being a current snapshot, causing any queries you execute to
> fail with the "no snapshot has been set" error. So I propose to simply
> have SPI_connect fail right off the bat and document that to avoid
> future surprises.

This strikes me as a pretty unreasonable restriction.  It would be OK
if there were no valid uses of SPI that didn't require a snapshot, but
that's not so.  As an example, consider trying to issue a LOCK TABLE
command via SPI (okay, there are other ways to do that, but it's still
a valid example).

            regards, tom lane

Re: [PATCH] Proposed: Have SPI_connect fail if there is no current snapshot

From
Martijn van Oosterhout
Date:
On Sat, Aug 13, 2005 at 06:22:06PM -0400, Tom Lane wrote:
> This strikes me as a pretty unreasonable restriction.  It would be OK
> if there were no valid uses of SPI that didn't require a snapshot, but
> that's not so.  As an example, consider trying to issue a LOCK TABLE
> command via SPI (okay, there are other ways to do that, but it's still
> a valid example).

You can lock a table even while you have no valid snapshot? I thought
that without a valid snapshot you couldn't do anything, except access
system tables which are exempt from the usual snapshot rules.

In that case it may be better to document the failure case in SPI_exec.
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment
Martijn van Oosterhout <kleptog@svana.org> writes:
> You can lock a table even while you have no valid snapshot?

Certainly.  In serializable mode, you really need to be able to take out
locks before the snapshot is set --- TFM explains:

    Note also that if one is relying on explicit locking to prevent
    concurrent changes, one should use Read Committed mode, or in
    Serializable mode be careful to obtain the lock(s) before performing
    queries. A lock obtained by a serializable transaction guarantees that
    no other transactions modifying the table are still running, but if the
    snapshot seen by the transaction predates obtaining the lock, it may
    predate some now-committed changes in the table. A serializable
    transaction's snapshot is actually frozen at the start of its first
    query or data-modification command (SELECT, INSERT, UPDATE, or DELETE),
    so it's possible to obtain locks explicitly before the snapshot is
    frozen.

            regards, tom lane