From: | mwilson(at)the-wire(dot)com (Mel Wilson) |
---|---|
To: | pgsql-general(at)postgreSQL(dot)org |
Subject: | Re: [GENERAL] Trouble: subquery doesn't terminate |
Date: | 2000-01-27 17:08:50 |
Message-ID: | iuHk4ks/KjXZ089yn@the-wire.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
In article <388EA1DD(dot)6685C433(at)thinx(dot)ch>,
Herbert Liechti <Herbert(dot)Liechti(at)thinx(dot)ch> wrote:
>> [ ... ] This query ran over 6 minutes
>> before Apache timed out and dropped the pipe:
>>
>> $result = $conn->exec(qq/
>> SELECT t.tune_id, t.title
>> FROM tune t
>> WHERE t.tune_id IN
>> (SELECT c.tune_id FROM composer c WHERE c.person_id = $person_id)
>> /);
>The IN Clause is known to be very slow. Try to use the EXISTS clause
>instead. I had the same problem. After changing to the EXISTS
>variant my performance troubles went away.
Thanks for your reply. I'm not sure how to use EXISTS in this case
(a list of tunes composed by a given person.) but it's a moot point
since the fully joined query
SELECT t.tune_id, t.title
FROM tune t, composer c
WHERE t.tune_id = c.tune_id
AND $person_id = c.person_id
ORDER BY t.title
runs in 2 seconds. (in today's test .. while the sub-select was taking
over 7:30 before Netscape killed it.)
Thanks again. Mel.
From | Date | Subject | |
---|---|---|---|
Next Message | Nicolas Huillard | 2000-01-27 17:12:34 | RE: [GENERAL] backup/maintenance scripts? |
Previous Message | Bruce Momjian | 2000-01-27 16:37:24 | Re: [SQL] RE: [GENERAL] Problem with SELECT on large negative INT4 |