mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Remove unnecessary calls of FlushRelationBuffers: there is no need
to write out data that we are about to tell the filesystem to drop. smgr_internal_unlink already had a DropRelFileNodeBuffers call to get rid of dead buffers without a write after it's no longer possible to roll back the deleting transaction. Adding a similar call in smgrtruncate simplifies callers and makes the overall division of labor clearer. This patch removes the former behavior that VACUUM would write all dirty buffers of a relation unconditionally.
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.132 2005/02/06 20:19:08 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.133 2005/03/20 22:00:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -709,8 +709,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
|
||||
void
|
||||
swap_relation_files(Oid r1, Oid r2)
|
||||
{
|
||||
Relation relRelation,
|
||||
rel;
|
||||
Relation relRelation;
|
||||
HeapTuple reltup1,
|
||||
reltup2;
|
||||
Form_pg_class relform1,
|
||||
@ -735,20 +734,6 @@ swap_relation_files(Oid r1, Oid r2)
|
||||
elog(ERROR, "cache lookup failed for relation %u", r2);
|
||||
relform2 = (Form_pg_class) GETSTRUCT(reltup2);
|
||||
|
||||
/*
|
||||
* The buffer manager gets confused if we swap relfilenodes for
|
||||
* relations that are not both local or non-local to this transaction.
|
||||
* Flush the buffers on both relations so the buffer manager can
|
||||
* forget about'em. (XXX this might not be necessary anymore?)
|
||||
*/
|
||||
rel = relation_open(r1, NoLock);
|
||||
FlushRelationBuffers(rel, 0);
|
||||
relation_close(rel, NoLock);
|
||||
|
||||
rel = relation_open(r2, NoLock);
|
||||
FlushRelationBuffers(rel, 0);
|
||||
relation_close(rel, NoLock);
|
||||
|
||||
/*
|
||||
* Actually swap the fields in the two tuples
|
||||
*/
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.147 2005/03/16 21:38:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.148 2005/03/20 22:00:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -5628,13 +5628,12 @@ copy_relation_data(Relation rel, SMgrRelation dst)
|
||||
Page page = (Page) buf;
|
||||
|
||||
/*
|
||||
* Since we copy the data directly without looking at the shared
|
||||
* Since we copy the file directly without looking at the shared
|
||||
* buffers, we'd better first flush out any pages of the source
|
||||
* relation that are in shared buffers. We assume no new pages will
|
||||
* get loaded into buffers while we are holding exclusive lock on the
|
||||
* rel.
|
||||
* relation that are in shared buffers. We assume no new changes
|
||||
* will be made while we are holding exclusive lock on the rel.
|
||||
*/
|
||||
FlushRelationBuffers(rel, 0);
|
||||
FlushRelationBuffers(rel);
|
||||
|
||||
/*
|
||||
* We need to log the copied data in WAL iff WAL archiving is enabled
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.304 2005/03/16 21:38:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.305 2005/03/20 22:00:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1138,16 +1138,6 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
|
||||
/* Clean pages from vacuum_pages list */
|
||||
vacuum_heap(vacrelstats, onerel, &vacuum_pages);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Flush dirty pages out to disk. We must do this even if we
|
||||
* didn't do anything else, because we want to ensure that all
|
||||
* tuples have correct on-row commit status on disk (see
|
||||
* bufmgr.c's comments for FlushRelationBuffers()).
|
||||
*/
|
||||
FlushRelationBuffers(onerel, vacrelstats->rel_pages);
|
||||
}
|
||||
}
|
||||
|
||||
/* update shared free space map with final free space info */
|
||||
@ -2420,15 +2410,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
|
||||
pfree(Nvacpagelist.pagedesc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush dirty pages out to disk. We do this unconditionally, even if
|
||||
* we don't need to truncate, because we want to ensure that all
|
||||
* tuples have correct on-row commit status on disk (see bufmgr.c's
|
||||
* comments for FlushRelationBuffers()).
|
||||
*/
|
||||
FlushRelationBuffers(onerel, blkno);
|
||||
|
||||
/* truncate relation, if needed */
|
||||
/* Truncate relation, if needed */
|
||||
if (blkno < nblocks)
|
||||
{
|
||||
RelationTruncate(onerel, blkno);
|
||||
@ -2818,27 +2800,17 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush dirty pages out to disk. We do this unconditionally, even if
|
||||
* we don't need to truncate, because we want to ensure that all
|
||||
* tuples have correct on-row commit status on disk (see bufmgr.c's
|
||||
* comments for FlushRelationBuffers()).
|
||||
*/
|
||||
/* Truncate relation if there are some empty end-pages */
|
||||
Assert(vacrelstats->rel_pages >= vacuum_pages->empty_end_pages);
|
||||
relblocks = vacrelstats->rel_pages - vacuum_pages->empty_end_pages;
|
||||
|
||||
FlushRelationBuffers(onerel, relblocks);
|
||||
|
||||
/* truncate relation if there are some empty end-pages */
|
||||
if (vacuum_pages->empty_end_pages > 0)
|
||||
{
|
||||
relblocks = vacrelstats->rel_pages - vacuum_pages->empty_end_pages;
|
||||
ereport(elevel,
|
||||
(errmsg("\"%s\": truncated %u to %u pages",
|
||||
RelationGetRelationName(onerel),
|
||||
vacrelstats->rel_pages, relblocks)));
|
||||
RelationTruncate(onerel, relblocks);
|
||||
vacrelstats->rel_pages = relblocks; /* set new number of
|
||||
* blocks */
|
||||
vacrelstats->rel_pages = relblocks; /* set new number of blocks */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.50 2004/12/31 21:59:42 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.51 2005/03/20 22:00:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -773,16 +773,6 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
|
||||
|
||||
/*
|
||||
* Okay to truncate.
|
||||
*
|
||||
* First, flush any shared buffers for the blocks we intend to delete.
|
||||
* FlushRelationBuffers is a bit more than we need for this, since it
|
||||
* will also write out dirty buffers for blocks we aren't deleting,
|
||||
* but it's the closest thing in bufmgr's API.
|
||||
*/
|
||||
FlushRelationBuffers(onerel, new_rel_pages);
|
||||
|
||||
/*
|
||||
* Do the physical truncation.
|
||||
*/
|
||||
RelationTruncate(onerel, new_rel_pages);
|
||||
|
||||
|
Reference in New Issue
Block a user