]> granicus.if.org Git - postgresql/commitdiff
Change currtid functions to use an MVCC snapshot, not SnapshotNow.
authorRobert Haas <rhaas@postgresql.org>
Thu, 25 Jul 2013 20:32:02 +0000 (16:32 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 25 Jul 2013 20:32:02 +0000 (16:32 -0400)
This has a slight performance cost, but the only known consumers
of these functions, known at the SQL level as currtid and currtid2,
is pgsql-odbc; whose usage, we hope, is not sufficiently intensive
to make this a problem.

Per discussion.

src/backend/utils/adt/tid.c

index 5df9e399a9702831b6d0b2c65dc97cc0335a706d..1c2503f50f6ecc0413496368a703b6b597ab54ad 100644 (file)
@@ -30,6 +30,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/rel.h"
+#include "utils/snapmgr.h"
 #include "utils/tqual.h"
 
 
@@ -332,6 +333,7 @@ currtid_byreloid(PG_FUNCTION_ARGS)
        ItemPointer result;
        Relation        rel;
        AclResult       aclresult;
+       Snapshot        snapshot;
 
        result = (ItemPointer) palloc(sizeof(ItemPointerData));
        if (!reloid)
@@ -352,7 +354,10 @@ currtid_byreloid(PG_FUNCTION_ARGS)
                return currtid_for_view(rel, tid);
 
        ItemPointerCopy(tid, result);
-       heap_get_latest_tid(rel, SnapshotNow, result);
+
+       snapshot = RegisterSnapshot(GetLatestSnapshot());
+       heap_get_latest_tid(rel, snapshot, result);
+       UnregisterSnapshot(snapshot);
 
        heap_close(rel, AccessShareLock);
 
@@ -368,6 +373,7 @@ currtid_byrelname(PG_FUNCTION_ARGS)
        RangeVar   *relrv;
        Relation        rel;
        AclResult       aclresult;
+       Snapshot        snapshot;
 
        relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
        rel = heap_openrv(relrv, AccessShareLock);
@@ -384,7 +390,9 @@ currtid_byrelname(PG_FUNCTION_ARGS)
        result = (ItemPointer) palloc(sizeof(ItemPointerData));
        ItemPointerCopy(tid, result);
 
-       heap_get_latest_tid(rel, SnapshotNow, result);
+       snapshot = RegisterSnapshot(GetLatestSnapshot());
+       heap_get_latest_tid(rel, snapshot, result);
+       UnregisterSnapshot(snapshot);
 
        heap_close(rel, AccessShareLock);