row stamp checks for both 8.2 and 8.3
authorMarko Kreen <markokr@gmail.com>
Wed, 28 Mar 2007 17:17:12 +0000 (17:17 +0000)
committerMarko Kreen <markokr@gmail.com>
Wed, 28 Mar 2007 17:17:12 +0000 (17:17 +0000)
src/function.c
src/plproxy.h

index dd4bd08bc6e4e558c5d31d23a5b9945394ef65ef..2467d8da5f48bcc1ea03fd4c17b141374462785b 100644 (file)
@@ -155,8 +155,7 @@ fn_new(FunctionCallInfo fcinfo, HeapTuple proc_tuple)
        f = palloc0(sizeof(*f));
        f->ctx = f_ctx;
        f->oid = fcinfo->flinfo->fn_oid;
-       f->xmin = HeapTupleHeaderGetXmin(proc_tuple->t_data);
-       f->cmin = HeapTupleHeaderGetCmin(proc_tuple->t_data);
+       plproxy_set_stamp(&f->stamp, proc_tuple);
 
        MemoryContextSwitchTo(old_ctx);
 
@@ -376,25 +375,11 @@ plproxy_compile(FunctionCallInfo fcinfo, bool validate)
        /* fn_extra not used, do lookup */
        f = fn_cache_lookup(oid);
 
-       /* got, but is it still valid? */
-       if (f)
+       /* if cached, is it still valid? */
+       if (f && !plproxy_check_stamp(&f->stamp, proc_tuple))
        {
-               bool            drop = 0;
-
-               if (f->xmin != HeapTupleHeaderGetXmin(proc_tuple->t_data))
-               {
-                       drop = 1;
-               }
-               else if (f->cmin == HeapTupleHeaderGetCmin(proc_tuple->t_data))
-               {
-                       drop = 1;
-               }
-
-               if (drop)
-               {
-                       fn_delete(f, true);
-                       f = NULL;
-               }
+               fn_delete(f, true);
+               f = NULL;
        }
 
        if (!f)
index 78fb7394b0395a536dab57283bf963dff00af88d..0d6be36fb8a2807f0c759be6448b2600ef7746de 100644 (file)
 
 #include <libpq-fe.h>
 
+#if PG_VERSION_NUM < 80300
+
+/*
+ * Row version check for 8.2
+ */
+typedef struct RowStamp {
+       TransactionId   xmin;
+       CommandId               cmin;
+} RowStamp;
+
+static inline void plproxy_set_stamp(RowStamp *stamp, HeapTuple tup)
+{
+       stamp->xmin = HeapTupleHeaderGetXmin(tup->t_data);
+       stamp->cmin = HeapTupleHeaderGetCmin(tup->t_data);
+}
+
+static inline bool plproxy_check_stamp(RowStamp *stamp, HeapTuple tup)
+{
+       return stamp->xmin == HeapTupleHeaderGetXmin(tup->t_data)
+               && stamp->cmin == HeapTupleHeaderGetCmin(tup->t_data);
+}
+
+#else /* ver >= 8.3 */
+
+/*
+ * Row version check for PG >= 8.3
+ */
+typedef struct RowStamp {
+       TransactionId           xmin;
+       ItemPointerData         tid;
+} RowStamp;
+
+static inline void plproxy_set_stamp(RowStamp *stamp, HeapTuple tup)
+{
+       stamp->xmin = HeapTupleHeaderGetXmin(tup->t_data);
+       stamp->tid = procTup->t_self;
+}
+
+static inline bool plproxy_check_stamp(RowStamp *stamp, HeapTuple tup)
+{
+       return stamp->xmin == HeapTupleHeaderGetXmin(tup->t_data)
+               && ItemPointerEquals(&stamp->tid, &tup->t_self);
+}
+#endif
+
 /*
  * Maintenece period in seconds.  Connnections will be freed
  * from stale results, and checked for lifetime.
@@ -199,8 +244,7 @@ typedef struct ProxyFunction
        Oid                     oid;                    /* Function OID */
        MemoryContext ctx;                      /* Where runtime allocations should happen */
 
-       TransactionId xmin;                     /* pg_proc xmin for cache validation */
-       CommandId       cmin;                   /* pg_proc cmin for cache validation */
+       RowStamp        stamp;                  /* for pg_proc cache validation */
 
        int                     arg_count;              /* Argument count of proxy function */
        ProxyType **arg_types;          /* Info about arguments */