pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Korotkov <a.korotkov@postgrespro.ru>
To: Piotr Stefaniak <postgres@piotr-stefaniak.me>
Cc: pgsql-committers@lists.postgresql.org <pgsql-committers@lists.postgresql.org>
Subject: Re: pgsql: Increase upper limit for vacuum_cleanup_index_scale_factor
Date: Mon, 15 Apr 2019 05:21:38 +0300
Message-ID: <CAPpHfdvQb8=kuCTH_m0zaVsWZ+hatmUdkGDFcL4UB5g67aJTQg@mail.gmail.com> (raw)
In-Reply-To: <DB8PR03MB5931C41F7787A95313F08322F22A0@DB8PR03MB5931.eurprd03.prod.outlook.com>
References: <E1fXnBp-0002z6-1o@gemulon.postgresql.org>
	<DB8PR03MB5931C41F7787A95313F08322F22A0@DB8PR03MB5931.eurprd03.prod.outlook.com>

Hi!

On Sun, Apr 14, 2019 at 11:00 PM Piotr Stefaniak
<postgres@piotr-stefaniak.me> wrote:
> On 26/06/2018 14.35, Alexander Korotkov wrote:
> > Increase upper limit for vacuum_cleanup_index_scale_factor
> >
> > Upper limits for vacuum_cleanup_index_scale_factor GUC and reloption
> > were initially set to 100.0 in 857f9c36.  However, after further
> > discussion, it appears that some users like to disable B-tree cleanup
> > index scan completely (assuming there are no deleted pages).
> >
> > vacuum_cleanup_index_scale_factor is used barely to protect against
> > stalled index statistics.  And after detailed consideration it appears
> > that risk of stalled index statistics is low.  And it would be nice to
> > allow advanced users setting higher values of
> > vacuum_cleanup_index_scale_factor.  So, set upper limit for these
> > GUC and reloption to DBL_MAX.
>
> UB Sanitizer points out that prev_num_heap_tuples is sometimes 0,
> leading to division by 0 in
>                         (info->num_heap_tuples - prev_num_heap_tuples) /
>                         prev_num_heap_tuples >= cleanup_scale_factor)
> which are currently lines 839-840 in nbtree.c.
>
> Attaching my idea of a fix.

Thank you for noticing.  BTW, I've more trivial idea for fixing this: replace
prev_num_heap_tuples < 0
with
prev_num_heap_tuples <= 0

If prev_num_heap_tuples == 0, subsequent part of expression isn't
evaluated because result is known to be true.  And I think it's right
to don't skip cleanup when prev_num_heap_tuples == 0.



------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

fix-division-by-zero-bt-vacuum-needs-cleanup.patch (application/octet-stream, 565B) download diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 7370379c6a1..02fb352b94a 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -835,7 +835,7 @@ _bt_vacuum_needs_cleanup(IndexVacuumInfo *info) prev_num_heap_tuples = metad->btm_last_cleanup_num_heap_tuples; if (cleanup_scale_factor <= 0 || - prev_num_heap_tuples < 0 || + prev_num_heap_tuples <= 0 || (info->num_heap_tuples - prev_num_heap_tuples) / prev_num_heap_tuples >= cleanup_scale_factor) result = true;

view thread (9+ messages)  latest in thread

Message-ID: <CAPpHfdvQb8=kuCTH_m0zaVsWZ+hatmUdkGDFcL4UB5g67aJTQg@mail.gmail.com>
Permalink:  ../CAPpHfdvQb8=kuCTH_m0zaVsWZ+hatmUdkGDFcL4UB5g67aJTQg@mail.gmail.com/
Also on:    postgresql.org/message-id/CAPpHfdvQb8=kuCTH_m0zaVsWZ+hatmUdkGDFcL4UB5g67aJTQg@mail.gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: a.korotkov@postgrespro.ru, postgres@piotr-stefaniak.me
  Subject: Re: pgsql: Increase upper limit for vacuum_cleanup_index_scale_factor
  In-Reply-To: <CAPpHfdvQb8=kuCTH_m0zaVsWZ+hatmUdkGDFcL4UB5g67aJTQg@mail.gmail.com>
  References: <E1fXnBp-0002z6-1o@gemulon.postgresql.org> <DB8PR03MB5931C41F7787A95313F08322F22A0@DB8PR03MB5931.eurprd03.prod.outlook.com> <CAPpHfdvQb8=kuCTH_m0zaVsWZ+hatmUdkGDFcL4UB5g67aJTQg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox