Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id CDD269F98DF for ; Sat, 3 Nov 2007 18:49:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 68198-05-6 for ; Sat, 3 Nov 2007 18:48:59 -0300 (ADT) X-Greylist: delayed 00:09:40.856051 by SQLgrey-1.7.5 Received: from ironport2-out.pppoe.ca (ironport2-out.pppoe.ca [206.248.154.182]) by postgresql.org (Postfix) with ESMTP id CCF189F98EB for ; Sat, 3 Nov 2007 18:49:04 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CANqGLEfO+Igp/2dsb2JhbACQPQ X-IronPort-AV: E=Sophos;i="4.21,367,1188792000"; d="scan'208";a="8778262" Received: from smtp.pppoe.ca ([65.39.196.238]) by ironport2-out.pppoe.ca with ESMTP; 03 Nov 2007 17:39:22 -0400 Received: from [206.248.136.41] ([206.248.136.41]) by smtp.pppoe.ca (Internet Mail Server v1.0) with ESMTP id IGQ27022; Sat, 03 Nov 2007 17:39:22 -0400 Message-ID: <472CEA89.30808@mark.mielke.cc> Date: Sat, 03 Nov 2007 17:39:21 -0400 From: Mark Mielke User-Agent: Thunderbird 2.0.0.5 (X11/20070727) MIME-Version: 1.0 To: Jeff Larsen CC: pgsql-performance@postgresql.org Subject: Re: Union within View vs.Union of Views References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/39 X-Sequence-Number: 27454 Jeff Larsen wrote: > If it's possible to consider this abstractly, is there any particular > reason why there is such a vast difference in performance? I would > guess that is has something to do with how the WHERE conditions are > applied to a view composed of a UNION of queries. Perhaps this is an > opportunity for improvement in the code. In the first case, it's as if > the server is doing the union on all rows (over 10 million altogether > in my case) without filtering, then applying the conditions to the > result. Maybe there is no better way. > > I can post query plans if anyone is interested. I haven't really > learned how to make sense out of them myself yet. > > For my purposes, I'm content to use the union of separate views in my > application, so if this doesn't pique anyone's interest, feel free to > ignore it. > I hit this as well in less impacting statements. I found myself curious that the sub-plan would have to be executed in full before it applied the filter. Perhaps PostgreSQL has difficulty pushing WHERE conditions through the rule system? It's an area I only barely understand, so I never looked further... I'm interested, but do not have anything of value to provide either. :-) Cheers, mark -- Mark Mielke