Re: nested select query take too long

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Arsalan Zaidi <azaidi(at)directi(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: nested select query take too long
Date: 2001-11-19 17:29:21
Message-ID: 20011119092847.S47208-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 19 Nov 2001, Arsalan Zaidi wrote:

> Hi.
>
> The following query takes absolutely *ages* to run. Even with just a 1000
> records in each table. It seems to me that the nested query is being run for
> *every* value in the dom_ns table.
>
> SELECT DISTINCT dom_ns.domname, dom_ns.tldtype FROM dom_ns WHERE
> dom_ns.domname NOT IN (SELECT domname FROM domains WHERE domname IS NOT
> NULL);
>
> Why should is this happening? I just want the nested query to run once!

See the FAQ. Short form: It'll be faster if you rewrite to use exists
rather than IN.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Pilsl 2001-11-19 17:37:24 cant alter/create tables via odbc
Previous Message Alexis Maldonado 2001-11-19 17:01:23 Help with Toast.