summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorHeikki Linnakangas2008-12-03 13:05:22 +0000
committerHeikki Linnakangas2008-12-03 13:05:22 +0000
commit608195a3a3656145a7eec7a47d903bc684011d73 (patch)
treeb6e425e9de5d44d8c4725b4c04824c5ad252401d /src/include
parent44ff90966cd05d7371e559c35e5f2a3979868c64 (diff)
Introduce visibility map. The visibility map is a bitmap with one bit per
heap page, where a set bit indicates that all tuples on the page are visible to all transactions, and the page therefore doesn't need vacuuming. It is stored in a new relation fork. Lazy vacuum uses the visibility map to skip pages that don't need vacuuming. Vacuum is also responsible for setting the bits in the map. In the future, this can hopefully be used to implement index-only-scans, but we can't currently guarantee that the visibility map is always 100% up-to-date. In addition to the visibility map, there's a new PD_ALL_VISIBLE flag on each heap page, also indicating that all tuples on the page are visible to all transactions. It's important that this flag is kept up-to-date. It is also used to skip visibility tests in sequential scans, which gives a small performance gain on seqscans.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/htup.h12
-rw-r--r--src/include/access/visibilitymap.h30
-rw-r--r--src/include/storage/bufpage.h13
-rw-r--r--src/include/storage/relfilenode.h7
-rw-r--r--src/include/utils/rel.h8
5 files changed, 59 insertions, 11 deletions
diff --git a/src/include/access/htup.h b/src/include/access/htup.h
index 3e075236d3..5d1f0b1d90 100644
--- a/src/include/access/htup.h
+++ b/src/include/access/htup.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.104 2008/11/14 01:57:42 alvherre Exp $
+ * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.105 2008/12/03 13:05:22 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -601,9 +601,10 @@ typedef struct xl_heaptid
typedef struct xl_heap_delete
{
xl_heaptid target; /* deleted tuple id */
+ bool all_visible_cleared; /* PD_ALL_VISIBLE was cleared */
} xl_heap_delete;
-#define SizeOfHeapDelete (offsetof(xl_heap_delete, target) + SizeOfHeapTid)
+#define SizeOfHeapDelete (offsetof(xl_heap_delete, all_visible_cleared) + sizeof(bool))
/*
* We don't store the whole fixed part (HeapTupleHeaderData) of an inserted
@@ -626,21 +627,24 @@ typedef struct xl_heap_header
typedef struct xl_heap_insert
{
xl_heaptid target; /* inserted tuple id */
+ bool all_visible_cleared; /* PD_ALL_VISIBLE was cleared */
/* xl_heap_header & TUPLE DATA FOLLOWS AT END OF STRUCT */
} xl_heap_insert;
-#define SizeOfHeapInsert (offsetof(xl_heap_insert, target) + SizeOfHeapTid)
+#define SizeOfHeapInsert (offsetof(xl_heap_insert, all_visible_cleared) + sizeof(bool))
/* This is what we need to know about update|move|hot_update */
typedef struct xl_heap_update
{
xl_heaptid target; /* deleted tuple id */
ItemPointerData newtid; /* new inserted tuple id */
+ bool all_visible_cleared; /* PD_ALL_VISIBLE was cleared */
+ bool new_all_visible_cleared; /* same for the page of newtid */
/* NEW TUPLE xl_heap_header (PLUS xmax & xmin IF MOVE OP) */
/* and TUPLE DATA FOLLOWS AT END OF STRUCT */
} xl_heap_update;
-#define SizeOfHeapUpdate (offsetof(xl_heap_update, newtid) + SizeOfIptrData)
+#define SizeOfHeapUpdate (offsetof(xl_heap_update, new_all_visible_cleared) + sizeof(bool))
/*
* This is what we need to know about vacuum page cleanup/redirect
diff --git a/src/include/access/visibilitymap.h b/src/include/access/visibilitymap.h
new file mode 100644
index 0000000000..3803ac40bc
--- /dev/null
+++ b/src/include/access/visibilitymap.h
@@ -0,0 +1,30 @@
+/*-------------------------------------------------------------------------
+ *
+ * visibilitymap.h
+ * visibility map interface
+ *
+ *
+ * Portions Copyright (c) 2007, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $PostgreSQL: pgsql/src/include/access/visibilitymap.h,v 1.1 2008/12/03 13:05:22 heikki Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef VISIBILITYMAP_H
+#define VISIBILITYMAP_H
+
+#include "utils/rel.h"
+#include "storage/buf.h"
+#include "storage/itemptr.h"
+#include "access/xlogdefs.h"
+
+extern void visibilitymap_clear(Relation rel, BlockNumber heapBlk);
+extern void visibilitymap_pin(Relation rel, BlockNumber heapBlk,
+ Buffer *vmbuf);
+extern void visibilitymap_set(Relation rel, BlockNumber heapBlk,
+ XLogRecPtr recptr, Buffer *vmbuf);
+extern bool visibilitymap_test(Relation rel, BlockNumber heapBlk, Buffer *vmbuf);
+extern void visibilitymap_truncate(Relation rel, BlockNumber heapblk);
+
+#endif /* VISIBILITYMAP_H */
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index a5b88e78df..6115d5fc64 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.84 2008/11/03 20:47:49 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/bufpage.h,v 1.85 2008/12/03 13:05:22 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -152,8 +152,10 @@ typedef PageHeaderData *PageHeader;
#define PD_HAS_FREE_LINES 0x0001 /* are there any unused line pointers? */
#define PD_PAGE_FULL 0x0002 /* not enough free space for new
* tuple? */
+#define PD_ALL_VISIBLE 0x0004 /* all tuples on page are visible to
+ * everyone */
-#define PD_VALID_FLAG_BITS 0x0003 /* OR of all valid pd_flags bits */
+#define PD_VALID_FLAG_BITS 0x0007 /* OR of all valid pd_flags bits */
/*
* Page layout version number 0 is for pre-7.3 Postgres releases.
@@ -336,6 +338,13 @@ typedef PageHeaderData *PageHeader;
#define PageClearFull(page) \
(((PageHeader) (page))->pd_flags &= ~PD_PAGE_FULL)
+#define PageIsAllVisible(page) \
+ (((PageHeader) (page))->pd_flags & PD_ALL_VISIBLE)
+#define PageSetAllVisible(page) \
+ (((PageHeader) (page))->pd_flags |= PD_ALL_VISIBLE)
+#define PageClearAllVisible(page) \
+ (((PageHeader) (page))->pd_flags &= ~PD_ALL_VISIBLE)
+
#define PageIsPrunable(page, oldestxmin) \
( \
AssertMacro(TransactionIdIsNormal(oldestxmin)), \
diff --git a/src/include/storage/relfilenode.h b/src/include/storage/relfilenode.h
index adedad61b3..90a0f642d4 100644
--- a/src/include/storage/relfilenode.h
+++ b/src/include/storage/relfilenode.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/relfilenode.h,v 1.20 2008/11/19 10:34:52 heikki Exp $
+ * $PostgreSQL: pgsql/src/include/storage/relfilenode.h,v 1.21 2008/12/03 13:05:22 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -24,14 +24,15 @@ typedef enum ForkNumber
{
InvalidForkNumber = -1,
MAIN_FORKNUM = 0,
- FSM_FORKNUM
+ FSM_FORKNUM,
+ VISIBILITYMAP_FORKNUM
/*
* NOTE: if you add a new fork, change MAX_FORKNUM below and update the
* forkNames array in catalog.c
*/
} ForkNumber;
-#define MAX_FORKNUM FSM_FORKNUM
+#define MAX_FORKNUM VISIBILITYMAP_FORKNUM
/*
* RelFileNode must provide all that we need to know to physically access
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index 44540dd649..c75b1cffc3 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.109 2008/11/26 17:08:58 heikki Exp $
+ * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.110 2008/12/03 13:05:22 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -195,8 +195,12 @@ typedef struct RelationData
List *rd_indpred; /* index predicate tree, if any */
void *rd_amcache; /* available for use by index AM */
- /* size of the FSM, or InvalidBlockNumber if not known yet */
+ /*
+ * sizes of the free space and visibility map forks, or InvalidBlockNumber
+ * if not known yet
+ */
BlockNumber rd_fsm_nblocks;
+ BlockNumber rd_vm_nblocks;
/* use "struct" here to avoid needing to include pgstat.h: */
struct PgStat_TableStatus *pgstat_info; /* statistics collection area */