From: | Julien Rouhaud <rjuju123(at)gmail(dot)com> |
---|---|
To: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
Cc: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Hypothetical indexes using BRIN broken since pg10 |
Date: | 2019-07-26 11:52:19 |
Message-ID: | CAOBaU_YhNKQmi2vSta44dDt3VksyYUzjMwbdY1jaqfOpqMqU6w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Jul 26, 2019 at 1:34 PM Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:
>
> There seems to be consensus on the going with the approach from the
> original patch, so I had a closer look at it.
>
> The patch first does this:
>
> >
> > /*
> > * Obtain some data from the index itself, if possible. Otherwise invent
> > * some plausible internal statistics based on the relation page count.
> > */
> > if (!index->hypothetical)
> > {
> > indexRel = index_open(index->indexoid, AccessShareLock);
> > brinGetStats(indexRel, &statsData);
> > index_close(indexRel, AccessShareLock);
> > }
> > else
> > {
> > /*
> > * Assume default number of pages per range, and estimate the number
> > * of ranges based on that.
> > */
> > indexRanges = Max(ceil((double) baserel->pages /
> > BRIN_DEFAULT_PAGES_PER_RANGE), 1.0);
> >
> > statsData.pagesPerRange = BRIN_DEFAULT_PAGES_PER_RANGE;
> > statsData.revmapNumPages = (indexRanges / REVMAP_PAGE_MAXITEMS) + 1;
> > }
> > ...
>
> And later in the function, there's this:
>
> > /* work out the actual number of ranges in the index */
> > indexRanges = Max(ceil((double) baserel->pages / statsData.pagesPerRange),
> > 1.0);
>
> It seems a bit error-prone that essentially the same formula is used
> twice in the function, to compute 'indexRanges', with some distance
> between them. Perhaps some refactoring would help with, although I'm not
> sure what exactly would be better. Maybe move the second computation
> earlier in the function, like in the attached patch?
I had the same thought without a great idea on how to refactor it.
I'm fine with the one in this patch.
> The patch assumes the default pages_per_range setting, but looking at
> the code at https://github.com/HypoPG/hypopg, the extension actually
> takes pages_per_range into account when it estimates the index size. I
> guess there's no easy way to pass the pages_per_range setting down to
> brincostestimate(). I'm not sure what we should do about that, but seems
> that just using BRIN_DEFAULT_PAGES_PER_RANGE here is not very accurate.
Yes, hypopg can use a custom pages_per_range as it intercepts it when
the hypothetical index is created. I didn't find any way to get that
information in brincostestimate(), especially for something that could
backpatched. I don't like it, but I don't see how to do better than
just using BRIN_DEFAULT_PAGES_PER_RANGE :(
> The attached patch is based on PG v11, because I tested this with
> https://github.com/HypoPG/hypopg, and it didn't compile with later
> versions. There's a small difference in the locking level used between
> v11 and 12, which makes the patch not apply across versions, but that's
> easy to fix by hand.
FTR I created a REL_1_STABLE branch for hypopg which is compatible
with pg12 (it's already used for debian packages), as master is still
in beta and v12 compatibility worked on.
From | Date | Subject | |
---|---|---|---|
Next Message | Daniel Verite | 2019-07-26 12:12:39 | Re: psql - add SHOW_ALL_RESULTS option |
Previous Message | Heikki Linnakangas | 2019-07-26 11:34:19 | Re: Hypothetical indexes using BRIN broken since pg10 |