Skip to content

Commit 354049c

Browse files
committed
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.
1 parent 683f60d commit 354049c

File tree

10 files changed

+92
-237
lines changed

10 files changed

+92
-237
lines changed

src/backend/access/nbtree/nbtree.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.124 2004/12/31 21:59:22 pgsql Exp $
15+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.125 2005/03/20 22:00:50 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -772,17 +772,6 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
772772
{
773773
/*
774774
* Okay to truncate.
775-
*
776-
* First, flush any shared buffers for the blocks we intend to
777-
* delete. FlushRelationBuffers is a bit more than we need
778-
* for this, since it will also write out dirty buffers for
779-
* blocks we aren't deleting, but it's the closest thing in
780-
* bufmgr's API.
781-
*/
782-
FlushRelationBuffers(rel, new_pages);
783-
784-
/*
785-
* Do the physical truncation.
786775
*/
787776
RelationTruncate(rel, new_pages);
788777

src/backend/catalog/heap.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.280 2005/01/27 03:17:17 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.281 2005/03/20 22:00:51 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1174,12 +1174,6 @@ heap_drop_with_catalog(Oid relid)
11741174
*/
11751175
rel = relation_open(relid, AccessExclusiveLock);
11761176

1177-
/*
1178-
* Release all buffers that belong to this relation, after writing any
1179-
* that are dirty
1180-
*/
1181-
FlushRelationBuffers(rel, (BlockNumber) 0);
1182-
11831177
/*
11841178
* Schedule unlinking of the relation's physical file at commit.
11851179
*/
@@ -1958,13 +1952,7 @@ RelationTruncateIndexes(Oid heapId)
19581952
/* Fetch info needed for index_build */
19591953
indexInfo = BuildIndexInfo(currentIndex);
19601954

1961-
/*
1962-
* Drop any buffers associated with this index. If they're dirty,
1963-
* they're just dropped without bothering to flush to disk.
1964-
*/
1965-
DropRelationBuffers(currentIndex);
1966-
1967-
/* Now truncate the actual data */
1955+
/* Now truncate the actual file (and discard buffers) */
19681956
RelationTruncate(currentIndex, 0);
19691957

19701958
/* Initialize the index and rebuild */
@@ -2024,13 +2012,7 @@ heap_truncate(List *relids)
20242012
{
20252013
Relation rel = lfirst(cell);
20262014

2027-
/*
2028-
* Release any buffers associated with this relation. If they're
2029-
* dirty, they're just dropped without bothering to flush to disk.
2030-
*/
2031-
DropRelationBuffers(rel);
2032-
2033-
/* Now truncate the actual data */
2015+
/* Truncate the actual file (and discard buffers) */
20342016
RelationTruncate(rel, 0);
20352017

20362018
/* If this relation has indexes, truncate the indexes too */

src/backend/catalog/index.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.247 2005/03/16 21:38:04 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.248 2005/03/20 22:00:51 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -775,10 +775,8 @@ index_drop(Oid indexId)
775775
LockRelation(userIndexRelation, AccessExclusiveLock);
776776

777777
/*
778-
* flush buffer cache and schedule physical removal of the file
778+
* Schedule physical removal of the file
779779
*/
780-
FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
781-
782780
RelationOpenSmgr(userIndexRelation);
783781
smgrscheduleunlink(userIndexRelation->rd_smgr,
784782
userIndexRelation->rd_istemp);
@@ -1617,14 +1615,7 @@ reindex_index(Oid indexId)
16171615

16181616
if (inplace)
16191617
{
1620-
/*
1621-
* Release any buffers associated with this index. If they're
1622-
* dirty, they're just dropped without bothering to flush to
1623-
* disk.
1624-
*/
1625-
DropRelationBuffers(iRel);
1626-
1627-
/* Now truncate the actual data */
1618+
/* Truncate the actual file (and discard buffers) */
16281619
RelationTruncate(iRel, 0);
16291620
}
16301621
else

src/backend/commands/cluster.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.132 2005/02/06 20:19:08 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.133 2005/03/20 22:00:52 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -709,8 +709,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
709709
void
710710
swap_relation_files(Oid r1, Oid r2)
711711
{
712-
Relation relRelation,
713-
rel;
712+
Relation relRelation;
714713
HeapTuple reltup1,
715714
reltup2;
716715
Form_pg_class relform1,
@@ -735,20 +734,6 @@ swap_relation_files(Oid r1, Oid r2)
735734
elog(ERROR, "cache lookup failed for relation %u", r2);
736735
relform2 = (Form_pg_class) GETSTRUCT(reltup2);
737736

738-
/*
739-
* The buffer manager gets confused if we swap relfilenodes for
740-
* relations that are not both local or non-local to this transaction.
741-
* Flush the buffers on both relations so the buffer manager can
742-
* forget about'em. (XXX this might not be necessary anymore?)
743-
*/
744-
rel = relation_open(r1, NoLock);
745-
FlushRelationBuffers(rel, 0);
746-
relation_close(rel, NoLock);
747-
748-
rel = relation_open(r2, NoLock);
749-
FlushRelationBuffers(rel, 0);
750-
relation_close(rel, NoLock);
751-
752737
/*
753738
* Actually swap the fields in the two tuples
754739
*/

src/backend/commands/tablecmds.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.147 2005/03/16 21:38:05 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.148 2005/03/20 22:00:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -5628,13 +5628,12 @@ copy_relation_data(Relation rel, SMgrRelation dst)
56285628
Page page = (Page) buf;
56295629

56305630
/*
5631-
* Since we copy the data directly without looking at the shared
5631+
* Since we copy the file directly without looking at the shared
56325632
* buffers, we'd better first flush out any pages of the source
5633-
* relation that are in shared buffers. We assume no new pages will
5634-
* get loaded into buffers while we are holding exclusive lock on the
5635-
* rel.
5633+
* relation that are in shared buffers. We assume no new changes
5634+
* will be made while we are holding exclusive lock on the rel.
56365635
*/
5637-
FlushRelationBuffers(rel, 0);
5636+
FlushRelationBuffers(rel);
56385637

56395638
/*
56405639
* We need to log the copied data in WAL iff WAL archiving is enabled

src/backend/commands/vacuum.c

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.304 2005/03/16 21:38:05 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.305 2005/03/20 22:00:52 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1138,16 +1138,6 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
11381138
/* Clean pages from vacuum_pages list */
11391139
vacuum_heap(vacrelstats, onerel, &vacuum_pages);
11401140
}
1141-
else
1142-
{
1143-
/*
1144-
* Flush dirty pages out to disk. We must do this even if we
1145-
* didn't do anything else, because we want to ensure that all
1146-
* tuples have correct on-row commit status on disk (see
1147-
* bufmgr.c's comments for FlushRelationBuffers()).
1148-
*/
1149-
FlushRelationBuffers(onerel, vacrelstats->rel_pages);
1150-
}
11511141
}
11521142

11531143
/* update shared free space map with final free space info */
@@ -2420,15 +2410,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
24202410
pfree(Nvacpagelist.pagedesc);
24212411
}
24222412

