Re: Boundary value check in lazy_tid_reaped()

From: Masahiko Sawada <masahiko(dot)sawada(at)2ndquadrant(dot)com>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Boundary value check in lazy_tid_reaped()
Date: 2020-09-08 08:23:04
Message-ID: CA+fd4k6eFB8=17ArZj5mT4O8tPn-qFb-KdchNLMFMCEb1AbhKg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 1 Sep 2020 at 04:44, Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:
>
> On Tue, Sep 1, 2020 at 7:21 AM Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:
> > On Sun, Aug 30, 2020 at 11:08 PM Masahiko Sawada
> > <masahiko(dot)sawada(at)2ndquadrant(dot)com> wrote:
> > > So my proposal is to add boundary value check in lazy_tid_reaped()
> > > before executing bsearch(3). This will help when index vacuum happens
> > > multiple times or when garbage tuples are concentrated to a narrow
> > > range.
> >
> > Makes sense if it's often out of range.
>
> ... though I'm not sure why you need to add extra members to do it?

Indeed. We can use the first and last elements of itemptrs array.

>
> > > I thought that we can have a generic function wrapping bsearch(3) that
> > > does boundary value checks and then does bsearch(3) so that we can use
> > > it in other similar places as well. But the attached patch doesn't do
> > > that as I'd like to hear opinions on the proposal first.
> >
> > I wonder if you would also see a speed-up with a bsearch() replacement
> > that is inlineable, so it can inline the comparator (instead of
> > calling it through a function pointer). I wonder if something more
> > like (lblk << 32 | loff) - (rblk << 32 | roff) would go faster than
> > the branchy comparator.
>
> Erm, off course that expression won't work... should be << 16, but
> even then it would only work with a bsearch that uses int64_t
> comparators, so I take that part back.

Yeah, it seems to worth benchmarking the speed-up with an inlining.
I'll do some performance tests with/without inlining on top of
checking boundary values.

Regards,

--
Masahiko Sawada http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2020-09-08 08:23:23 Re: Internal key management system
Previous Message Peter Eisentraut 2020-09-08 08:12:16 Re: Fix for configure error in 9.5/9.6 on macOS 11.0 Big Sur