Skip site navigation (1) Skip section navigation (2)

Re: Speedy query help..

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Mitch Vincent" <mitch(at)venux(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Speedy query help..
Date: 2000-04-10 23:25:35
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
"Mitch Vincent" <mitch(at)venux(dot)net> writes:
> Any ideas on how I might speed this up? I know sub-selects are seriously
> slow, I'm not sure what else can be done though.

> DELETE from applicants_states WHERE app_id IN (SELECT s.app_id FROM
> applicants_states AS s, applicants AS a WHERE s.app_id=a.app_id AND
> (a.created + '90 days') < 'now' AND a.resubmitted < '10-03-1999')

I believe you'd get the same result from

DELETE FROM applicants_states
WHERE app_id = applicants.app_id AND
      (applicants.created + '90 days') < 'now' AND
      applicants.resubmitted < '10-03-1999';

This is not SQL-standard; doing an implicit join when you mention
another table in WHERE is a leftover from Berkeley Postquel.  But
it solves this sort of problem rather handily.

If you want to stick to portable SQL, I'd at least suggest getting rid
of the unnecessary join in the subselect; wouldn't

DELETE from applicants_states WHERE app_id IN (SELECT app_id
    FROM applicants
    WHERE (created + '90 days') < 'now' AND resubmitted < '10-03-1999');

produce the same results?

Also, 7.0 does uncorrelated subselects (like this one) somewhat
faster than prior releases, so just upgrading might solve the problem
for you.

			regards, tom lane

In response to

pgsql-sql by date

Next:From: Tom LaneDate: 2000-04-10 23:35:12
Subject: Re: Finding primary keys
Previous:From: Matlack, BradDate: 2000-04-10 22:37:53
Subject: Finding primary keys

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group