2423-
/*
2424-
* Flush dirty pages out to disk. We do this unconditionally, even if
2425-
* we don't need to truncate, because we want to ensure that all
2426-
* tuples have correct on-row commit status on disk (see bufmgr.c's
2427-
* comments for FlushRelationBuffers()).
2428-
*/
2429-
FlushRelationBuffers(onerel, blkno);
2430-
2431-
/* truncate relation, if needed */
2413+
/* Truncate relation, if needed */
24322414
if (blkno < nblocks)
24332415
{
24342416
RelationTruncate(onerel, blkno);
@@ -2818,27 +2800,17 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
28182800
}
28192801
}
28202802

2821-
/*
2822-
* Flush dirty pages out to disk. We do this unconditionally, even if
2823-
* we don't need to truncate, because we want to ensure that all
2824-
* tuples have correct on-row commit status on disk (see bufmgr.c's
2825-
* comments for FlushRelationBuffers()).
2826-
*/
2803+
/* Truncate relation if there are some empty end-pages */
28272804
Assert(vacrelstats->rel_pages >= vacuum_pages->empty_end_pages);
2828-
relblocks = vacrelstats->rel_pages - vacuum_pages->empty_end_pages;
2829-
2830-
FlushRelationBuffers(onerel, relblocks);
2831-
2832-
/* truncate relation if there are some empty end-pages */
28332805
if (vacuum_pages->empty_end_pages > 0)
28342806
{
2807+
relblocks = vacrelstats->rel_pages - vacuum_pages->empty_end_pages;
28352808
ereport(elevel,
28362809
(errmsg("\"%s\": truncated %u to %u pages",
28372810
RelationGetRelationName(onerel),
28382811
vacrelstats->rel_pages, relblocks)));
28392812
RelationTruncate(onerel, relblocks);
2840-
vacrelstats->rel_pages = relblocks; /* set new number of
2841-
* blocks */
2813+
vacrelstats->rel_pages = relblocks; /* set new number of blocks */
28422814
}
28432815
}
28442816

src/backend/commands/vacuumlazy.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
*
3333
* IDENTIFICATION
34-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.50 2004/12/31 21:59:42 pgsql Exp $
34+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.51 2005/03/20 22:00:52 tgl Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -773,16 +773,6 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
773773

774774
/*
775775
* Okay to truncate.
776-
*
777-
* First, flush any shared buffers for the blocks we intend to delete.
778-
* FlushRelationBuffers is a bit more than we need for this, since it
779-
* will also write out dirty buffers for blocks we aren't deleting,
780-
* but it's the closest thing in bufmgr's API.
781-
*/
782-
FlushRelationBuffers(onerel, new_rel_pages);
783-
784-
/*
785-
* Do the physical truncation.
786776
*/
787777
RelationTruncate(onerel, new_rel_pages);
788778

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy