summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2001-07-12 04:11:13 +0000
committerTom Lane2001-07-12 04:11:13 +0000
commitb9f3a929ee6b0309c50d837f464da7440303d2ef (patch)
treec3bd00b8b62a92bbfaf834dda3342df6f90453c6 /src/include
parenteaafc9d66c3196bd0d47cef2b0d8c2cafad504f3 (diff)
Create a new HeapTupleSatisfiesVacuum() routine in tqual.c that embodies the
validity checking rules for VACUUM. Make some other rearrangements of the VACUUM code to allow more code to be shared between full and lazy VACUUM. Minor code cleanups and added comments for TransactionId manipulations.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/heapam.h8
-rw-r--r--src/include/access/transam.h99
-rw-r--r--src/include/access/xact.h16
-rw-r--r--src/include/commands/vacuum.h22
-rw-r--r--src/include/utils/tqual.h32
5 files changed, 87 insertions, 90 deletions
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 62b91e5162..2f9a6de2ad 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: heapam.h,v 1.65 2001/06/22 19:16:23 wieck Exp $
+ * $Id: heapam.h,v 1.66 2001/07/12 04:11:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -15,6 +15,7 @@
#define HEAPAM_H
#include <time.h>
+
#include "access/htup.h"
#include "access/relscan.h"
#include "access/tupmacs.h"
@@ -218,6 +219,11 @@ extern void heap_restrpos(HeapScanDesc scan);
extern void heap_redo(XLogRecPtr lsn, XLogRecord *rptr);
extern void heap_undo(XLogRecPtr lsn, XLogRecord *rptr);
extern void heap_desc(char *buf, uint8 xl_info, char *rec);
+extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
+ char *unused, int unlen);
+extern XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf,
+ ItemPointerData from,
+ Buffer newbuf, HeapTuple newtup);
/* in common/heaptuple.c */
extern Size ComputeDataSize(TupleDesc tupleDesc, Datum *value, char *nulls);
diff --git a/src/include/access/transam.h b/src/include/access/transam.h
index 90d1f35983..5d328b3c71 100644
--- a/src/include/access/transam.h
+++ b/src/include/access/transam.h
@@ -1,17 +1,13 @@
/*-------------------------------------------------------------------------
*
* transam.h
- * postgres transaction access method support code header
+ * postgres transaction access method support code
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: transam.h,v 1.35 2001/05/25 15:45:33 momjian Exp $
- *
- * NOTES
- * Transaction System Version 101 now support proper oid
- * generation and recording in the variable relation.
+ * $Id: transam.h,v 1.36 2001/07/12 04:11:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,77 +16,60 @@
#include "storage/bufmgr.h"
+
/* ----------------
- * transaction system version id
+ * Special transaction ID values
*
- * this is stored on the first page of the log, time and variable
- * relations on the first 4 bytes. This is so that if we improve
- * the format of the transaction log after postgres version 2, then
- * people won't have to rebuild their databases.
+ * We do not use any transaction IDs less than 512 --- this leaves the first
+ * 128 bytes of pg_log available for special purposes such as version number
+ * storage. (Currently, we do not actually use them for anything.)
*
- * TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
- * Two databases with the same major version should be compatible,
- * even if their minor versions differ.
+ * AmiTransactionId is the XID for "bootstrap" operations. It should always
+ * be considered valid.
+ *
+ * FirstTransactionId is the first "normal" transaction id.
+ * ----------------
+ */
+#define NullTransactionId ((TransactionId) 0)
+#define DisabledTransactionId ((TransactionId) 1)
+#define AmiTransactionId ((TransactionId) 512)
+#define FirstTransactionId ((TransactionId) 514)
+
+/* ----------------
+ * transaction ID manipulation macros
* ----------------
*/
-#define TRANS_SYSTEM_VERSION 200
+#define TransactionIdIsValid(xid) ((bool) ((xid) != NullTransactionId))
+#define TransactionIdIsSpecial(xid) ((bool) ((xid) < FirstTransactionId))
+#define TransactionIdEquals(id1, id2) ((bool) ((id1) == (id2)))
+#define TransactionIdPrecedes(id1, id2) ((bool) ((id1) < (id2)))
+#define TransactionIdStore(xid, dest) \
+ (*((TransactionId*) (dest)) = (TransactionId) (xid))
+#define StoreInvalidTransactionId(dest) \
+ (*((TransactionId*) (dest)) = NullTransactionId)
/* ----------------
- * transaction id status values
+ * transaction status values
*
* someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
* commiting of child xactions.
* ----------------
*/
-#define XID_COMMIT 2 /* transaction commited */
-#define XID_ABORT 1 /* transaction aborted */
#define XID_INPROGRESS 0 /* transaction in progress */
+#define XID_ABORT 1 /* transaction aborted */
+#define XID_COMMIT 2 /* transaction commited */
#define XID_COMMIT_CHILD 3 /* child xact commited */
-typedef unsigned char XidStatus;/* (2 bits) */
+typedef unsigned char XidStatus; /* (2 bits) */
/* ----------
- * note: we reserve the first 16384 object ids for internal use.
+ * We reserve the first 16384 object ids for manual assignment.
* oid's less than this appear in the .bki files. the choice of
* 16384 is completely arbitrary.
* ----------
*/
#define BootstrapObjectIdData 16384
-/* ----------------
- * BitIndexOf computes the index of the Nth xid on a given block
- * ----------------
- */
-#define BitIndexOf(N) ((N) * 2)
-
-/* ----------------
- * transaction page definitions
- * ----------------
- */
-#define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
-#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
-
-/* ----------------
- * LogRelationContents structure
- *
- * This structure describes the storage of the data in the
- * first 128 bytes of the log relation. This storage is never
- * used for transaction status because transaction id's begin
- * their numbering at 512.
- *
- * The first 4 bytes of this relation store the version
- * number of the transaction system.
- * ----------------
- */
-typedef struct LogRelationContentsData
-{
- XLogRecPtr LSN; /* temp hack: LSN is member of any block */
- /* so should be described in bufmgr */
- int TransSystemVersion;
-} LogRelationContentsData;
-
-typedef LogRelationContentsData *LogRelationContents;
-
/*
* VariableCache is placed in shmem and used by
* backends to get next available XID & OID.
@@ -104,6 +83,7 @@ typedef struct VariableCacheData
typedef VariableCacheData *VariableCache;
+
/* ----------------
* extern declarations
* ----------------
@@ -142,16 +122,7 @@ extern void CheckMaxObjectId(Oid assigned_oid);
/* in transam.c */
extern Relation LogRelation;
-extern TransactionId cachedTestXid;
-extern XidStatus cachedTestXidStatus;
-
-extern TransactionId NullTransactionId;
-extern TransactionId AmiTransactionId;
-extern TransactionId FirstTransactionId;
-
-extern int RecoveryCheckingEnableState;
-
-/* in transsup.c */
+/* in xact.c */
extern bool AMI_OVERRIDE;
/* in varsup.c */
diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index ab75ec001f..abbe16ced3 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: xact.h,v 1.33 2001/03/22 04:00:32 momjian Exp $
+ * $Id: xact.h,v 1.34 2001/07/12 04:11:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -67,17 +67,6 @@ typedef TransactionStateData *TransactionState;
#define TBLOCK_ABORT 4
#define TBLOCK_ENDABORT 5
-/* ----------------
- * transaction ID manipulation macros
- * ----------------
- */
-#define TransactionIdIsValid(xid) ((bool) ((xid) != NullTransactionId))
-#define TransactionIdEquals(id1, id2) ((bool) ((id1) == (id2)))
-#define TransactionIdStore(xid, dest) \
- (*((TransactionId*) (dest)) = (TransactionId) (xid))
-#define StoreInvalidTransactionId(dest) \
- (*((TransactionId*) (dest)) = NullTransactionId)
-
/*
* XLOG allows to store some information in high 4 bits of log
* record xl_info field
@@ -133,8 +122,6 @@ extern void AbortOutOfAnyTransaction(void);
extern void RecordTransactionCommit(void);
-extern TransactionId DisabledTransactionId;
-
extern void XactPushRollback(void (*func) (void *), void *data);
extern void XactPopRollback(void);
@@ -146,6 +133,5 @@ extern void xact_desc(char *buf, uint8 xl_info, char *rec);
extern Datum xidin(PG_FUNCTION_ARGS);
extern Datum xidout(PG_FUNCTION_ARGS);
extern Datum xideq(PG_FUNCTION_ARGS);
-extern void TransactionIdAdd(TransactionId *xid, int value);
#endif /* XACT_H */
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index 0d9f66d04b..ff02055052 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -7,23 +7,43 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: vacuum.h,v 1.36 2001/06/27 23:31:39 tgl Exp $
+ * $Id: vacuum.h,v 1.37 2001/07/12 04:11:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef VACUUM_H
#define VACUUM_H
+#include <time.h>
+#include <sys/time.h>
+
+#ifdef HAVE_GETRUSAGE
+#include <sys/resource.h>
+#else
+#include "rusagestub.h"
+#endif
+
#include "nodes/parsenodes.h"
#include "storage/block.h"
+/* State structure for vac_init_rusage/vac_show_rusage */
+typedef struct VacRUsage
+{
+ struct timeval tv;
+ struct rusage ru;
+} VacRUsage;
+
+
/* in commands/vacuum.c */
extern void vacuum(VacuumStmt *vacstmt);
extern void vac_update_relstats(Oid relid,
BlockNumber num_pages,
double num_tuples,
bool hasindex);
+extern void vac_init_rusage(VacRUsage *ru0);
+extern const char *vac_show_rusage(VacRUsage *ru0);
+
/* in commands/analyze.c */
extern void analyze_rel(Oid relid, VacuumStmt *vacstmt);
diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h
index 7c3dece02f..86c88892ad 100644
--- a/src/include/utils/tqual.h
+++ b/src/include/utils/tqual.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: tqual.h,v 1.31 2001/06/18 21:38:02 momjian Exp $
+ * $Id: tqual.h,v 1.32 2001/07/12 04:11:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,8 +23,9 @@ typedef struct SnapshotData
{
TransactionId xmin; /* XID < xmin are visible to me */
TransactionId xmax; /* XID >= xmax are invisible to me */
- uint32 xcnt; /* # of xact below */
- TransactionId *xip; /* array of xacts in progress */
+ uint32 xcnt; /* # of xact ids in xip[] */
+ TransactionId *xip; /* array of xact IDs in progress */
+ /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
ItemPointerData tid; /* required for Dirty snapshot -:( */
} SnapshotData;
@@ -34,8 +35,8 @@ typedef SnapshotData *Snapshot;
#define SnapshotSelf ((Snapshot) 0x1)
#define SnapshotAny ((Snapshot) 0x2)
-extern Snapshot SnapshotDirty;
-extern Snapshot QuerySnapshot;
+extern DLLIMPORT Snapshot SnapshotDirty;
+extern DLLIMPORT Snapshot QuerySnapshot;
extern DLLIMPORT Snapshot SerializableSnapshot;
extern bool ReferentialIntegritySnapshotOverride;
@@ -66,11 +67,11 @@ extern bool ReferentialIntegritySnapshotOverride;
(IsSnapshotSelf(snapshot) ? \
HeapTupleSatisfiesItself((tuple)->t_data) \
: \
- (IsSnapshotDirty(snapshot) ? \
- HeapTupleSatisfiesDirty((tuple)->t_data) \
+ (IsSnapshotNow(snapshot) ? \
+ HeapTupleSatisfiesNow((tuple)->t_data) \
: \
- (IsSnapshotNow(snapshot) ? \
- HeapTupleSatisfiesNow((tuple)->t_data) \
+ (IsSnapshotDirty(snapshot) ? \
+ HeapTupleSatisfiesDirty((tuple)->t_data) \
: \
HeapTupleSatisfiesSnapshot((tuple)->t_data, snapshot) \
) \
@@ -79,18 +80,31 @@ extern bool ReferentialIntegritySnapshotOverride;
) \
)
+/* Result codes for HeapTupleSatisfiesUpdate */
#define HeapTupleMayBeUpdated 0
#define HeapTupleInvisible 1
#define HeapTupleSelfUpdated 2
#define HeapTupleUpdated 3
#define HeapTupleBeingUpdated 4
+/* Result codes for HeapTupleSatisfiesVacuum */
+typedef enum
+{
+ HEAPTUPLE_DEAD, /* tuple is dead and deletable */
+ HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */
+ HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */
+ HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
+ HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
+} HTSV_Result;
+
extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple);
extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple,
Snapshot snapshot);
extern int HeapTupleSatisfiesUpdate(HeapTuple tuple);
+extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
+ TransactionId XmaxRecent);
extern Snapshot GetSnapshotData(bool serializable);
extern void SetQuerySnapshot(void);