Re: Can this query be optimized?

Поиск
Список
Период
Сортировка
От Claus Heiko Niesen
Тема Re: Can this query be optimized?
Дата
Msg-id 5.1.0.14.2.20011108122508.00ae2350@pop.gmx.net
обсуждение исходный текст
Ответ на Re: Can this query be optimized?  ("Josh Berkus" <josh@agliodbs.com>)
Ответы Re: Can this query be optimized?  ("Ross J. Reedstrom" <reedstrm@rice.edu>)
Список pgsql-sql
At 10:49 AM 11/08/2001, Josh wrote:
>Claus,
>
> > > I'm stuck optimizing the following query:
> > > select distinct extract(year from date) as year, extract(month from
> > date)
> > > as month, date from week_pics order by date desc;
> >
> > Perhaps it would work to forget the "distinct" and instead GROUP BY
> > date.
>
>Also, do the following:
>-- Make sure you have an index on week_pics.date

Yes I do have one where the date is the first key of the index.  But since 
I only extract partial data from the index column postgresql seems to 
ignore the index.  Probably to difficult for it to see that the index is in 
the extract(year from date), extract(month from date) order.

>-- Build the above query as a VIEW, which should improve performance
>somewhat.

What's the secret about the improved performance.  Is it just that the 
query access plan doesn't have to be determined every time the query is 
executed or is there something else?

>Technically, you could build an index on extract(month from date), I
>believe, but I'm not sure how effective such an index would be in
>practice.


I just tried to build an index to see what the explain path would do but I 
get an error on the word extract:

# create index week_pics_month_key on week_pics (extract(year from 
time_stamp), extract(month from time_stamp));
ERROR:  parser: parse error at or near "extract"

>-Josh

Thanks for the help Josh
  Claus

PS:  Accidently I had also the date column selected in the query that I 
posted.  This was incorrect and the query should have been:

select distinct extract(year from date) as year, extract(month from date) 
as month from week_pics order by year desc, month desc;




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

Предыдущее
От: Claus Heiko Niesen
Дата:
Сообщение: Re: Can this query be optimized?
Следующее
От: "Ross J. Reedstrom"
Дата:
Сообщение: Re: Can this query be optimized?