Re: PATCH: Using BRIN indexes for sorted output

2024-02-01 Thread vignesh C
On Sun, 21 Jan 2024 at 07:32, vignesh C wrote: > > On Wed, 2 Aug 2023 at 21:34, Tomas Vondra > wrote: > > > > > > > > On 8/2/23 17:25, Sergey Dudoladov wrote: > > > Hello, > > > > > >> Parallel version is not supported, but I think it should be possible. > > > > > > @Tomas are you working on thi

Re: PATCH: Using BRIN indexes for sorted output

2024-01-20 Thread vignesh C
On Wed, 2 Aug 2023 at 21:34, Tomas Vondra wrote: > > > > On 8/2/23 17:25, Sergey Dudoladov wrote: > > Hello, > > > >> Parallel version is not supported, but I think it should be possible. > > > > @Tomas are you working on this ? If not, I would like to give it a try. > > > > Feel free to try. Just

Re: PATCH: Using BRIN indexes for sorted output

2023-08-02 Thread Tomas Vondra
On 8/2/23 17:25, Sergey Dudoladov wrote: > Hello, > >> Parallel version is not supported, but I think it should be possible. > > @Tomas are you working on this ? If not, I would like to give it a try. > Feel free to try. Just keep it in a separate part/patch, to make it easier to combine the

Re: PATCH: Using BRIN indexes for sorted output

