pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vadim Mikheev <vadim@krs.ru>
To: andreas.fredriksson@pacer.se
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] SubQuery speed
Date: Wed, 09 Sep 1998 10:29:07 +0800
Message-ID: <35F5E7F3.9FE5925C@krs.ru> (raw)
References: <Pine.LNX.4.00.9809081635420.676-100000@zenith.pacer.se>

andreas.fredriksson@pacer.se wrote:
> 
> BEGIN;
> DECLARE CURSOR curs FOR
> SELECT url,title FROM idx_files WHERE id IN (
>  SELECT file_id FROM idx_ref WHERE word_id IN (
>   SELECT id FROM idx_words WHERE word = 'search term 1' OR .. ) );
> FETCH FORWARD 10 IN curs;
> END;
> 
> The idx_files table holds about 1.000 rows, the idx_words table holds
> about 50.000 words, and the idx_ref is a massive 250.000+
> row cross-reference (file_id, word_id) which links the words and
> pages together.
> 
> A query like the above took several hours on my Pentium 200 at work before
> I killed the stuck daemon. This is kind of strange since the innermost
> subquery is only suppose to return a single id. :-(
> 
> Are there any alternate methods of solving this? I don't think it's
> possible to write this kind of query using a multi-JOIN?

Try to rewrite query using EXISTS instead of IN and create
indices.

Vadim



view thread (3+ messages)

Message-ID: <35F5E7F3.9FE5925C@krs.ru>
Permalink:  ../35F5E7F3.9FE5925C@krs.ru/
Also on:    postgresql.org/message-id/35F5E7F3.9FE5925C@krs.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: vadim@krs.ru, andreas.fredriksson@pacer.se
  Subject: Re: [SQL] SubQuery speed
  In-Reply-To: <35F5E7F3.9FE5925C@krs.ru>
  References: <Pine.LNX.4.00.9809081635420.676-100000@zenith.pacer.se> <35F5E7F3.9FE5925C@krs.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox