Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.8.8/8.7.5) with ESMTP id LAA14106 for ; Tue, 8 Sep 1998 11:11:06 -0400 (EDT) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.5/8.8.5) with ESMTP id RAA06219; Tue, 8 Sep 1998 17:10:42 +0200 (IST) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Tue, 8 Sep 1998 17:10:50 +0200 To: andreas.fredriksson@pacer.se From: Herouth Maoz Subject: Re: [SQL] SubQuery speed Cc: pgsql-sql@postgreSQL.org At 16:45 +0200 on 8/9/98, andreas.fredriksson@pacer.se wrote: > 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? Why not? So long as the query is "in", and not "not in"? Should be something like: SELECT DISTINCT url,title FROM idx_files, idx_ref, idx_words WHERE idx_files.id = idx_ref.file_id AND idx_ref.word_id = idx_words.id AND (idx_words.word = 'search term 1' OR .. ); In any case, are there indices on the appropriate fields? If the innermost query is supposed to return only one tuple, you should use "=" rather than IN, although I don't know how much that adds. The optimizer probably has an easier time with "=" than with IN. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma