Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (8.11.3/8.11.4) with SMTP id fA7L0mm25063 for ; Wed, 7 Nov 2001 16:00:49 -0500 (EST) (envelope-from cniesen@gmx.net) Received: (qmail 13697 invoked by uid 0); 7 Nov 2001 21:00:43 -0000 Received: from pc79088.adp.iastate.edu (HELO D8VGHK.gmx.net) (129.186.79.88) by mail.gmx.net (mp006-rz3) with SMTP; 7 Nov 2001 21:00:43 -0000 Message-Id: <5.1.0.14.2.20011107144418.00a83b68@pop.gmx.net> X-Sender: 196541@pop.gmx.net X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 07 Nov 2001 15:00:40 -0600 To: pgsql-sql@postgresql.org From: Claus Heiko Niesen Subject: Can this query be optimized? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200111/123 X-Sequence-Number: 5507 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; The table "week_pics" contains the column "date" which is indexed in descending order. Unfortunately postresql isn't using the index since I'm using extract and order by the resulting values. Instead postgresql will sort the result set. To order by the date implies that the date needs to be in my select statement, which interferes with uniqueness of the year-month pair. Is there anything I could do to optimize this query besides breaking the date into three separate columns? Claus