Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fA8GnPm08423 for ; Thu, 8 Nov 2001 11:49:25 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.7) with HTTP id 501647; Thu, 08 Nov 2001 08:49:28 -0800 From: "Josh Berkus" Subject: Re: Can this query be optimized? To: Claus Heiko Niesen Cc: pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.7 Date: Thu, 08 Nov 2001 08:49:28 -0800 Message-ID: In-Reply-To: <16760.1005229805@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200111/133 X-Sequence-Number: 5517 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@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco