From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | Alex Rice <alrice(at)ARCplanning(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: 2 simple SQL questions: optimizing aggegate query |
Date: | 2003-05-05 19:45:18 |
Message-ID: | 20030505194518.GA5200@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, May 05, 2003 at 12:59:47 -0600,
Alex Rice <alrice(at)ARCplanning(dot)com> wrote:
> Hello, I am using Mnogosearch with a PostgreSQL backend. I am writing
> my own queries because I can't use the existing Perl or PHP front ends
> to Mnogosearch.
>
> 1) Is there a way to optimize this query? It takes ~6 seconds on my
> workstation :-( I would like to get it under 2 seconds.
>
> SELECT url.rec_id, url, title, content_type, txt,
> sum(
> case
> when dict.word = 'wordx' then 1
> when dict.word = 'wordx' then 1
> when dict.word = 'wordy' then 1
> else 0
> end
> ) as rank
> FROM dict, url
> WHERE url.rec_id = dict.url_id
> GROUP BY rec_id, url, title, content_type, txt
> ORDER BY rank DESC
Is there some reason you can't put the word list in the where clause?
(You can use coalesce to set NULL sums to 0.)
From | Date | Subject | |
---|---|---|---|
Next Message | Michael A Nachbaur | 2003-05-05 19:57:16 | pgsql Replication Proxy (was Re: Replication for a large database) |
Previous Message | Michael A Nachbaur | 2003-05-05 19:28:45 | Re: Replication for a large database |