Re: Emit fewer vacuum records by reaping removable tuples during pruning

Robert Haas <robertmhaas@gmail.com>

From: Robert Haas <robertmhaas@gmail.com>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, Peter Geoghegan <pg@bowt.ie>, Pg Hackers <pgsql-hackers@postgresql.org>, Andres Freund <andres@anarazel.de>
Date: 2024-01-10T20:54:40Z
Lists: pgsql-hackers
On Tue, Jan 9, 2024 at 5:42 PM Melanie Plageman
<melanieplageman@gmail.com> wrote:
> Done in attached v6.

Don't kill me, but:

+                       /*
+                        * For now, pass no_indexes == false
regardless of whether or not
+                        * the relation has indexes. In the future we
may enable immediate
+                        * reaping for on access pruning.
+                        */
+                       heap_page_prune(relation, buffer, vistest, false,
+                                                       &presult, NULL);

My previous comments about lying seem equally applicable here.

-               if (!ItemIdIsUsed(itemid) || ItemIdIsDead(itemid))
+               if (!ItemIdIsUsed(itemid))
                        continue;

There is a bit of overhead here for the !no_indexes case. I assume it
doesn't matter.

 static void
 heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum)
 {
+       /*
+        * If the relation has no indexes, we can remove dead tuples during
+        * pruning instead of marking their line pointers dead. Set this tuple's
+        * line pointer LP_UNUSED. We hint that tables with indexes are more
+        * likely.
+        */
+       if (unlikely(prstate->no_indexes))
+       {
+               heap_prune_record_unused(prstate, offnum);
+               return;
+       }

I think this should be pushed to the callers. Else you make the
existing function name into another lie.

+       bool            recordfreespace;

Not sure if it's necessary to move this to an outer scope like this?
The whole handling of this looks kind of confusing. If we're going to
do it this way, then I think lazy_scan_prune() definitely needs to
document how it handles this function (i.e. might set true to false,
won't set false to true, also meaning). But are we sure we want to let
a local variable with a weird name "leak out" like this?

+       Assert(vacrel->do_index_vacuuming);

Is this related?

-- 
Robert Haas
EDB: http://www.enterprisedb.com



Commits

  1. Combine FSM updates for prune and no-prune cases.

  2. Remove LVPagePruneState.

  3. Move VM update code from lazy_scan_heap() to lazy_scan_prune().

  4. Optimize vacuuming of relations with no indexes.

  5. Be more consistent about whether to update the FSM while vacuuming.

  6. Remove hastup from LVPagePruneState.

  7. Use scanned_pages to decide when to failsafe check.

  8. Simplify lazy_scan_heap's handling of scanned pages.

  9. While vacuuming a large table, update upper-level FSM data every so often.