X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 023C39FA5C3 for ; Fri, 16 Jun 2006 10:28:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 32572-09 for ; Fri, 16 Jun 2006 10:28:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms048pub.verizon.net (vms048pub.verizon.net [206.46.252.48]) by postgresql.org (Postfix) with ESMTP id 77BAD9FA42B for ; Fri, 16 Jun 2006 10:28:49 -0300 (ADT) Received: from [192.169.1.2] ([71.101.6.8]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0J0Y00302G3ZYP00@vms048.mailsrvcs.net> for pgsql-sql@postgresql.org; Fri, 16 Jun 2006 08:28:48 -0500 (CDT) Date: Fri, 16 Jun 2006 09:29:44 -0400 From: Joe Subject: Re: Repetitive code In-reply-to: To: Aaron Bono Cc: pgsql-sql@postgresql.org Message-id: <4492B248.7040406@freedomcircle.net> Organization: Freedom Circle, LLC MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit References: <44920AA7.7070709@freedomcircle.net> User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/204 X-Sequence-Number: 25440 Aaron Bono wrote: > Each of your queries has the filter xxx >= $dt where the xxx is the > first column in each select. You could simplify the query by turning > the unioned selects into a sub-query and then putting the $dt filter in > the outer query. It would probably have to be two subqueries unless I can find a way to merge the differences between new and changed rows. > I don't know if this will cause performance problems though. If > PostgreSQL completes the inner query before filtering by your $dt you > may be better off leaving the $dt filters where they are. The query is only run a few times a week so performance is largely not a concern. I'm trying to simplify it to make adding tables less cumbersome (as a separate effort, the schema may be modified to normalize it, e.g., topic joins to entry via subject_id and actor_id and a subject and actor can also appear in topic_entry's topic_id). > I know Oracle has materialized views. Does PostgreSQL also have > materialized views? If so, you could get great performance from your > views AND simplify your SQL. AFAIK PostgreSQL does not support materialized views but it's interesting that you mention that because in essence the query is used to materialize a view, i.e., it's part of an INSERT / SELECT into a table which is then joined back to the other tables to construct a web page as well as an RSS feed. Joe