Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc42a6fc

Browse files
vacuumlazy.c: Further consolidate resource allocation.
Move remaining VACUUM resource allocation and deallocation code fromlazy_scan_heap() to its caller, heap_vacuum_rel(). This finishes offwork started by commit73f6ec3.Author: Peter Geoghegan <pg@bowt.ie>Discussion:https://postgr.es/m/CAH2-Wzk3fNBa_S3Ngi+16GQiyJ=AmUu3oUY99syMDTMRxitfyQ@mail.gmail.com
1 parent7844c99 commitc42a6fc

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

‎src/backend/access/heap/vacuumlazy.c

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ typedef struct LVSavedErrInfo
246246

247247

248248
/* non-export function prototypes */
249-
staticvoidlazy_scan_heap(LVRelState*vacrel,intnworkers);
249+
staticvoidlazy_scan_heap(LVRelState*vacrel);
250250
staticBlockNumberlazy_scan_skip(LVRelState*vacrel,Buffer*vmbuffer,
251251
BlockNumbernext_block,
252252
bool*next_unskippable_allvis,
@@ -514,11 +514,28 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
514514
vacrel->NewRelminMxid=OldestMxact;
515515
vacrel->skippedallvis= false;
516516

517+
/*
518+
* Allocate dead_items array memory using dead_items_alloc. This handles
519+
* parallel VACUUM initialization as part of allocating shared memory
520+
* space used for dead_items. (But do a failsafe precheck first, to
521+
* ensure that parallel VACUUM won't be attempted at all when relfrozenxid
522+
* is already dangerously old.)
523+
*/
524+
lazy_check_wraparound_failsafe(vacrel);
525+
dead_items_alloc(vacrel,params->nworkers);
526+
517527
/*
518528
* Call lazy_scan_heap to perform all required heap pruning, index
519529
* vacuuming, and heap vacuuming (plus related processing)
520530
*/
521-
lazy_scan_heap(vacrel,params->nworkers);
531+
lazy_scan_heap(vacrel);
532+
533+
/*
534+
* Free resources managed by dead_items_alloc. This ends parallel mode in
535+
* passing when necessary.
536+
*/
537+
dead_items_cleanup(vacrel);
538+
Assert(!IsInParallelMode());
522539

523540
/*
524541
* Update pg_class entries for each of rel's indexes where appropriate.
@@ -825,14 +842,14 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
825842
*supply.
826843
*/
827844
staticvoid
828-
lazy_scan_heap(LVRelState*vacrel,intnworkers)
845+
lazy_scan_heap(LVRelState*vacrel)
829846
{
830-
VacDeadItems*dead_items;
831847
BlockNumberrel_pages=vacrel->rel_pages,
832848
blkno,
833849
next_unskippable_block,
834-
next_failsafe_block,
835-
next_fsm_block_to_vacuum;
850+
next_failsafe_block=0,
851+
next_fsm_block_to_vacuum=0;
852+
VacDeadItems*dead_items=vacrel->dead_items;
836853
Buffervmbuffer=InvalidBuffer;
837854
boolnext_unskippable_allvis,
838855
skipping_current_range;
@@ -843,23 +860,6 @@ lazy_scan_heap(LVRelState *vacrel, int nworkers)
843860
};
844861
int64initprog_val[3];
845862

846-
/*
847-
* Do failsafe precheck before calling dead_items_alloc. This ensures
848-
* that parallel VACUUM won't be attempted when relfrozenxid is already
849-
* dangerously old.
850-
*/
851-
lazy_check_wraparound_failsafe(vacrel);
852-
next_failsafe_block=0;
853-
854-
/*
855-
* Allocate the space for dead_items. Note that this handles parallel
856-
* VACUUM initialization as part of allocating shared memory space used
857-
* for dead_items.
858-
*/
859-
dead_items_alloc(vacrel,nworkers);
860-
dead_items=vacrel->dead_items;
861-
next_fsm_block_to_vacuum=0;
862-
863863
/* Report that we're scanning the heap, advertising total # of blocks */
864864
initprog_val[0]=PROGRESS_VACUUM_PHASE_SCAN_HEAP;
865865
initprog_val[1]=rel_pages;
@@ -1236,12 +1236,13 @@ lazy_scan_heap(LVRelState *vacrel, int nworkers)
12361236
}
12371237
}
12381238

1239+
vacrel->blkno=InvalidBlockNumber;
1240+
if (BufferIsValid(vmbuffer))
1241+
ReleaseBuffer(vmbuffer);
1242+
12391243
/* report that everything is now scanned */
12401244
pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_SCANNED,blkno);
12411245

1242-
/* Clear the block number information */
1243-
vacrel->blkno=InvalidBlockNumber;
1244-
12451246
/* now we can compute the new value for pg_class.reltuples */
12461247
vacrel->new_live_tuples=vac_estimate_reltuples(vacrel->rel,rel_pages,
12471248
vacrel->scanned_pages,
@@ -1256,15 +1257,9 @@ lazy_scan_heap(LVRelState *vacrel, int nworkers)
12561257
vacrel->missed_dead_tuples;
12571258

12581259
/*
1259-
* Release any remaining pin on visibility map page.
1260+
* Do index vacuuming (call each index's ambulkdelete routine), then do
1261+
* related heap vacuuming
12601262
*/
1261-
if (BufferIsValid(vmbuffer))
1262-
{
1263-
ReleaseBuffer(vmbuffer);
1264-
vmbuffer=InvalidBuffer;
1265-
}
1266-
1267-
/* Perform a final round of index and heap vacuuming */
12681263
if (dead_items->num_items>0)
12691264
lazy_vacuum(vacrel);
12701265

@@ -1278,16 +1273,9 @@ lazy_scan_heap(LVRelState *vacrel, int nworkers)
12781273
/* report all blocks vacuumed */
12791274
pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED,blkno);
12801275

1281-
/* Dopost-vacuumcleanup */
1276+
/* Dofinal indexcleanup (call each index's amvacuumcleanup routine) */
12821277
if (vacrel->nindexes>0&&vacrel->do_index_cleanup)
12831278
lazy_cleanup_all_indexes(vacrel);
1284-
1285-
/*
1286-
* Free resources managed by dead_items_alloc. This ends parallel mode in
1287-
* passing when necessary.
1288-
*/
1289-
dead_items_cleanup(vacrel);
1290-
Assert(!IsInParallelMode());
12911279
}
12921280

12931281
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp