Skip to content

Commit 9226ba8

Browse files
committed
Keep heap_page_prune from marking the buffer dirty when it didn't
really change anything. Per report from Itagaki Takahiro. Fix by Pavan Deolasee.
1 parent 1c92724 commit 9226ba8

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/backend/access/heap/pruneheap.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/pruneheap.c,v 1.2 2007/09/21 21:25:42 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/pruneheap.c,v 1.3 2007/10/24 13:05:57 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -146,17 +146,29 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
146146
int nredirected = 0;
147147
int ndead = 0;
148148
int nunused = 0;
149+
bool page_was_full = false;
150+
TransactionId save_prune_xid;
149151

150152
START_CRIT_SECTION();
151153

152154
/*
153-
* Mark the page as clear of prunable tuples. If we find a tuple which
154-
* may soon become prunable, we shall set the hint again. Also clear
155-
* the "page is full" flag, since there's no point in repeating the
156-
* prune/defrag process until something else happens to the page.
155+
* Save the current pd_prune_xid and mark the page as clear of prunable
156+
* tuples. If we find a tuple which may soon become prunable, we shall set
157+
* the hint again.
157158
*/
159+
save_prune_xid = ((PageHeader) page)->pd_prune_xid;
158160
PageClearPrunable(page);
159-
PageClearFull(page);
161+
162+
/*
163+
* Also clear the "page is full" flag if it is set, since there's no point
164+
* in repeating the prune/defrag process until something else happens to
165+
* the page.
166+
*/
167+
if (PageIsFull(page))
168+
{
169+
PageClearFull(page);
170+
page_was_full = true;
171+
}
160172

161173
/* Scan the page */
162174
maxoff = PageGetMaxOffsetNumber(page);
@@ -209,10 +221,13 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
209221
else
210222
{
211223
/*
212-
* If we didn't prune anything, we have nonetheless updated the
213-
* pd_prune_xid field; treat this as a non-WAL-logged hint.
224+
* If we didn't prune anything, but have updated either the
225+
* pd_prune_xid field or the "page is full" flag, mark the buffer
226+
* dirty. This is treated as a non-WAL-logged hint.
214227
*/
215-
SetBufferCommitInfoNeedsSave(buffer);
228+
if (((PageHeader) page)->pd_prune_xid != save_prune_xid ||
229+
page_was_full)
230+
SetBufferCommitInfoNeedsSave(buffer);
216231
}
217232

218233
END_CRIT_SECTION();

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