Re: Can this query be optimized? - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Can this query be optimized?
Date
Msg-id web-501647@davinci.ethosmedia.com
Whole thread Raw
In response to Re: Can this query be optimized?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Can this query be optimized?  (Claus Heiko Niesen <cniesen@gmx.net>)
List pgsql-sql
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 
(Tom, did you guys ever straignten out the issue with DESC sorts on
indexes?)
-- Build the above query as a VIEW, which should improve performance
somewhat.

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.

-Josh

______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: help with function and quotes
Next
From: Claus Heiko Niesen
Date:
Subject: Re: Can this query be optimized?