Re: Do BRIN indexes support MIN/MAX?

From: Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>
To: Andrey Klochkov <diggerk(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Francisco Olarte <folarte(at)peoplecall(dot)com>, Julien Rouhaud <rjuju123(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Do BRIN indexes support MIN/MAX?
Date: 2023-03-30 04:57:48
Message-ID: CAB=Je-HGr6DUvdBXMbkutdn7Bh+BkCUK+YghSpcN9kmwWBf1Yw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> You could for example (when looking for a MAX) skip scanning
block ranges whose indexed MAX is less than the indexed MIN of some
other block range.

When looking for a max, you could scan the range with the maximal indexed
MAX, and then you could skip all the ranges that have MAX less than the
already found max value. You can use any found value as a cutoff point.

You do not need to have much hackery as you can scan the most promising
range first, and then scan the others if the most promising did not yield
value which is known to exceed all the other ranges.

So find_min and find_max can be pretty efficient with BRIN.
I’m not sure regarding the practical use of that though.

Top N can be implemented in the same way by passing all the values to a
binary heap and skipping all the ranges that are known to be less than what
we already have in a heap.

Andrey, could you clarify the use cases for looking up of min/max record?
I am afraid, PostgreSQL has no way to represent “this access method
supports min/max retrieval”, and what currently exists is “this access
method supports ordered scans sorted by the indexed column’s value”
Apparently, implementing ordered BRIN scan would be harder (from
implementation, costing, and testing point of views), so it would be nice
to hear on the use cases for having min/max am scans or for having BRIN
ordered scans.

Vladimir

--
Vladimir

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message houzj.fnst@fujitsu.com 2023-03-30 06:37:10 RE: Support logical replication of DDLs
Previous Message David Rowley 2023-03-30 04:44:01 Re: Do BRIN indexes support MIN/MAX?