Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4e9fc3a

Browse files
committed
Return data from heap_page_prune via a struct.
Previously, one of the values in the struct was returned as the return value, and another was returned via an output parameter. In preparation for returning more stuff, consolidate both values into a struct returned via an output parameter. Melanie Plageman, reviewed by Andres Freund and by me. Discussion: https://postgr.es/m/CAAKRu_br124qsGJieuYA0nGjywEukhK1dKBfRdby_4yY3E9SXA%40mail.gmail.com
1 parent 22ff5c9 commit 4e9fc3a

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

src/backend/access/heap/pruneheap.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,13 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
155155
*/
156156
if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree)
157157
{
158-
int ndeleted,
159-
nnewlpdead;
158+
PruneResult presult;
160159

161-
ndeleted = heap_page_prune(relation, buffer, vistest,
162-
&nnewlpdead, NULL);
160+
heap_page_prune(relation, buffer, vistest, &presult, NULL);
163161

164162
/*
165163
* Report the number of tuples reclaimed to pgstats. This is
166-
* ndeleted minus the number of newly-LP_DEAD-set items.
164+
* presult.ndeleted minus the number of newly-LP_DEAD-set items.
167165
*
168166
* We derive the number of dead tuples like this to avoid totally
169167
* forgetting about items that were set to LP_DEAD, since they
@@ -175,9 +173,9 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
175173
* tracks ndeleted, since it will set the same LP_DEAD items to
176174
* LP_UNUSED separately.
177175
*/
178-
if (ndeleted > nnewlpdead)
176+
if (presult.ndeleted > presult.nnewlpdead)
179177
pgstat_update_heap_dead_tuples(relation,
180-
ndeleted - nnewlpdead);
178+
presult.ndeleted - presult.nnewlpdead);
181179
}
182180

