Re: Optimizer misses big in 10.4 with BRIN index

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, arcadiy(at)gmail(dot)com
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Optimizer misses big in 10.4 with BRIN index
Date: 2018-07-26 05:40:46
Message-ID: CAKJS1f86rpqPGAxYGndo8zzDM-9xuJM=EBaqQ6QBdxOy8Eg_+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 26 July 2018 at 04:50, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com> wrote:
> My guess is this is the root cause - the estimated number of rows is much
> higher than in practice (3377106 vs. 23040), so at the end the seqscan is
> considered to be slightly cheaper and wins. But the actual row count is
> ~150x lower, making the bitmap index scan way faster.

Isn't the 23040 just the totalpages * 10 per `return totalpages * 10;`
in bringetbitmap()?

The BRIN index costing was changed quite dramatically in [1] which
first appears in pg10. Previous to that patch BRIN assumed it would
touch total_pages * pred_selectivity blocks in the bitmap scan. That
worked well when the table happened to be perfectly ordered by the
column of the BRIN index, but was pretty broken when the order was
random. That lead to BRIN indexes being used when they really
shouldn't have been. The patch tried to fix that by using what
information it could. That was basically the correlation statistics
from pg_statistic. It appeared that the patch was producing more
realistic plans than unpatched, so we went with it, but it's
definitely not perfect; what statistics are?

It would be quite interesting to know the result of:

select stakind3 from pg_Statistic where starelid =
'schema0_lab.data_table'::regclass;

I also see the estimated costs of either plan are very close, so the
chosen plan may well be quite susceptible to changing after different
ANALYZE runs on the table.

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7e534adcdc70866e7be74d626b0ed067c890a251

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2018-07-26 05:50:11 Re: [HACKERS] WAL logging problem in 9.4.3?
Previous Message Ashutosh Bapat 2018-07-26 05:31:51 Re: Expression errors with "FOR UPDATE" and postgres_fdw with partition wise join enabled.