Re: Do BRIN indexes support MIN/MAX?

From: Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>
To: Julien Rouhaud <rjuju123(at)gmail(dot)com>
Cc: Andrey Klochkov <diggerk(at)gmail(dot)com>, Francisco Olarte <folarte(at)peoplecall(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:19:07
Message-ID: CAB=Je-HrTBzFGvR2RdAyXVm8bAFVZzteXPX=QcEiQRLvan74VA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> so you can't deduce in which range the current min or max value is from
there.

That is why you select several candidate ranges and scan the table for
those ranges.

For instance, if you have ranges
1) 1..4
2) 5..8
3) 6..9

Then you do something like

select x
from (
select max(col) x from tab t where rowid in 5..8 or rowid in 6..9
union all
selext max(col) x from tab t where rowid in 1..4
)
limit 1

If the first two (2 and 3) ranges happen to be empty, then scanning of 1
would be needed.

Of course, it would degrade to scanning all the pages in table if all the
ranges intersect or if all the rows are deleted from the table. However, it
might work well in timestamp-like cases.

Vladimir

--
Vladimir

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2023-03-30 04:44:01 Re: Do BRIN indexes support MIN/MAX?
Previous Message Tom Lane 2023-03-30 04:18:28 Re: Do BRIN indexes support MIN/MAX?