183181
/* And release buffer lock */
@@ -204,21 +202,19 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
204202
* (see heap_prune_satisfies_vacuum and
205203
* HeapTupleSatisfiesVacuum).
206204
*
207-
* Sets *nnewlpdead for caller, indicating the number of items that were
208-
* newly set LP_DEAD during prune operation.
209-
*
210205
* off_loc is the offset location required by the caller to use in error
211206
* callback.
212207
*
213-
* Returns the number of tuples deleted from the page during this call.
208+
* presult contains output parameters needed by callers such as the number of
209+
* tuples removed and the number of line pointers newly marked LP_DEAD.
210+
* heap_page_prune() is responsible for initializing it.
214211
*/
215-
int
212+
void
216213
heap_page_prune(Relation relation, Buffer buffer,
217214
GlobalVisState *vistest,
218-
int *nnewlpdead,
215+
PruneResult *presult,
219216
OffsetNumber *off_loc)
220217
{
221-
int ndeleted = 0;
222218
Page page = BufferGetPage(buffer);
223219
BlockNumber blockno = BufferGetBlockNumber(buffer);
224220
OffsetNumber offnum,
@@ -244,6 +240,9 @@ heap_page_prune(Relation relation, Buffer buffer,
244240
prstate.nredirected = prstate.ndead = prstate.nunused = 0;
245241
memset(prstate.marked, 0, sizeof(prstate.marked));
246242

243+
presult->ndeleted = 0;
244+
presult->nnewlpdead = 0;
245+
247246
maxoff = PageGetMaxOffsetNumber(page);
248247
tup.t_tableOid = RelationGetRelid(prstate.rel);
249248

@@ -318,7 +317,7 @@ heap_page_prune(Relation relation, Buffer buffer,
318317
continue;
319318

320319
/* Process this item or chain of items */
321-
ndeleted += heap_prune_chain(buffer, offnum, &prstate);
320+
presult->ndeleted += heap_prune_chain(buffer, offnum, &prstate);
322321
}
323322

324323
/* Clear the offset information once we have processed the given page. */
@@ -419,9 +418,7 @@ heap_page_prune(Relation relation, Buffer buffer,
419418
END_CRIT_SECTION();
420419

421420
/* Record number of newly-set-LP_DEAD items for caller */
422-
*nnewlpdead = prstate.ndead;
423-
424-
return ndeleted;
421+
presult->nnewlpdead = prstate.ndead;
425422
}
426423

427424

src/backend/access/heap/vacuumlazy.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,12 +1544,11 @@ lazy_scan_prune(LVRelState *vacrel,
15441544
ItemId itemid;
15451545
HeapTupleData tuple;
15461546
HTSV_Result res;
1547-
int tuples_deleted,
1548-
tuples_frozen,
1547+
PruneResult presult;
1548+
int tuples_frozen,
15491549
lpdead_items,
15501550
live_tuples,
15511551
recently_dead_tuples;
1552-
int nnewlpdead;
15531552
HeapPageFreeze pagefrz;
15541553
int64 fpi_before = pgWalUsage.wal_fpi;
15551554
OffsetNumber deadoffsets[MaxHeapTuplesPerPage];
@@ -1572,7 +1571,6 @@ lazy_scan_prune(LVRelState *vacrel,
15721571
pagefrz.FreezePageRelminMxid = vacrel->NewRelminMxid;
15731572
pagefrz.NoFreezePageRelfrozenXid = vacrel->NewRelfrozenXid;
15741573
pagefrz.NoFreezePageRelminMxid = vacrel->NewRelminMxid;
1575-
tuples_deleted = 0;
15761574
tuples_frozen = 0;
15771575
lpdead_items = 0;
15781576
live_tuples = 0;
@@ -1581,15 +1579,12 @@ lazy_scan_prune(LVRelState *vacrel,
15811579
/*
15821580
* Prune all HOT-update chains in this page.
15831581
*
1584-
* We count tuples removed by the pruning step as tuples_deleted. Its
1585-
* final value can be thought of as the number of tuples that have been
1586-
* deleted from the table. It should not be confused with lpdead_items;
1582+
* We count the number of tuples removed from the page by the pruning step
1583+
* in presult.ndeleted. It should not be confused with lpdead_items;
15871584
* lpdead_items's final value can be thought of as the number of tuples
15881585
* that were deleted from indexes.
15891586
*/
1590-
tuples_deleted = heap_page_prune(rel, buf, vacrel->vistest,
1591-
&nnewlpdead,
1592-
&vacrel->offnum);
1587+
heap_page_prune(rel, buf, vacrel->vistest, &presult, &vacrel->offnum);
15931588

15941589
/*
15951590
* Now scan the page to collect LP_DEAD items and check for tuples
@@ -1929,7 +1924,7 @@ lazy_scan_prune(LVRelState *vacrel,
19291924
}
19301925

19311926
/* Finally, add page-local counts to whole-VACUUM counts */
1932-
vacrel->tuples_deleted += tuples_deleted;
1927+
vacrel->tuples_deleted += presult.ndeleted;
19331928
vacrel->tuples_frozen += tuples_frozen;
19341929
vacrel->lpdead_items += lpdead_items;
19351930
vacrel->live_tuples += live_tuples;

src/include/access/heapam.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ typedef struct HeapPageFreeze
191191

192192
} HeapPageFreeze;
193193

194+
/*
195+
* Per-page state returned from pruning
196+
*/
197+
typedef struct PruneResult
198+
{
199+
int ndeleted; /* Number of tuples deleted from the page */
200+
int nnewlpdead; /* Number of newly LP_DEAD items */
201+
} PruneResult;
202+
194203
/* ----------------
195204
* function prototypes for heap access method
196205
*
@@ -284,9 +293,9 @@ extern TransactionId heap_index_delete_tuples(Relation rel,
284293
/* in heap/pruneheap.c */
285294
struct GlobalVisState;
286295
extern void heap_page_prune_opt(Relation relation, Buffer buffer);
287-
extern int heap_page_prune(Relation relation, Buffer buffer,
296+
extern void heap_page_prune(Relation relation, Buffer buffer,
288297
struct GlobalVisState *vistest,
289-
int *nnewlpdead,
298+
PruneResult *presult,
290299
OffsetNumber *off_loc);
291300
extern void heap_page_prune_execute(Buffer buffer,
292301
OffsetNumber *redirected, int nredirected,

src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,7 @@ ProjectionPath
21512151
PromptInterruptContext
21522152
ProtocolVersion
21532153
PrsStorage
2154+
PruneResult
21542155
PruneState
21552156
PruneStepResult
21562157
PsqlScanCallbacks

0 commit comments

Comments
 (0)