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

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Geoghegan <pg(at)bowt(dot)ie>
Subject: Re: Emit fewer vacuum records by reaping removable tuples during pruning
Date: 2024-01-05 23:57:02
Message-ID: CAAKRu_b6hKG-GCiJmxMssmCJ15e+2UR74PFwTiY9DXT9rduBLA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jan 5, 2024 at 2:47 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
> On 2024-01-04 17:37:27 -0500, Melanie Plageman wrote:
> > On Thu, Jan 4, 2024 at 3:03 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
> > >
> > > On 2023-11-17 18:12:08 -0500, Melanie Plageman wrote:
> > > > @@ -972,20 +970,21 @@ lazy_scan_heap(LVRelState *vacrel)
> > > > continue;
> > > > }
> > > >
> > > > - /* Collect LP_DEAD items in dead_items array, count tuples */
> > > > - if (lazy_scan_noprune(vacrel, buf, blkno, page, &hastup,
> > > > + /*
> > > > + * Collect LP_DEAD items in dead_items array, count tuples,
> > > > + * determine if rel truncation is safe
> > > > + */
> > > > + if (lazy_scan_noprune(vacrel, buf, blkno, page,
> > > > &recordfreespace))
> > > > {
> > > > Size freespace = 0;
> > > >
> > > > /*
> > > > * Processed page successfully (without cleanup lock) -- just
> > > > - * need to perform rel truncation and FSM steps, much like the
> > > > - * lazy_scan_prune case. Don't bother trying to match its
> > > > - * visibility map setting steps, though.
> > > > + * need to update the FSM, much like the lazy_scan_prune case.
> > > > + * Don't bother trying to match its visibility map setting
> > > > + * steps, though.
> > > > */
> > > > - if (hastup)
> > > > - vacrel->nonempty_pages = blkno + 1;
> > > > if (recordfreespace)
> > > > freespace = PageGetHeapFreeSpace(page);
> > > > UnlockReleaseBuffer(buf);
> > >
> > > The comment continues to say that we "determine if rel truncation is safe" -
> > > but I don't see that? Oh, I see, it's done inside lazy_scan_noprune(). This
> > > doesn't seem like a clear improvement to me. Particularly because it's only
> > > set if lazy_scan_noprune() actually does something.
> >
> > I don't get what the last sentence means ("Particularly because...").
>
> Took me a second to understand myself again too, oops. What I think I meant is
> that it seems error-prone that it's only set in some paths inside
> lazy_scan_noprune(). Previously it was at least a bit clearer in
> lazy_scan_heap() that it would be set for the different possible paths.

I see what you are saying. But if lazy_scan_noprune() doesn't do
anything, then it calls lazy_scan_prune(), which does set hastup and
update vacrel->nonempty_pages if needed.

Using hastup in lazy_scan_[no]prune() also means that they are
directly updating LVRelState after determining how to update it.
lazy_scan_heap() isn't doing responsible anymore. I don't see a reason
to be passing information back to lazy_scan_heap() to update
LVRelState when lazy_scan_[no]prune() has access to the LVRelState.

Importantly, once I combine the prune and freeze records, hastup is
set in heap_page_prune() instead of lazy_scan_prune() (that whole loop
in lazy_scan_prune() is eliminated()). And I don't like having to pass
hastup back through lazy_scan_prune() and then to lazy_scan_heap() so
that lazy_scan_heap() can use it (and use it to update a data
structure available in lazy_scan_prune()).

- Melanie

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Cheshev 2024-01-06 00:00:04 Re: Multidimensional Histograms
Previous Message Nathan Bossart 2024-01-05 23:03:57 Re: Improve the log message output of basic_archive when basic_archive.archive_directory parameter is not set