Adjust lazy_scan_heap() accounting comments.
authorPeter Geoghegan <[email protected]>
Mon, 15 Feb 2021 03:28:37 +0000 (19:28 -0800)
committerPeter Geoghegan <[email protected]>
Mon, 15 Feb 2021 03:28:37 +0000 (19:28 -0800)
Explain which particular LP_DEAD line pointers get accounted for by the
tups_vacuumed variable.

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

index e3a716a2a2f24013bb0dabf97cc263060a15d20d..8bb38d6406e5e8e0520aa1d1322a94d2c1f7067a 100644 (file)
@@ -213,11 +213,12 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
  * send its own new total to pgstats, and we don't want this delta applied
  * on top of that.)
  *
+ * Sets latestRemovedXid for caller on return.
+ *
  * off_loc is the offset location required by the caller to use in error
  * callback.
  *
- * Returns the number of tuples deleted from the page and sets
- * latestRemovedXid.
+ * Returns the number of tuples deleted from the page during this call.
  */
 int
 heap_page_prune(Relation relation, Buffer buffer,
index f3d2265fad7e4bfc3759f27589a138e3adaeffec..e9bd6dba80f758c6392eff5825e50b1d35e89fc8 100644 (file)
@@ -765,9 +765,9 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
                next_fsm_block_to_vacuum;
    double      num_tuples,     /* total number of nonremovable tuples */
                live_tuples,    /* live tuples (reltuples estimate) */
-               tups_vacuumed,  /* tuples cleaned up by vacuum */
+               tups_vacuumed,  /* tuples cleaned up by current vacuum */
                nkeep,          /* dead-but-not-removable tuples */
-               nunused;        /* unused line pointers */
+               nunused;        /* # existing unused line pointers */
    IndexBulkDeleteResult **indstats;
    int         i;
    PGRUsage    ru0;
@@ -1234,7 +1234,8 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
        /*
         * Prune all HOT-update chains in this page.
         *
-        * We count tuples removed by the pruning step as removed by VACUUM.
+        * We count tuples removed by the pruning step as removed by VACUUM
+        * (existing LP_DEAD line pointers don't count).
         */
        tups_vacuumed += heap_page_prune(onerel, buf, vistest, false,
                                         InvalidTransactionId, 0,
@@ -1286,10 +1287,13 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
            ItemPointerSet(&(tuple.t_self), blkno, offnum);
 
            /*
-            * DEAD line pointers are to be vacuumed normally; but we don't
+            * LP_DEAD line pointers are to be vacuumed normally; but we don't
             * count them in tups_vacuumed, else we'd be double-counting (at
             * least in the common case where heap_page_prune() just freed up
-            * a non-HOT tuple).
+            * a non-HOT tuple).  Note also that the final tups_vacuumed value
+            * might be very low for tables where opportunistic page pruning
+            * happens to occur very frequently (via heap_page_prune_opt()
+            * calls that free up non-HOT tuples).
             */
            if (ItemIdIsDead(itemid))
            {
@@ -1742,10 +1746,6 @@ lazy_scan_heap(Relation onerel, VacuumParams *params, LVRelStats *vacrelstats,
                        vacrelstats->relname,
                        tups_vacuumed, vacuumed_pages)));
 
-   /*
-    * This is pretty messy, but we split it up so that we can skip emitting
-    * individual parts of the message when not applicable.
-    */
    initStringInfo(&buf);
    appendStringInfo(&buf,
                     _("%.0f dead row versions cannot be removed yet, oldest xmin: %u\n"),