mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +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
src/backend/utils/cache/relcache.c
vendored
13
src/backend/utils/cache/relcache.c
vendored
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.277 2008/11/26 17:08:57 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.278 2008/12/03 13:05:22 heikki Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -305,6 +305,7 @@ AllocateRelationDesc(Relation relation, Form_pg_class relp)
|
||||
MemSet(relation, 0, sizeof(RelationData));
|
||||
relation->rd_targblock = InvalidBlockNumber;
|
||||
relation->rd_fsm_nblocks = InvalidBlockNumber;
|
||||
relation->rd_vm_nblocks = InvalidBlockNumber;
|
||||
|
||||
/* make sure relation is marked as having no open file yet */
|
||||
relation->rd_smgr = NULL;
|
||||
@ -1377,6 +1378,7 @@ formrdesc(const char *relationName, Oid relationReltype,
|
||||
relation = (Relation) palloc0(sizeof(RelationData));
|
||||
relation->rd_targblock = InvalidBlockNumber;
|
||||
relation->rd_fsm_nblocks = InvalidBlockNumber;
|
||||
relation->rd_vm_nblocks = InvalidBlockNumber;
|
||||
|
||||
/* make sure relation is marked as having no open file yet */
|
||||
relation->rd_smgr = NULL;
|
||||
@ -1665,9 +1667,13 @@ RelationReloadIndexInfo(Relation relation)
|
||||
heap_freetuple(pg_class_tuple);
|
||||
/* We must recalculate physical address in case it changed */
|
||||
RelationInitPhysicalAddr(relation);
|
||||
/* Must reset targblock and fsm_nblocks in case rel was truncated */
|
||||
/*
|
||||
* Must reset targblock, fsm_nblocks and vm_nblocks in case rel was
|
||||
* truncated
|
||||
*/
|
||||
relation->rd_targblock = InvalidBlockNumber;
|
||||
relation->rd_fsm_nblocks = InvalidBlockNumber;
|
||||
relation->rd_vm_nblocks = InvalidBlockNumber;
|
||||
/* Must free any AM cached data, too */
|
||||
if (relation->rd_amcache)
|
||||
pfree(relation->rd_amcache);
|
||||
@ -1751,6 +1757,7 @@ RelationClearRelation(Relation relation, bool rebuild)
|
||||
{
|
||||
relation->rd_targblock = InvalidBlockNumber;
|
||||
relation->rd_fsm_nblocks = InvalidBlockNumber;
|
||||
relation->rd_vm_nblocks = InvalidBlockNumber;
|
||||
if (relation->rd_rel->relkind == RELKIND_INDEX)
|
||||
{
|
||||
relation->rd_isvalid = false; /* needs to be revalidated */
|
||||
@ -2346,6 +2353,7 @@ RelationBuildLocalRelation(const char *relname,
|
||||
|
||||
rel->rd_targblock = InvalidBlockNumber;
|
||||
rel->rd_fsm_nblocks = InvalidBlockNumber;
|
||||
rel->rd_vm_nblocks = InvalidBlockNumber;
|
||||
|
||||
/* make sure relation is marked as having no open file yet */
|
||||
rel->rd_smgr = NULL;
|
||||
@ -3603,6 +3611,7 @@ load_relcache_init_file(void)
|
||||
rel->rd_smgr = NULL;
|
||||
rel->rd_targblock = InvalidBlockNumber;
|
||||
rel->rd_fsm_nblocks = InvalidBlockNumber;
|
||||
rel->rd_vm_nblocks = InvalidBlockNumber;
|
||||
if (rel->rd_isnailed)
|
||||
rel->rd_refcnt = 1;
|
||||
else
|
||||
|
Reference in New Issue
Block a user