2023-08-02 Thread Sergey Dudoladov
Hello, > Parallel version is not supported, but I think it should be possible. @Tomas are you working on this ? If not, I would like to give it a try. > static void > AssertCheckRanges(BrinSortState *node) > { > #ifdef USE_ASSERT_CHECKING > > #endif > } I guess it should not be empty at the ong

Re: PATCH: Using BRIN indexes for sorted output

2023-07-14 Thread Tomas Vondra
On 7/14/23 16:42, Matthias van de Meent wrote: > On Fri, 14 Jul 2023 at 16:21, Tomas Vondra > wrote: >> >> >> >> >> On 7/11/23 13:20, Matthias van de Meent wrote: >>> On Mon, 10 Jul 2023 at 22:04, Tomas Vondra >>> wrote: Approximation in what sense? My understanding was we'd get a range o

Re: PATCH: Using BRIN indexes for sorted output

2023-07-14 Thread Matthias van de Meent
On Fri, 14 Jul 2023 at 16:21, Tomas Vondra wrote: > > > > > On 7/11/23 13:20, Matthias van de Meent wrote: >> On Mon, 10 Jul 2023 at 22:04, Tomas Vondra >> wrote: >>> Approximation in what sense? My understanding was we'd get a range of >>> distances that we know covers all rows in that range. So

Re: PATCH: Using BRIN indexes for sorted output

2023-07-14 Thread Tomas Vondra
On 7/11/23 13:20, Matthias van de Meent wrote: > On Mon, 10 Jul 2023 at 22:04, Tomas Vondra > wrote: >> On 7/10/23 18:18, Matthias van de Meent wrote: >>> On Mon, 10 Jul 2023 at 17:09, Tomas Vondra >>> wrote: On 7/10/23 14:38, Matthias van de Meent wrote: >> I haven't really thought

Re: PATCH: Using BRIN indexes for sorted output

2023-07-11 Thread Matthias van de Meent
On Mon, 10 Jul 2023 at 22:04, Tomas Vondra wrote: > On 7/10/23 18:18, Matthias van de Meent wrote: >> On Mon, 10 Jul 2023 at 17:09, Tomas Vondra >> wrote: >>> On 7/10/23 14:38, Matthias van de Meent wrote: > I haven't really thought about geometric types, just about minmax and > minmax-mu

Re: PATCH: Using BRIN indexes for sorted output

2023-07-10 Thread Tomas Vondra
On 7/10/23 18:18, Matthias van de Meent wrote: > On Mon, 10 Jul 2023 at 17:09, Tomas Vondra > wrote: >> On 7/10/23 14:38, Matthias van de Meent wrote: >>> Kind of. For single-dimensional opclasses (minmax, minmax_multi) we >>> only need to extract the normal min/max values for ASC/DESC sorts, >

Re: PATCH: Using BRIN indexes for sorted output

2023-07-10 Thread Matthias van de Meent
On Mon, 10 Jul 2023 at 17:09, Tomas Vondra wrote: > On 7/10/23 14:38, Matthias van de Meent wrote: >> Kind of. For single-dimensional opclasses (minmax, minmax_multi) we >> only need to extract the normal min/max values for ASC/DESC sorts, >> which are readily available in the summary. But for mul

Re: PATCH: Using BRIN indexes for sorted output

2023-07-10 Thread Matthias van de Meent
On Mon, 10 Jul 2023 at 13:43, Tomas Vondra wrote: > On 7/10/23 12:22, Matthias van de Meent wrote: >> On Fri, 7 Jul 2023 at 20:26, Tomas Vondra >> wrote: >>> However, it's not quite clear to me is what you mean by the weight- and >>> compare-operators? That is, what are >>> >>> - brin_minmax_mi

Re: PATCH: Using BRIN indexes for sorted output

2023-07-10 Thread Tomas Vondra
On 7/10/23 12:22, Matthias van de Meent wrote: > On Fri, 7 Jul 2023 at 20:26, Tomas Vondra > wrote: >> >> Hi, >> >> I finally had time to look at this patch again. There's a bit of bitrot, >> so here's a rebased version (no other changes). > > Thanks! > >> On 2/27/23 16:40, Matthias van de M

Re: PATCH: Using BRIN indexes for sorted output

2023-07-10 Thread Matthias van de Meent
On Fri, 7 Jul 2023 at 20:26, Tomas Vondra wrote: > > Hi, > > I finally had time to look at this patch again. There's a bit of bitrot, > so here's a rebased version (no other changes). Thanks! > On 2/27/23 16:40, Matthias van de Meent wrote: > > Some initial comments on 0004: > > > >> +/* > >> +

Re: PATCH: Using BRIN indexes for sorted output

2023-07-07 Thread Tomas Vondra
Hi, I finally had time to look at this patch again. There's a bit of bitrot, so here's a rebased version (no other changes). [more comments inline] On 2/27/23 16:40, Matthias van de Meent wrote: > Hi, > > On Thu, 23 Feb 2023 at 17:44, Matthias van de Meent > wrote: >> >> I'll see to further re

Re: PATCH: Using BRIN indexes for sorted output

2023-03-01 Thread Alvaro Herrera
On 2023-Feb-24, Tomas Vondra wrote: > On 2/24/23 16:14, Alvaro Herrera wrote: > > I think a formulation of this kind has the benefit that it works after > > BlockNumber is enlarged to 64 bits, and doesn't have to be changed ever > > again (assuming it is correct). > > Did anyone even propose doi

Re: PATCH: Using BRIN indexes for sorted output

2023-02-27 Thread Matthias van de Meent
Hi, On Thu, 23 Feb 2023 at 17:44, Matthias van de Meent wrote: > > I'll see to further reviewing 0004 and 0005 when I have additional time. Some initial comments on 0004: > +/* > + * brin_minmax_ranges > + *Load the BRIN ranges and sort them. > + */ > +Datum > +brin_minmax_ranges(PG_FUN

Re: PATCH: Using BRIN indexes for sorted output

2023-02-27 Thread Matthias van de Meent
On Fri, 24 Feb 2023, 20:14 Tomas Vondra, wrote: > > On 2/24/23 19:03, Matthias van de Meent wrote: > > On Thu, 23 Feb 2023 at 19:48, Tomas Vondra > >> Yeah, that sounds like a bug. Also a sign the tests should have some > >> by-ref data types (presumably there are none, as that would certainly > >

Re: PATCH: Using BRIN indexes for sorted output

2023-02-24 Thread Tomas Vondra
On 2/24/23 19:03, Matthias van de Meent wrote: > On Thu, 23 Feb 2023 at 19:48, Tomas Vondra > wrote: >> >> On 2/23/23 17:44, Matthias van de Meent wrote: >>> On Thu, 23 Feb 2023 at 16:22, Tomas Vondra >>> wrote: On 2/23/23 15:19, Matthias van de Meent wrote: > Comments on 0001, m

Re: PATCH: Using BRIN indexes for sorted output

2023-02-24 Thread Matthias van de Meent
On Thu, 23 Feb 2023 at 19:48, Tomas Vondra wrote: > > On 2/23/23 17:44, Matthias van de Meent wrote: > > On Thu, 23 Feb 2023 at 16:22, Tomas Vondra > > wrote: > >> > >> On 2/23/23 15:19, Matthias van de Meent wrote: > >>> Comments on 0001, mostly comments and patch design: > > > > One more commen

Re: PATCH: Using BRIN indexes for sorted output

2023-02-24 Thread Matthias van de Meent
On Fri, 24 Feb 2023 at 17:04, Tomas Vondra wrote: > > On 2/24/23 16:14, Alvaro Herrera wrote: > > ... if pagesPerRange is not a whole divisor of MaxBlockNumber, I think > > this will neglect the last range in the table. > > > > Why would it? Let's say BlockNumber is uint8, i.e. 255 max. And there

Re: PATCH: Using BRIN indexes for sorted output

2023-02-24 Thread Tomas Vondra
On 2/24/23 16:14, Alvaro Herrera wrote: > On 2023-Feb-24, Tomas Vondra wrote: > >> I guess the easiest fix would be to do the arithmetic in 64 bits. That'd >> eliminate the overflow. > > Yeah, that might be easy to set up. We then don't have to worry about > it until BlockNumber is enlarged t

Re: PATCH: Using BRIN indexes for sorted output

2023-02-24 Thread Alvaro Herrera
On 2023-Feb-24, Tomas Vondra wrote: > I guess the easiest fix would be to do the arithmetic in 64 bits. That'd > eliminate the overflow. Yeah, that might be easy to set up. We then don't have to worry about it until BlockNumber is enlarged to 64 bits ... but by that time surely we can just grow

Re: PATCH: Using BRIN indexes for sorted output

2023-02-24 Thread Tomas Vondra
On 2/24/23 09:39, Alvaro Herrera wrote: > On 2023-Feb-23, Matthias van de Meent wrote: > >>> + for (heapBlk = 0; heapBlk < nblocks; heapBlk += pagesPerRange) >> >> I am not familiar with the frequency of max-sized relations, but this >> would go into an infinite loop for pagesPerRange values >1

Re: PATCH: Using BRIN indexes for sorted output

2023-02-24 Thread Alvaro Herrera
On 2023-Feb-23, Matthias van de Meent wrote: > > + for (heapBlk = 0; heapBlk < nblocks; heapBlk += pagesPerRange) > > I am not familiar with the frequency of max-sized relations, but this > would go into an infinite loop for pagesPerRange values >1 for > max-sized relations due to BlockNumber wra

Re: PATCH: Using BRIN indexes for sorted output

2023-02-23 Thread Tomas Vondra
On 2/23/23 17:44, Matthias van de Meent wrote: > On Thu, 23 Feb 2023 at 16:22, Tomas Vondra > wrote: >> >> On 2/23/23 15:19, Matthias van de Meent wrote: >>> Comments on 0001, mostly comments and patch design: > > One more comment: > + range->min_value = bval->bv_values[0]; + range->ma

Re: PATCH: Using BRIN indexes for sorted output

2023-02-23 Thread Matthias van de Meent
On Thu, 23 Feb 2023 at 16:22, Tomas Vondra wrote: > > On 2/23/23 15:19, Matthias van de Meent wrote: >> Comments on 0001, mostly comments and patch design: One more comment: >>> + range->min_value = bval->bv_values[0]; >>> + range->max_value = bval->bv_values[1]; This produces dangling pointers

Re: PATCH: Using BRIN indexes for sorted output

2023-02-23 Thread Tomas Vondra
On 2/23/23 15:19, Matthias van de Meent wrote: > On Sat, 18 Feb 2023 at 16:55, Tomas Vondra > wrote: >> >> cfbot complained there's one more place triggering a compiler warning on >> 32-bit systems, so here's a version fixing that. >> >> I've also added a copy of the regression tests but using the

Re: PATCH: Using BRIN indexes for sorted output

2023-02-23 Thread Matthias van de Meent
On Sat, 18 Feb 2023 at 16:55, Tomas Vondra wrote: > > cfbot complained there's one more place triggering a compiler warning on > 32-bit systems, so here's a version fixing that. > > I've also added a copy of the regression tests but using the indexam > stats added in 0001. This is just a copy of t

Re: PATCH: Using BRIN indexes for sorted output

2023-02-18 Thread Tomas Vondra
On 2/18/23 19:51, Justin Pryzby wrote: > Are (any of) these patches targetting v16 ? > Probably not. Maybe if there's more feedback / scrutiny, but I'm not sure one commitfest is enough to polish the patch (especially considering I haven't done much on the costing yet). > typos: > ar we - we are

Re: PATCH: Using BRIN indexes for sorted output

2023-02-18 Thread Justin Pryzby
Are (any of) these patches targetting v16 ? typos: ar we - we are? morestly - mostly interstect - intersect > + * XXX We don't sort the bins, so just do binary sort. For large number of > values > + * this might be an issue, for small number of values a linear search is > fine. "binary sort" i

Re: PATCH: Using BRIN indexes for sorted output

2023-02-16 Thread Justin Pryzby
On Thu, Feb 16, 2023 at 03:07:59PM +0100, Tomas Vondra wrote: > Rebased version of the patches, fixing only minor conflicts. Per cfbot, the patch fails on 32 bit builds. +ERROR: count mismatch: 0 != 1000 And causes warnings in mingw cross-compile. On Sun, Oct 23, 2022 at 11:32:37PM -0500, Justi

Re: PATCH: Using BRIN indexes for sorted output

2022-12-06 Thread Andres Freund
Hi, On 2022-11-17 00:52:35 +0100, Tomas Vondra wrote: > Well, yeah. That's pretty much exactly what the last version of this > patch (from October 23) does. That version unfortunately doesn't build successfully: https://cirrus-ci.com/task/5108789846736896 [03:02:48.641] Duplicate OIDs detected:

Re: PATCH: Using BRIN indexes for sorted output

2022-11-16 Thread Tomas Vondra
On 11/16/22 22:52, Greg Stark wrote: > Fwiw tuplesort does do something like what you want for the top-k > case. At least it used to last I looked -- not sure if it went out > with the tapesort ... > > For top-k it inserts new tuples into the heap data structure and then > pops the top element out

Re: PATCH: Using BRIN indexes for sorted output

2022-11-16 Thread Greg Stark
Fwiw tuplesort does do something like what you want for the top-k case. At least it used to last I looked -- not sure if it went out with the tapesort ... For top-k it inserts new tuples into the heap data structure and then pops the top element out of the hash. That keeps a fixed number of elemen

Re: PATCH: Using BRIN indexes for sorted output

2022-10-24 Thread Tomas Vondra
On 10/24/22 06:32, Justin Pryzby wrote: > On Sat, Oct 15, 2022 at 02:33:50PM +0200, Tomas Vondra wrote: >> Of course, if there are e.g. BTREE indexes this is going to be slower, >> but people are unlikely to have both index types on the same column. > > On Sun, Oct 16, 2022 at 05:48:31PM +0200,

Re: PATCH: Using BRIN indexes for sorted output

2022-10-18 Thread Tomas Vondra
On 10/17/22 16:00, Matthias van de Meent wrote: > On Mon, 17 Oct 2022 at 05:43, Tomas Vondra > wrote: >> >> On 10/16/22 22:17, Matthias van de Meent wrote: >>> On Sun, 16 Oct 2022 at 16:34, Tomas Vondra >>> wrote: Try to formulate the whole algorithm. Maybe I'm missing something. T

Re: PATCH: Using BRIN indexes for sorted output

2022-10-17 Thread Matthias van de Meent
On Mon, 17 Oct 2022 at 05:43, Tomas Vondra wrote: > > On 10/16/22 22:17, Matthias van de Meent wrote: > > On Sun, 16 Oct 2022 at 16:34, Tomas Vondra > > wrote: > >> Try to formulate the whole algorithm. Maybe I'm missing something. > >> > >> The current algorithm is something like this: > >> > >>

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Tomas Vondra
On 10/16/22 22:17, Matthias van de Meent wrote: > First of all, it's really great to see that this is being worked on. > > On Sun, 16 Oct 2022 at 16:34, Tomas Vondra > wrote: >> Try to formulate the whole algorithm. Maybe I'm missing something. >> >> The current algorithm is something like this:

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Matthias van de Meent
First of all, it's really great to see that this is being worked on. On Sun, 16 Oct 2022 at 16:34, Tomas Vondra wrote: > Try to formulate the whole algorithm. Maybe I'm missing something. > > The current algorithm is something like this: > > 1. request info about ranges from the BRIN opclass > 2.

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Matthias van de Meent
On Sun, 16 Oct 2022 at 16:42, Tom Lane wrote: > > It also seems kind of unfair to decide > that the relevant comparison point is a seqscan rather than a > btree indexscan. I think the comparison against full table scan seems appropriate, as the benefit of BRIN is less space usage when compared to

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Tomas Vondra
On 10/16/22 16:42, Zhihong Yu wrote: > ... > > I don't have good answer w.r.t. splitting the page range [0,127] now. > Let me think more about it. > Sure, no problem. > The 10 step flow (subject to changes down the road) should be either > given in the description of the patch or, written as co

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Tomas Vondra
On 10/16/22 16:41, Tom Lane wrote: > Tomas Vondra writes: >> I forgot to mention one important issue in my list yesterday, and that's >> memory consumption. > > TBH, this is all looking like vastly more complexity than benefit. > It's going to be impossible to produce a reliable cost estimate

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Zhihong Yu
On Sun, Oct 16, 2022 at 7:33 AM Tomas Vondra wrote: > > > On 10/16/22 16:01, Zhihong Yu wrote: > > > > > > On Sun, Oct 16, 2022 at 6:51 AM Tomas Vondra > > mailto:tomas.von...@enterprisedb.com>> > > wrote: > > > > On 10/15/22 14:33, Tomas Vondra wrote: > > > Hi, > > > > > > ... >

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Tom Lane
Tomas Vondra writes: > I forgot to mention one important issue in my list yesterday, and that's > memory consumption. TBH, this is all looking like vastly more complexity than benefit. It's going to be impossible to produce a reliable cost estimate given all the uncertainty, and I fear that will

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Tomas Vondra
On 10/16/22 16:01, Zhihong Yu wrote: > > > On Sun, Oct 16, 2022 at 6:51 AM Tomas Vondra > mailto:tomas.von...@enterprisedb.com>> > wrote: > > On 10/15/22 14:33, Tomas Vondra wrote: > > Hi, > > > > ... > > > > There's a bunch of issues with this initial version of the p

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Tomas Vondra
On 10/16/22 03:36, Zhihong Yu wrote: > > > On Sat, Oct 15, 2022 at 8:23 AM Tomas Vondra > mailto:tomas.von...@enterprisedb.com>> > wrote: > > On 10/15/22 15:46, Zhihong Yu wrote: > >... > >     8) Parallel version is not supported, but I think it shouldn't be > >     possible.

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Zhihong Yu
On Sun, Oct 16, 2022 at 6:51 AM Tomas Vondra wrote: > On 10/15/22 14:33, Tomas Vondra wrote: > > Hi, > > > > ... > > > > There's a bunch of issues with this initial version of the patch, > > usually described in XXX comments in the relevant places.6) > > > > ... > > I forgot to mention one import

Re: PATCH: Using BRIN indexes for sorted output

2022-10-16 Thread Tomas Vondra
On 10/15/22 14:33, Tomas Vondra wrote: > Hi, > > ... > > There's a bunch of issues with this initial version of the patch, > usually described in XXX comments in the relevant places.6) > > ... I forgot to mention one important issue in my list yesterday, and that's memory consumption. The way t

Re: PATCH: Using BRIN indexes for sorted output

2022-10-15 Thread Zhihong Yu
On Sat, Oct 15, 2022 at 8:23 AM Tomas Vondra wrote: > On 10/15/22 15:46, Zhihong Yu wrote: > >... > > 8) Parallel version is not supported, but I think it shouldn't be > > possible. Just make the leader build the range info, and then let the > > workers to acquire/sort ranges and merg

Re: PATCH: Using BRIN indexes for sorted output

2022-10-15 Thread Tomas Vondra
On 10/15/22 15:46, Zhihong Yu wrote: >... > 8) Parallel version is not supported, but I think it shouldn't be > possible. Just make the leader build the range info, and then let the > workers to acquire/sort ranges and merge them by Gather Merge. > ... > Hi, > I am still going over the

Re: PATCH: Using BRIN indexes for sorted output

2022-10-15 Thread Zhihong Yu
On Sat, Oct 15, 2022 at 5:34 AM Tomas Vondra wrote: > Hi, > > There have been a couple discussions about using BRIN indexes for > sorting - in fact this was mentioned even in the "Improving Indexing > Performance" unconference session this year (don't remember by whom). > But I haven't seen any p