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

2005-08-14 Thread Tom Lane
Martijn van Oosterhout  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

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


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

2005-08-14 Thread Martijn van Oosterhout
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  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.


pgpvmc0hHpzS5.pgp
Description: PGP signature


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

2005-08-13 Thread Tom Lane
Martijn van Oosterhout  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

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


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

2005-08-13 Thread Martijn van Oosterhout
[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  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.
Index: src/backend/executor/spi.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/executor/spi.c,v
retrieving revision 1.131
diff -u -r1.131 spi.c
--- src/backend/executor/spi.c  13 Oct 2004 01:25:10 -  1.131
+++ src/backend/executor/spi.c  13 Aug 2005 19:50:40 -
@@ -70,6 +70,12 @@
 */
if (_SPI_curid != _SPI_connected)
return SPI_ERROR_CONNECT;
+   
+   /* You can't actually execute queries if there is no current
+* snapshot, so return an error straightaway. eg User defined type
+* input functions */
+   if (SerializableSnapshot == NULL)
+   return SPI_ERROR_CONNECT;
 
if (_SPI_stack == NULL)
{
Index: doc/src/sgml/spi.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/spi.sgml,v
retrieving revision 1.42
diff -u -r1.42 spi.sgml
--- doc/src/sgml/spi.sgml   29 Jul 2005 13:00:03 -  1.42
+++ doc/src/sgml/spi.sgml   13 Aug 2005 19:50:40 -
@@ -106,6 +106,13 @@
SPI_finish are forbidden.
(But see SPI_push and SPI_pop.)
   
+
+   
+   SPI_connect will also fail if there is no current
+   snapshot. This generally only happens in implicitly called functions such
+   as type input functions.
+  
+
  
 
  


pgp3aK3nTsDsV.pgp
Description: PGP signature