[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [GENERAL] Trouble: subquery doesn't terminate
From:       mwilson () the-wire ! com (Mel Wilson)
Date:       2000-01-27 17:08:50
[Download RAW message or body]

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.

************

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic