]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix Assert failure when a fastpath function call is attempted inside an
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 11 Jun 2006 15:49:46 +0000 (15:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 11 Jun 2006 15:49:46 +0000 (15:49 +0000)
already-aborted transaction block.  GetSnapshotData throws an Assert if
not in a valid transaction; hence we mustn't attempt to set a snapshot
for the function until after checking for aborted transaction.  This is
harmless AFAICT if Asserts aren't enabled (GetSnapshotData will compute
a bogus snapshot, but it doesn't matter since HandleFunctionRequest will
throw an error shortly anywy).  Hence, not a major bug.

Along the way, add some ability to log fastpath calls when statement
logging is turned on.  This could probably stand to be improved further,
but not logging anything is clearly undesirable.

Backpatched as far as 8.0; bug doesn't exist before that.

src/backend/tcop/fastpath.c
src/backend/tcop/postgres.c

index b2c8903353039b267bfb1215c4b430ed9765f587..a4bcead4fc6e32b17c507eaa3357becdcd412c57 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.77 2004/12/31 22:01:16 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.77.4.1 2006/06/11 15:49:46 tgl Exp $
  *
  * NOTES
  *       This cruft is the server side of PQfn.
@@ -26,6 +26,7 @@
 #include "miscadmin.h"
 #include "mb/pg_wchar.h"
 #include "tcop/fastpath.h"
+#include "tcop/tcopprot.h"
 #include "utils/acl.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
@@ -304,14 +305,25 @@ HandleFunctionRequest(StringInfo msgBuf)
                                 errmsg("current transaction is aborted, "
                                        "commands ignored until end of transaction block")));
 
+       /*
+        * Now that we know we are in a valid transaction, set snapshot in
+        * case needed by function itself or one of the datatype I/O routines.
+        */
+       ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
+
        /*
         * Begin parsing the buffer contents.
         */
        if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
-               (void) pq_getmsgstring(msgBuf); /* dummy string */
+               (void) pq_getmsgstring(msgBuf);                 /* dummy string */
 
        fid = (Oid) pq_getmsgint(msgBuf, 4);            /* function oid */
 
+       if (log_statement == LOGSTMT_ALL)
+               ereport(LOG,
+                               (errmsg("fastpath function call: function OID %u",
+                                               fid)));
+
        /*
         * There used to be a lame attempt at caching lookup info here. Now we
         * just do the lookups on every call.
index b166e7d9b8ec96473afca58ad37b0e8e43e498b7..d7dc81959751dad3d7adb4f0bf39a4c0e350b6b5 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.440.4.5 2005/12/14 17:06:51 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.440.4.6 2006/06/11 15:49:46 tgl Exp $
  *
  * NOTES
  *       this is the "main" module of the postgres backend and
@@ -3161,12 +3161,18 @@ PostgresMain(int argc, char *argv[], const char *username)
                                /* start an xact for this function invocation */
                                start_xact_command();
 
+                               /*
+                                * Note: we may at this point be inside an aborted
+                                * transaction.  We can't throw error for that until
+                                * we've finished reading the function-call message, so
+                                * HandleFunctionRequest() must check for it after doing so.
+                                * Be careful not to do anything that assumes we're inside a
+                                * valid transaction here.
+                                */
+
                                /* switch back to message context */
                                MemoryContextSwitchTo(MessageContext);
 
-                               /* set snapshot in case function needs one */
-                               ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
-
                                if (HandleFunctionRequest(&input_message) == EOF)
                                {
                                        /* lost frontend connection during F message input */