pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Andrew Perrin - Demography <aperrin@demog.berkeley.edu>
To: pgsql-sql@postgresql.org
Subject: Speeding up a query
Date: Fri, 7 Apr 2000 12:12:39 -0700 (PDT)
Message-ID: <Pine.LNX.4.10.10004071209290.7254-100000@famine.DEMOG.Berkeley.EDU> (raw)
Greetings.
The following query returns the last names of people in our database whom
we consider 'students' during the time period 1-jan-1998 to 1-jun-1998.
It's based on selecting events from a table in which each event can
determine that a person is a Student, NotStudent, or Neutral; the idea is
that a given person is a student from the date of their first Student
event to the date of their next NotStudent event, etc.
The problem is that it's very slow - on the order of 45-60 seconds to
generate a list that's only about 30 names long. Can anyone offer some
advice on speeding it up? The dates need to be user-selectable.
Many thanks.
select last_name from personal_data where id in (
select distinct id from event_detail, event_universe where
event_detail.eventtypeid = event_universe.eventtypeid and
event_universe.studentstatus = 'Student' and
event_detail.date_effective <= datetime(date('1-jan-1998')))
and
id not in (
select distinct id from event_detail, event_universe where
event_detail.eventtypeid = event_universe.eventtypeid and
event_universe.studentstatus = 'NotStudent' and
event_detail.date_effective <= datetime(date('1-jun-1998')))
---------------------------------------------------------------------
Andrew J. Perrin - aperrin@demog.berkeley.edu - NT/Unix Admin/Support
Department of Demography - University of California at Berkeley
2232 Piedmont Avenue #2120 - Berkeley, California, 94720-2120 USA
http://demog.berkeley.edu/~aperrin --------------------------SEIU1199
view thread (2+ messages) latest in thread
Message-ID: <Pine.LNX.4.10.10004071209290.7254-100000@famine.DEMOG.Berkeley.EDU> Permalink: ../Pine.LNX.4.10.10004071209290.7254-100000@famine.DEMOG.Berkeley.EDU/ Also on: postgresql.org/message-id/Pine.LNX.4.10.10004071209290.7254-100000@famine.DEMOG.Berkeley.EDU ·
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 from your mail client; the link fills in the headers below: reply via email Some clients, webmail especially, drop In-Reply-To and References from a link, and the reply then starts a new thread: use the mbox below. To: pgsql-sql@postgresql.org Cc: aperrin@demog.berkeley.edu Subject: Re: Speeding up a query In-Reply-To: <Pine.LNX.4.10.10004071209290.7254-100000@famine.DEMOG.Berkeley.EDU> References: <Pine.LNX.4.10.10004071209290.7254-100000@famine.DEMOG.Berkeley.EDU> * 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