Re: Complicated query... is there a simpler way?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Joshua Adam Ginsberg <rainman(at)owlnet(dot)rice(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Complicated query... is there a simpler way?
Date: 2001-06-27 07:11:00
Message-ID: 3B398703.44F9A59C@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua Adam Ginsberg wrote:
>
> I've got a nasty looking search query, and I'm afraid with a large table
> it's going to be horribly inefficient, and I was wondering if anybody
> could think of a way to slim this one down.

> Here's the query:
>
> select lastname, firstnames, subject, threadid from posts, users,
> (select threadid, concat(body) as thread_body from (select postid as
> threadid, body from posts where reply_to is null union select reply_to
> as threadid, body from posts where reply_to is not null) as
> inner_subquery group by threadid) as outer_subquery where users.userid =
> posts.author and threadid = postid and
> score_search('$query',subject,thread_body) > 0 order by
> score_search('$query',subject,thread_body);

Just thinking out loud, and it depends on how you are doing your
scoring, but what about scoring each message individually and the
grouping by threadid summing the scores? Should bring it down to two
levels plus a join with users.

- Richard Huxton

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gunnar Rønning 2001-06-27 07:12:04 Re: Blobs in PostgreSQL
Previous Message Richard Huxton 2001-06-27 07:00:01 Re: Bug in createlang?