Re: Performance and IN clauses

От: Tomas Vondra
Тема: Re: Performance and IN clauses
Дата: ,
Msg-id: 49236288.3000006@fuzzy.cz
(см: обсуждение, исходный текст)
Ответ на: Re: Performance and IN clauses  (Mark Roberts)
Список: pgsql-performance

Скрыть дерево обсуждения

Performance and IN clauses  ("Kynn Jones", )
 Re: Performance and IN clauses  (Matthew Wakeling, )
  Re: Performance and IN clauses  (, )
   Re: Performance and IN clauses  (Mark Roberts, )
    Re: Performance and IN clauses  (Tomas Vondra, )
    Re: Performance and IN clauses  (Tomas Vondra, )

> I know that it's much faster (for us) to run many smaller queries than
> one large query, and I think that it's primarily because of your reason
> a.  Most of our problems come from Pg misunderstanding the results of a
> join and making a bad plan decision.  Batching dramatically reduces the
> liklihood of this.
>
> -Mark

Show us the plan (output of EXPLAIN ANALYZE), along with detailed info
about the table (number of rows / pages) and environment (amount of RAM,
etc.). Without these information it's impossible to tell which of the
choices is right.

In my experience the planner is a very good piece of software, but if
you feed him with bad information about the environment / data in the
beginning, you can hardly expect good plans.

Occasionally I provide consultancy to developers having problems with
PostgreSQL, and while most of the time (say 70% of the time) the
problems are caused by mistakes in SQL or incorrect design of the
system, problems with proper settings of the PostgreSQL are quite often.
I really don't know if you use the default values or if you have tuned
the settings (and how), but it's hard to tell from your original post.

For example if you don't set the work_mem according to your settings,
this may result in on-disk sorting even if you have plenty of free
memory. Or if you have fast drives, the default cost settings may
produce bad plans (index scan may seem too expensive), etc. And of
course you may have data with complicated statistical properties, and
the default level of details may not be sufficient (try increase it with
SET STATISTICS for the column).

Anyway - there may be glitch / corner case in the planner of course, but
   it's hard to tell without the EXPLAIN ANALYZE output.

regards
Tomas


В списке pgsql-performance по дате сообщения:

От: Tomas Vondra
Дата:
Сообщение: Re: Performance and IN clauses
От: "Віталій Тимчишин"
Дата:
Сообщение: PostgreSQL NOT IN performance