diff options
| author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2008-12-03 13:05:22 +0000 |
|---|---|---|
| committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2008-12-03 13:05:22 +0000 |
| commit | 608195a3a3656145a7eec7a47d903bc684011d73 (patch) | |
| tree | b6e425e9de5d44d8c4725b4c04824c5ad252401d /src/backend/catalog/storage.c | |
| parent | 44ff90966cd05d7371e559c35e5f2a3979868c64 (diff) | |
| download | postgresql-608195a3a3656145a7eec7a47d903bc684011d73.tar.gz | |
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/backend/catalog/storage.c')
| -rw-r--r-- | src/backend/catalog/storage.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index c8187d511c..dfba476cda 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/storage.c,v 1.1 2008/11/19 10:34:51 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/storage.c,v 1.2 2008/12/03 13:05:22 heikki Exp $ * * NOTES * Some of this code used to be in storage/smgr/smgr.c, and the @@ -19,6 +19,7 @@ #include "postgres.h" +#include "access/visibilitymap.h" #include "access/xact.h" #include "access/xlogutils.h" #include "catalog/catalog.h" @@ -175,6 +176,7 @@ void RelationTruncate(Relation rel, BlockNumber nblocks) { bool fsm; + bool vm; /* Open it at the smgr level if not already done */ RelationOpenSmgr(rel); @@ -187,6 +189,11 @@ RelationTruncate(Relation rel, BlockNumber nblocks) if (fsm) FreeSpaceMapTruncateRel(rel, nblocks); + /* Truncate the visibility map too if it exists. */ + vm = smgrexists(rel->rd_smgr, VISIBILITYMAP_FORKNUM); + if (vm) + visibilitymap_truncate(rel, nblocks); + /* * We WAL-log the truncation before actually truncating, which * means trouble if the truncation fails. If we then crash, the WAL @@ -217,12 +224,12 @@ RelationTruncate(Relation rel, BlockNumber nblocks) /* * Flush, because otherwise the truncation of the main relation - * might hit the disk before the WAL record of truncating the - * FSM is flushed. If we crashed during that window, we'd be - * left with a truncated heap, but the FSM would still contain - * entries for the non-existent heap pages. + * might hit the disk before the WAL record, and the truncation of + * the FSM or visibility map. If we crashed during that window, we'd + * be left with a truncated heap, but the FSM or visibility map would + * still contain entries for the non-existent heap pages. */ - if (fsm) + if (fsm || vm) XLogFlush(lsn); } |
