Re: Can this query be optimized?

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: Claus Heiko Niesen <cniesen(at)gmx(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Can this query be optimized?
Date: 2001-11-08 16:49:28
Message-ID: web-501647@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Claus Heiko Niesen 2001-11-08 19:11:34 Re: Can this query be optimized?
Previous Message Josh Berkus 2001-11-08 16:44:05 Re: help with function and quotes