Re: Slow query: bitmap scan troubles

Поиск
Список
Период
Сортировка
От Jeff Janes
Тема Re: Slow query: bitmap scan troubles
Дата
Msg-id CAMkU=1zCDqsnfQ-cE4jc_A8=WhJYkDGwMh1-V8vB4a8fQ60ysA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Slow query: bitmap scan troubles  (<postgresql@foo.me.uk>)
Список pgsql-performance
On Tue, Dec 4, 2012 at 9:47 AM,  <postgresql@foo.me.uk> wrote:
>
>>> But the row estimates are not precise at the top of the join/filter.
>>> It thinks there will 2120 rows, but there are only 11.
>
>>Ah... I didn't spot that one...
>
> Yes, you are right there - this is probably a slightly atypical query of
> this sort actually, 2012 is a pretty good guess.

What do the timings look like on a more realistic example?

> On Claudio's suggestion I have found lots more things to read up on and am
> eagerly awaiting 6pm when I can bring the DB down and start tweaking. The
> effective_work_mem setting is going from 6Gb->88Gb which I think will make
> quite a difference.

You can change effective_cache_size just in your own session, or do it
globally with a "reload" or SIGHUP, no need to bring down the server.

However, I don't think it will make much difference.  Even though it
thinks it is hitting the index 14,085 times, that is still small
compared to the overall size of the table.

> I still can't quite wrap around my head why accessing an index is expected
> to use more disk access than doing a bitmap scan of the table itself,

It is only doing an bitmap scan of those parts of the table which
contain relevant data, and it is doing them in physical order, so it
thinks that much of the IO which it thinks it is going to do is
largely sequential.

> but I
> guess it does make a bit of sense if postgres assumes the table is more
> likely to be cached.

Unfortunately, postgres's planner doesn't know anything about that.
From your "explain" I can see in hindsight that everything you needed
was cached, but that is not information that the planner can use
(currently).  And I don't know if *everything* is cached, or if just
those particular blocks are because you already ran the same query
with the same parameters recently.

Also, your work_mem is pretty low given the amount of RAM you have.

work_mem = 1MB

I don't think the current planner attempts to take account of the fact
that a bitmap scan which overflows work_mem and so becomes "lossy" is
quite a performance set-back.  Nor does it look like explain analyze
informs you of this happening.   But maybe I'm just looking in the
wrong places.

Cheers,

Jeff


В списке pgsql-performance по дате отправления:

Предыдущее
От: Sergey Konoplev
Дата:
Сообщение: Re: Slow query: bitmap scan troubles
Следующее
От: Jeff Janes
Дата:
Сообщение: Re: Slow query: bitmap scan troubles