Add empty BRIN ranges during CREATE INDEX
authorTomas Vondra <tomas.vondra@postgresql.org>
Fri, 8 Dec 2023 16:07:30 +0000 (17:07 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Fri, 8 Dec 2023 16:14:32 +0000 (17:14 +0100)
commitdae761a87edae444d11a411f711f1d679bed5941
tree9c98e722318c9390a8c971b32538adadcc1a4bc1
parent00edb2061fcf288574b7b5c0be67fab71f7e136b
Add empty BRIN ranges during CREATE INDEX

When building BRIN indexes, the brinbuildCallback only advances to the
next page range when seeing a tuple that doesn't belong to the current
one. This means that the index may end up missing ranges at the end of
the table, if those pages do not contain any indexable tuples.

We tend not to have completely empty pages at the end of a relation, but
this also applies to partial indexes, where the tuples may simply not
match the index predicate. This results in inefficient scans using the
affected BRIN index - without the summaries, the page ranges have to be
read and processed, which consumes I/O and possibly also CPU time.

The existing code already added empty ranges for earlier parts of the
table, this commit makes sure we add them for the ranges at the end of
the table too.

Patch by Matthias van de Meent, with review/improvements by me.

Author: Matthias van de Meent
Reviewed-by: Tomas Vondra
Discussion: https://postgr.es/m/CAEze2WiMsPZg%3DxkvSF_jt4%3D69k6K7gz5B8V2wY3gCGZ%2B1BzCbQ%40mail.gmail.com
contrib/pageinspect/expected/brin.out
contrib/pageinspect/sql/brin.sql
src/backend/access/brin/brin.c