From: Claus Heiko Niesen <cniesen@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Can this query be optimized?
Date: Wed, 07 Nov 2001 15:00:40 -0600
Message-ID: <5.1.0.14.2.20011107144418.00a83b68@pop.gmx.net> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: cniesen@gmx.net
Subject: Re: Can this query be optimized?
In-Reply-To: <5.1.0.14.2.20011107144418.00a83b68@pop.gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox