summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/sets.c8
-rw-r--r--src/backend/utils/cache/relcache.c12
-rw-r--r--src/backend/utils/time/tqual.c207
3 files changed, 203 insertions, 24 deletions
diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c
index a9c669bc3a..6553e73214 100644
--- a/src/backend/utils/adt/sets.c
+++ b/src/backend/utils/adt/sets.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.19 1998/11/27 19:52:23 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.20 1998/12/15 12:46:34 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -109,7 +109,7 @@ SetDefine(char *querystr, char *typename)
/* change the pg_proc tuple */
procrel = heap_openr(ProcedureRelationName);
- RelationSetLockForWrite(procrel);
+ LockRelation(procrel, AccessExclusiveLock);
tup = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(setoid),
@@ -123,7 +123,7 @@ SetDefine(char *querystr, char *typename)
repl);
setheapoverride(true);
- heap_replace(procrel, &tup->t_self, newtup);
+ heap_replace(procrel, &tup->t_self, newtup, NULL);
setheapoverride(false);
setoid = newtup->t_data->t_oid;
@@ -139,7 +139,7 @@ SetDefine(char *querystr, char *typename)
CatalogIndexInsert(idescs, Num_pg_proc_indices, procrel, newtup);
CatalogCloseIndices(Num_pg_proc_indices, idescs);
}
- RelationUnsetLockForWrite(procrel);
+ UnlockRelation(procrel, AccessExclusiveLock);
heap_close(procrel);
}
return setoid;
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 492eba6f65..99ee3d2fc5 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.51 1998/11/27 19:52:28 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.52 1998/12/15 12:46:37 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -363,8 +363,6 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo)
* ----------------
*/
pg_class_desc = heap_openr(RelationRelationName);
- if (!IsInitProcessingMode())
- RelationSetLockForRead(pg_class_desc);
pg_class_scan = heap_beginscan(pg_class_desc, 0, SnapshotNow, 1, &key);
pg_class_tuple = heap_getnext(pg_class_scan, 0);
@@ -388,8 +386,6 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo)
/* all done */
heap_endscan(pg_class_scan);
- if (!IsInitProcessingMode())
- RelationUnsetLockForRead(pg_class_desc);
heap_close(pg_class_desc);
return return_tuple;
@@ -403,7 +399,7 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo)
pg_class_desc = heap_openr(RelationRelationName);
if (!IsInitProcessingMode())
- RelationSetLockForRead(pg_class_desc);
+ LockRelation(pg_class_desc, AccessShareLock);
switch (buildinfo.infotype)
{
@@ -428,7 +424,7 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo)
/* all done */
if (!IsInitProcessingMode())
- RelationUnsetLockForRead(pg_class_desc);
+ UnlockRelation(pg_class_desc, AccessShareLock);
heap_close(pg_class_desc);
return return_tuple;
@@ -1126,7 +1122,6 @@ RelationIdCacheGetRelation(Oid relationId)
}
RelationIncrementReferenceCount(rd);
- RelationSetLockForDescriptorOpen(rd);
}
@@ -1159,7 +1154,6 @@ RelationNameCacheGetRelation(char *relationName)
}
RelationIncrementReferenceCount(rd);
- RelationSetLockForDescriptorOpen(rd);
}
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index c88646151a..f53fdd7272 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.20 1998/11/27 19:52:36 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.21 1998/12/15 12:46:40 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,6 +26,9 @@
extern bool PostgresIsInitialized;
+SnapshotData SnapshotDirtyData;
+Snapshot SnapshotDirty = &SnapshotDirtyData;
+
/*
* XXX Transaction system override hacks start here
*/
@@ -88,8 +91,9 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple)
{
if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */
return true;
- else
- return false;
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+ return false;
}
if (!TransactionIdDidCommit(tuple->t_xmin))
@@ -107,10 +111,18 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple)
return true;
if (tuple->t_infomask & HEAP_XMAX_COMMITTED)
- return false;
+ {
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+ return false; /* updated by other */
+ }
if (TransactionIdIsCurrentTransactionId(tuple->t_xmax))
+ {
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
return false;
+ }
if (!TransactionIdDidCommit(tuple->t_xmax))
{
@@ -122,6 +134,9 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple)
/* by here, deleting transaction has committed */
tuple->t_infomask |= HEAP_XMAX_COMMITTED;
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+
return false;
}
@@ -152,13 +167,6 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple)
* (Xmax is not committed && the row was deleted by another transaction
* Xmax != my-transaction)))) that has not been committed
*
- * XXX
- * CommandId stuff didn't work properly if one used SQL-functions in
- * UPDATE/INSERT(fromSELECT)/DELETE scans: SQL-funcs call
- * CommandCounterIncrement and made tuples changed/inserted by
- * current command visible to command itself (so we had multiple
- * update of updated tuples, etc). - vadim 08/29/97
- *
* mao says 17 march 1993: the tests in this routine are correct;
* if you think they're not, you're wrong, and you should think
* about it again. i know, it happened to me. we don't need to
@@ -203,6 +211,9 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
Assert(TransactionIdIsCurrentTransactionId(tuple->t_xmax));
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+
if (CommandIdGEScanCommandId(tuple->t_cmax))
return true; /* deleted after scan started */
else
@@ -229,10 +240,16 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
return true;
if (tuple->t_infomask & HEAP_XMAX_COMMITTED)
+ {
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
return false;
+ }
if (TransactionIdIsCurrentTransactionId(tuple->t_xmax))
{
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
if (CommandIdGEScanCommandId(tuple->t_cmax))
return true; /* deleted after scan started */
else
@@ -249,5 +266,173 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
/* xmax transaction committed */
tuple->t_infomask |= HEAP_XMAX_COMMITTED;
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+
return false;
}
+
+int
+HeapTupleSatisfiesUpdate(HeapTuple tuple)
+{
+ HeapTupleHeader th = tuple->t_data;
+
+ if (AMI_OVERRIDE)
+ return HeapTupleMayBeUpdated;
+
+ if (!(th->t_infomask & HEAP_XMIN_COMMITTED))
+ {
+ if (th->t_infomask & HEAP_XMIN_INVALID) /* xid invalid or aborted */
+ return HeapTupleInvisible;
+
+ if (TransactionIdIsCurrentTransactionId(th->t_xmin))
+ {
+ if (CommandIdGEScanCommandId(th->t_cmin) && !heapisoverride())
+ return HeapTupleInvisible; /* inserted after scan started */
+
+ if (th->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */
+ return HeapTupleMayBeUpdated;
+
+ Assert(TransactionIdIsCurrentTransactionId(th->t_xmax));
+
+ if (th->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return HeapTupleMayBeUpdated;
+
+ if (CommandIdGEScanCommandId(th->t_cmax))
+ return HeapTupleSelfUpdated;/* updated after scan started */
+ else
+ return HeapTupleInvisible; /* updated before scan started */
+ }
+
+ /*
+ * This call is VERY expensive - requires a log table lookup.
+ * Actually, this should be done by query before...
+ */
+
+ if (!TransactionIdDidCommit(th->t_xmin))
+ {
+ if (TransactionIdDidAbort(th->t_xmin))
+ th->t_infomask |= HEAP_XMIN_INVALID; /* aborted */
+ return HeapTupleInvisible;
+ }
+
+ th->t_infomask |= HEAP_XMIN_COMMITTED;
+ }
+
+ /* by here, the inserting transaction has committed */
+
+ if (th->t_infomask & HEAP_XMAX_INVALID) /* xid invalid or aborted */
+ return HeapTupleMayBeUpdated;
+
+ if (th->t_infomask & HEAP_XMAX_COMMITTED)
+ {
+ if (th->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return HeapTupleMayBeUpdated;
+ return HeapTupleUpdated; /* updated by other */
+ }
+
+ if (TransactionIdIsCurrentTransactionId(th->t_xmax))
+ {
+ if (th->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return HeapTupleMayBeUpdated;
+ if (CommandIdGEScanCommandId(th->t_cmax))
+ return HeapTupleSelfUpdated;/* updated after scan started */
+ else
+ return HeapTupleInvisible; /* updated before scan started */
+ }
+
+ if (!TransactionIdDidCommit(th->t_xmax))
+ {
+ if (TransactionIdDidAbort(th->t_xmax))
+ {
+ th->t_infomask |= HEAP_XMAX_INVALID; /* aborted */
+ return HeapTupleMayBeUpdated;
+ }
+ /* running xact */
+ return HeapTupleBeingUpdated; /* in updation by other */
+ }
+
+ /* xmax transaction committed */
+ th->t_infomask |= HEAP_XMAX_COMMITTED;
+
+ if (th->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return HeapTupleMayBeUpdated;
+
+ return HeapTupleUpdated; /* updated by other */
+}
+
+bool
+HeapTupleSatisfiesDirty(HeapTupleHeader tuple)
+{
+ SnapshotDirty->xmin = SnapshotDirty->xmax = InvalidTransactionId;
+
+ if (AMI_OVERRIDE)
+ return true;
+
+ if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
+ {
+ if (tuple->t_infomask & HEAP_XMIN_INVALID) /* xid invalid or aborted */
+ return false;
+
+ if (TransactionIdIsCurrentTransactionId(tuple->t_xmin))
+ {
+ if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */
+ return true;
+
+ Assert(TransactionIdIsCurrentTransactionId(tuple->t_xmax));
+
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+
+ return false;
+ }
+
+ if (!TransactionIdDidCommit(tuple->t_xmin))
+ {
+ if (TransactionIdDidAbort(tuple->t_xmin))
+ {
+ tuple->t_infomask |= HEAP_XMIN_INVALID; /* aborted */
+ return false;
+ }
+ SnapshotDirty->xmin = tuple->t_xmin;
+ return true; /* in insertion by other */
+ }
+
+ tuple->t_infomask |= HEAP_XMIN_COMMITTED;
+ }
+
+ /* by here, the inserting transaction has committed */
+
+ if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid or aborted */
+ return true;
+
+ if (tuple->t_infomask & HEAP_XMAX_COMMITTED)
+ {
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+ return false; /* updated by other */
+ }
+
+ if (TransactionIdIsCurrentTransactionId(tuple->t_xmax))
+ return false;
+
+ if (!TransactionIdDidCommit(tuple->t_xmax))
+ {
+ if (TransactionIdDidAbort(tuple->t_xmax))
+ {
+ tuple->t_infomask |= HEAP_XMAX_INVALID; /* aborted */
+ return true;
+ }
+ /* running xact */
+ SnapshotDirty->xmax = tuple->t_xmax;
+ return true; /* in updation by other */
+ }
+
+ /* xmax transaction committed */
+ tuple->t_infomask |= HEAP_XMAX_COMMITTED;
+
+ if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
+ return true;
+
+ return false; /* updated by other */
+}