Re: Slow query: bitmap scan troubles

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Claudio Freire <klaussfreire(at)gmail(dot)com>
Cc: postgresql(at)foo(dot)me(dot)uk, postgres performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Slow query: bitmap scan troubles
Date: 2012-12-06 21:09:54
Message-ID: CAMkU=1wpMU8JvDBkxZS0zb5=xqh=_xHRcwvY--YT=6uyOOfZ0g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

On Thu, Dec 6, 2012 at 12:05 PM, Claudio Freire <klaussfreire(at)gmail(dot)com> wrote:
> On Thu, Dec 6, 2012 at 2:27 PM, Jeff Janes <jeff(dot)janes(at)gmail(dot)com> wrote:
>> On Wed, Dec 5, 2012 at 9:43 AM, Claudio Freire <klaussfreire(at)gmail(dot)com> wrote:
>>> As far as I can see on the explain, the misestimation is 3x~4x not 200x.
>>
>> It is 3x (14085 vs 4588) for selectivity on one of the tables, "Index
>> Only Scan using idx_trade_id_book on trade".
>>
>> But for the join of both tables it is estimate 2120 vs actual 11.
>
> But the final result set isn't further worked on (except for the
> aggregate), which means it doesn't affect the cost by much.

Good point. Both the NL and hash join do about the same amount of
work probing for success whether the success is actually there or not.

So scratch what I said about the correlation being important, in this
case it is not.

The 3x error is enough to push it over the edge, but the fudge factor
is what gets it so close to that edge in the first place.

And I'm now pretty sure the fudge factor change would fix this. The
truly-fast NL plan is getting overcharged by the fudge-factor once per
each 14,085 of the loopings, while the truly-slow bitmap scan is
overcharged only once for the entire scan. So the change is by no
means neutralized between the two plans.

I don't know if my other theory that the bitmap scan is overflowing
work_mem (but not costed for doing so) is also contributing.

Cheers,

Jeff

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Asif Rehman 2012-12-06 21:13:49 Re: why can't plpgsql return a row-expression?
Previous Message Alvaro Herrera 2012-12-06 21:02:11 pgsql: Background worker processes

Browse pgsql-performance by date

  From Date Subject
Next Message David Crawford 2012-12-07 22:09:52 How do I track stats on foreign table access through foreign data wrapper?
Previous Message Claudio Freire 2012-12-06 20:05:09 Re: Slow query: bitmap scan troubles