pgsql: Add bound check before bsearch() for performance

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add bound check before bsearch() for performance
Date: 2021-03-10 14:52:31
Message-ID: E1lK0CN-0001GJ-7o@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add bound check before bsearch() for performance

In the current lazy vacuum implementation, some index AMs such as
btree indexes call lazy_tid_reaped() for each index tuple during
ambulkdelete to check if the index tuple points to the (collected)
garbage tuple. In that function, we simply call bsearch(), but we
should be able to know the result without bsearch() if the index tuple
points to the heap tuple that is out of range of the collected garbage
tuples. Therefore, add a simple bound check before resorting to
bsearch(). Testing has shown that this can give significant
performance benefits.

Author: Masahiko Sawada <masahiko(dot)sawada(at)2ndquadrant(dot)com>
Discussion: https://www.postgresql.org/message-id/flat/CA+fd4k76j8jKzJzcx8UqEugvayaMSnQz0iLUt_XgBp-_-bd22A(at)mail(dot)gmail(dot)com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/bbaf315309ed1194d451326cc8f4f59a45906408

Modified Files
--------------
src/backend/access/heap/vacuumlazy.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2021-03-10 16:34:10 pgsql: Doc: improve introductory information about procedures.
Previous Message Thomas Munro 2021-03-10 10:21:29 Re: pgsql: pgbench: Refactor thread portability support.