pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Claus Heiko Niesen <cniesen@gmx.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Can this query be optimized?
Date: Thu, 08 Nov 2001 08:49:28 -0800
Message-ID: <web-501647@davinci.ethosmedia.com> (raw)
In-Reply-To: <16760.1005229805@sss.pgh.pa.us>

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



view thread (7+ messages)  latest in thread

Message-ID: <web-501647@davinci.ethosmedia.com>
Permalink:  ../web-501647@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-501647@davinci.ethosmedia.com

 · 

reply

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: josh@agliodbs.com, cniesen@gmx.net
  Subject: Re: Can this query be optimized?
  In-Reply-To: <web-501647@davinci.ethosmedia.com>

* 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