mirror of
https://github.com/postgres/postgres.git
synced 2025-10-19 15:49:24 +03:00
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.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.381 2008/11/19 10:34:51 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.382 2008/12/03 13:05:22 heikki Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "access/genam.h"
|
||||
#include "access/heapam.h"
|
||||
#include "access/transam.h"
|
||||
#include "access/visibilitymap.h"
|
||||
#include "access/xact.h"
|
||||
#include "access/xlog.h"
|
||||
#include "catalog/namespace.h"
|
||||
@@ -3005,10 +3006,19 @@ move_chain_tuple(Relation rel,
|
||||
|
||||
END_CRIT_SECTION();
|
||||
|
||||
PageClearAllVisible(BufferGetPage(old_buf));
|
||||
if (dst_buf != old_buf)
|
||||
PageClearAllVisible(BufferGetPage(dst_buf));
|
||||
|
||||
LockBuffer(dst_buf, BUFFER_LOCK_UNLOCK);
|
||||
if (dst_buf != old_buf)
|
||||
LockBuffer(old_buf, BUFFER_LOCK_UNLOCK);
|
||||
|
||||
/* Clear the bits in the visibility map. */
|
||||
visibilitymap_clear(rel, BufferGetBlockNumber(old_buf));
|
||||
if (dst_buf != old_buf)
|
||||
visibilitymap_clear(rel, BufferGetBlockNumber(dst_buf));
|
||||
|
||||
/* Create index entries for the moved tuple */
|
||||
if (ec->resultRelInfo->ri_NumIndices > 0)
|
||||
{
|
||||
@@ -3107,6 +3117,23 @@ move_plain_tuple(Relation rel,
|
||||
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/*
|
||||
* Clear the visible-to-all hint bits on the page, and bits in the
|
||||
* visibility map. Normally we'd release the locks on the heap pages
|
||||
* before updating the visibility map, but doesn't really matter here
|
||||
* because we're holding an AccessExclusiveLock on the relation anyway.
|
||||
*/
|
||||
if (PageIsAllVisible(dst_page))
|
||||
{
|
||||
PageClearAllVisible(dst_page);
|
||||
visibilitymap_clear(rel, BufferGetBlockNumber(dst_buf));
|
||||
}
|
||||
if (PageIsAllVisible(old_page))
|
||||
{
|
||||
PageClearAllVisible(old_page);
|
||||
visibilitymap_clear(rel, BufferGetBlockNumber(old_buf));
|
||||
}
|
||||
|
||||
dst_vacpage->free = PageGetFreeSpaceWithFillFactor(rel, dst_page);
|
||||
LockBuffer(dst_buf, BUFFER_LOCK_UNLOCK);
|
||||
LockBuffer(old_buf, BUFFER_LOCK_UNLOCK);
|
||||
|
Reference in New Issue
Block a user