X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E7C68476397 for ; Mon, 5 May 2003 14:59:50 -0400 (EDT) Received: from taka.swcp.com (taka.swcp.com [198.59.115.12]) by postgresql.org (Postfix) with ESMTP id 27F8B476384 for ; Mon, 5 May 2003 14:59:50 -0400 (EDT) Received: from ARCplanning.com (pcp02742825pcs.sntafe01.nm.comcast.net [68.35.10.62]) by taka.swcp.com (8.12.9/8.12.9) with ESMTP id h45Ixmqu092226 for ; Mon, 5 May 2003 12:59:49 -0600 (MDT) Date: Mon, 5 May 2003 12:59:47 -0600 Mime-Version: 1.0 (Apple Message framework v552) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: 2 simple SQL questions: optimizing aggegate query From: Alex Rice To: pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit Message-Id: X-Mailer: Apple Mail (2.552) X-Spam-Status: No, hits=-8.9 required=5.0 tests=BAYES_10,USER_AGENT_APPLEMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/61 X-Sequence-Number: 13226 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