@@ -158,6 +158,9 @@ static bool lazy_check_needs_freeze(Buffer buf, bool *hastup);
158
158
static void lazy_vacuum_index(Relation indrel,
159
159
IndexBulkDeleteResult **stats,
160
160
LVRelStats *vacrelstats);
161
+ static void lazy_vacuum_all_indexes(Relation onerel, LVRelStats *vacrelstats,
162
+ Relation *Irel, int nindexes,
163
+ IndexBulkDeleteResult **indstats);
161
164
static void lazy_cleanup_index(Relation indrel,
162
165
IndexBulkDeleteResult *stats,
163
166
LVRelStats *vacrelstats);
@@ -740,12 +743,6 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
740
743
if ((vacrelstats->max_dead_tuples - vacrelstats->num_dead_tuples) < MaxHeapTuplesPerPage &&
741
744
vacrelstats->num_dead_tuples > 0)
742
745
{
743
- const int hvp_index[] = {
744
- PROGRESS_VACUUM_PHASE,
745
- PROGRESS_VACUUM_NUM_INDEX_VACUUMS
746
- };
747
- int64 hvp_val[2];
748
-
749
746
/*
750
747
* Before beginning index vacuuming, we release any pin we may
751
748
* hold on the visibility map page. This isn't necessary for
@@ -758,28 +755,9 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
758
755
vmbuffer = InvalidBuffer;
759
756
}
760
757
761
- /* Log cleanup info before we touch indexes */
762
- vacuum_log_cleanup_info(onerel, vacrelstats);
763
-
764
- /* Report that we are now vacuuming indexes */
765
- pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
766
- PROGRESS_VACUUM_PHASE_VACUUM_INDEX);
767
-
768
- /* Remove index entries */
769
- for (i = 0; i < nindexes; i++)
770
- lazy_vacuum_index(Irel[i],
771
- &indstats[i],
772
- vacrelstats);
773
-
774
- /*
775
- * Report that we are now vacuuming the heap. We also increase
776
- * the number of index scans here; note that by using
777
- * pgstat_progress_update_multi_param we can update both
778
- * parameters atomically.
779
- */
780
- hvp_val[0] = PROGRESS_VACUUM_PHASE_VACUUM_HEAP;
781
- hvp_val[1] = vacrelstats->num_index_scans + 1;
782
- pgstat_progress_update_multi_param(2, hvp_index, hvp_val);
758
+ /* Work on all the indexes, then the heap */
759
+ lazy_vacuum_all_indexes(onerel, vacrelstats, Irel,
760
+ nindexes, indstats);
783
761
784
762
/* Remove tuples from heap */
785
763
lazy_vacuum_heap(onerel, vacrelstats);
@@ -790,7 +768,6 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
790
768
* valid.
791
769
*/
792
770
vacrelstats->num_dead_tuples = 0;
793
- vacrelstats->num_index_scans++;
794
771
795
772
/*
796
773
* Vacuum the Free Space Map to make newly-freed space visible on
@@ -1420,33 +1397,12 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
1420
1397
/* XXX put a threshold on min number of tuples here? */
1421
1398
if (vacrelstats->num_dead_tuples > 0)
1422
1399
{
1423
- const int hvp_index[] = {
1424
- PROGRESS_VACUUM_PHASE,
1425
- PROGRESS_VACUUM_NUM_INDEX_VACUUMS
1426
- };
1427
- int64 hvp_val[2];
1428
-
1429
- /* Log cleanup info before we touch indexes */
1430
- vacuum_log_cleanup_info(onerel, vacrelstats);
1431
-
1432
- /* Report that we are now vacuuming indexes */
1433
- pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
1434
- PROGRESS_VACUUM_PHASE_VACUUM_INDEX);
1435
-
1436
- /* Remove index entries */
1437
- for (i = 0; i < nindexes; i++)
1438
- lazy_vacuum_index(Irel[i],
1439
- &indstats[i],
1440
- vacrelstats);
1441
-
1442
- /* Report that we are now vacuuming the heap */
1443
- hvp_val[0] = PROGRESS_VACUUM_PHASE_VACUUM_HEAP;
1444
- hvp_val[1] = vacrelstats->num_index_scans + 1;
1445
- pgstat_progress_update_multi_param(2, hvp_index, hvp_val);
1400
+ /* Work on all the indexes, and then the heap */
1401
+ lazy_vacuum_all_indexes(onerel, vacrelstats, Irel, nindexes,
1402
+ indstats);
1446
1403
1447
1404
/* Remove tuples from heap */
1448
1405
lazy_vacuum_heap(onerel, vacrelstats);
1449
- vacrelstats->num_index_scans++;
1450
1406
}
1451
1407
1452
1408
/*
@@ -1508,6 +1464,36 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
1508
1464
pfree(buf.data);
1509
1465
}
1510
1466
1467
+ /*
1468
+ * lazy_vacuum_all_indexes() -- vacuum all indexes of relation.
1469
+ *
1470
+ * This is a utility wrapper for lazy_vacuum_index(), able to do
1471
+ * progress reporting.
1472
+ */
1473
+ static void
1474
+ lazy_vacuum_all_indexes(Relation onerel, LVRelStats *vacrelstats,
1475
+ Relation *Irel, int nindexes,
1476
+ IndexBulkDeleteResult **indstats)
1477
+ {
1478
+ int i;
1479
+
1480
+ /* Log cleanup info before we touch indexes */
1481
+ vacuum_log_cleanup_info(onerel, vacrelstats);
1482
+
1483
+ /* Report that we are now vacuuming indexes */
1484
+ pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
1485
+ PROGRESS_VACUUM_PHASE_VACUUM_INDEX);
1486
+
1487
+ /* Remove index entries */
1488
+ for (i = 0; i < nindexes; i++)
1489
+ lazy_vacuum_index(Irel[i], &indstats[i], vacrelstats);
1490
+
1491
+ /* Increase and report the number of index scans */
1492
+ vacrelstats->num_index_scans++;
1493
+ pgstat_progress_update_param(PROGRESS_VACUUM_NUM_INDEX_VACUUMS,
1494
+ vacrelstats->num_index_scans);
1495
+ }
1496
+
1511
1497
1512
1498
/*
1513
1499
* lazy_vacuum_heap() -- second pass over the heap
@@ -1528,6 +1514,10 @@ lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats)
1528
1514
PGRUsage ru0;
1529
1515
Buffer vmbuffer = InvalidBuffer;
1530
1516
1517
+ /* Report that we are now vacuuming the heap */
1518
+ pgstat_progress_update_param(PROGRESS_VACUUM_PHASE,
1519
+ PROGRESS_VACUUM_PHASE_VACUUM_HEAP);
1520
+
1531
1521
pg_rusage_init(&ru0);
1532
1522
npages = 0;
1533
1523
0 commit comments