Re: Do BRIN indexes support MIN/MAX? - Mailing list pgsql-general

From Vladimir Sitnikov
Subject Re: Do BRIN indexes support MIN/MAX?
Date
Msg-id CAB=Je-HrTBzFGvR2RdAyXVm8bAFVZzteXPX=QcEiQRLvan74VA@mail.gmail.com
Whole thread Raw
In response to Re: Do BRIN indexes support MIN/MAX?  (Julien Rouhaud <rjuju123@gmail.com>)
List 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Do BRIN indexes support MIN/MAX?
Next
From: David Rowley
Date:
Subject: Re: Do BRIN indexes support MIN/MAX?