Re: [GENERAL] Trouble: subquery doesn't terminate - Mailing list pgsql-general

From mwilson@the-wire.com (Mel Wilson)
Subject Re: [GENERAL] Trouble: subquery doesn't terminate
Date
Msg-id iuHk4ks/KjXZ089yn@the-wire.com
Whole thread Raw
In response to Trouble: subquery doesn't terminate  (mwilson@the-wire.com (Mel Wilson))
List pgsql-general
In article <388EA1DD.6685C433@thinx.ch>,
Herbert Liechti <Herbert.Liechti@thinx.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.

pgsql-general by date:

Previous
From: Nicolas Huillard
Date:
Subject: RE: [GENERAL] backup/maintenance scripts?
Next
From: bgpyvd@myhome.net
Date:
Subject: 18 yr. old blonde 8046