Re: [GENERAL] Trouble: subquery doesn't terminate

From: Herbert Liechti <Herbert(dot)Liechti(at)thinx(dot)ch>
To: pgsql-general(at)postgreSQL(dot)org
Cc: Mel Wilson <mwilson(at)the-wire(dot)com>
Subject: Re: [GENERAL] Trouble: subquery doesn't terminate
Date: 2000-01-26 07:27:25
Message-ID: 388EA1DD.6685C433@thinx.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)Liechti(at)thinx(dot)ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message DSDeurne Automatisering, Wim Aarts 2000-01-26 08:36:12 Re: [GENERAL] Re: server hardware recommendations
Previous Message Chairudin Sentosa Harjo 2000-01-26 07:12:43 Re: [GENERAL] Query time is too long for netscape