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

From Herbert Liechti
Subject Re: [GENERAL] Trouble: subquery doesn't terminate
Date
Msg-id 388EA1DD.6685C433@thinx.ch
Whole thread Raw
In response to Trouble: subquery doesn't terminate  (mwilson@the-wire.com (Mel Wilson))
List pgsql-general
Mel Wilson wrote:
>
>    Trouble:  I'm running CGI perl routines from Apache (without
> mod_perl) to query a small database.  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.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti                     E-Mail: Herbert.Liechti@thinx.ch
ThinX networked business services        Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pgsql-general by date:

Previous
From: Chairudin Sentosa Harjo
Date:
Subject: Re: [GENERAL] Query time is too long for netscape
Next
From: "DSDeurne Automatisering, Wim Aarts"
Date:
Subject: Re: [GENERAL] Re: server hardware recommendations