pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alex Rice <alrice@ARCplanning.com>
To: pgsql-sql@postgresql.org
Subject: 2 simple SQL questions: optimizing aggegate query
Date: Mon, 5 May 2003 12:59:47 -0600
Message-ID: <BE0640A2-7F2B-11D7-969D-000393529642@ARCplanning.com> (raw)

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

2) In the above query, why can't I write "HAVING rank > 0"? instead of 
repeating the whole entire sum() expression "HAVING sum(...)"

Thanks in advance,

Alex Rice, Software Developer
Architectural Research Consultants, Inc.
alrice@ARCplanning.com
alrice@swcp.com




view thread (5+ messages)  latest in thread

Message-ID: <BE0640A2-7F2B-11D7-969D-000393529642@ARCplanning.com>
Permalink:  ../BE0640A2-7F2B-11D7-969D-000393529642@ARCplanning.com/
Also on:    postgresql.org/message-id/BE0640A2-7F2B-11D7-969D-000393529642@ARCplanning.com

 · 

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: alrice@ARCplanning.com
  Subject: Re: 2 simple SQL questions: optimizing aggegate query
  In-Reply-To: <BE0640A2-7F2B-11D7-969D-000393529642@ARCplanning.com>
  References: <BE0640A2-7F2B-11D7-969D-000393529642@ARCplanning.com>

* 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