Re: A very long running query....

От: Tom Lane
Тема: Re: A very long running query....
Дата: ,
Msg-id: 20579.1342889900@sss.pgh.pa.us
(см: обсуждение, исходный текст)
Ответ на: Re: A very long running query....  (Ioannis Anagnostopoulos)
Ответы: Re: A very long running query....  (Ioannis Anagnostopoulos)
Список: pgsql-performance

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

A very long running query....  (Ioannis Anagnostopoulos, )
 Re: A very long running query....  (Claudio Freire, )
  Re: A very long running query....  (Ioannis Anagnostopoulos, )
   Re: A very long running query....  (Rosser Schwarz, )
    Re: A very long running query....  (Ioannis Anagnostopoulos, )
     Re: A very long running query....  (Ioannis Anagnostopoulos, )
      Re: A very long running query....  (Craig Ringer, )
   Re: A very long running query....  (Claudio Freire, )
    Re: A very long running query....  (Ioannis Anagnostopoulos, )
    Re: A very long running query....  (Tom Lane, )
     Re: A very long running query....  (Ioannis Anagnostopoulos, )
     Re: A very long running query....  (Ioannis Anagnostopoulos, )
      Re: A very long running query....  (Claudio Freire, )
       Re: A very long running query....  (Ioannis Anagnostopoulos, )
 Re: A very long running query....  ("Marc Mamin", )
  Re: A very long running query....  (Ioannis Anagnostopoulos, )
   Re: A very long running query....  (Tom Lane, )
    Re: A very long running query....  (Ioannis Anagnostopoulos, )
 Re: A very long running query....  (Claudio Freire, )
  Re: A very long running query....  (Claudio Freire, )
   Re: A very long running query....  (Ioannis Anagnostopoulos, )

[ Please try to trim quotes when replying.  People don't want to re-read
  the entire thread in every message. ]

Ioannis Anagnostopoulos <> writes:
> On 21/07/2012 10:16, Marc Mamin wrote:
>> isn't the first test superfluous here ?
>>
>>> where extract('day' from message_copies.msg_date_rec) = 17
>>> and date_trunc('day', message_copies.msg_date_rec) = '2012-07-17'

> No because it is used to select a partition. Otherwise it will go
> through the whole hierarchy...

You're using extract(day...) to define partitions?  You might want to
rethink that.  The planner has got absolutely no intelligence about
the behavior of extract, and in particular doesn't realize that the
date_trunc condition implies the extract condition; so that's another
part of the cause of the estimation error here.

What's usually recommended for partitioning is simple equality or
range constraints, such as "msg_date_rec >= 'date1' AND
msg_date_rec < 'date2'", which the planner does have a fair amount
of intelligence about.

Now, you can generalize that to equality or range constraints using
an expression; for instance there'd be no problem to partition on
date_trunc('day', msg_date_rec) rather than msg_date_rec directly,
so long as your queries always use that same expression.  But you
should not expect that the planner can deduce very much about the
correlations between results of different functions.

            regards, tom lane


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

От: Ioannis Anagnostopoulos
Дата:
Сообщение: Re: A very long running query....
От: Jim Vanns
Дата:
Сообщение: Odd blocking (or massively latent) issue - even with EXPLAIN