Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f382g9854690 for ; Sat, 7 Apr 2001 22:42:09 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f34Nsi820884 for ; Wed, 4 Apr 2001 19:54:45 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.1/8.11.1) id f34NpUX31988 for pgsql-sql@postgresql.org; Wed, 4 Apr 2001 19:51:30 -0400 (EDT) (envelope-from news) From: "Gordon A. Runkle" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: UNION in a VIEW? Date: Wed, 04 Apr 2001 19:57:47 -0400 Organization: Integrated Dynamics, Inc. Lines: 34 Message-ID: <9agc20$v7h$1@news.tht.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: scrappy@hub.org User-Agent: Pan/0.9.6 (Unix) X-No-Productlinks: Yes To: pgsql-sql@postgresql.org X-Archive-Number: 200104/108 X-Sequence-Number: 2450 In article , "Josh Berkus" wrote: > Tom, Gordon, > Hmmm ... I'm pretty used an external WHERE clause being applied to the > output of the view, rather than pushed down into the member selects of > the UNION, in the same way as if the UNION query were a subselect. > Coming from a SQL Server background, I'd actually find the suggested > behavior rather confusing (as well as tough for you guys to implement). Like I said, I'm not a backend guru. However, SQL Server and DB2 both *appear* to be pushing down the WHERE clause. They may not be, but they both process the query nearly instantaneously on large tables, which leads me to speculate that they do. PostgreSQL goes off and munches for a *long* time on the same view/query, whereas if I write a query which explicitly distributes the WHERE then PostgreSQL processes the query very fast (faster than DB2 or SQL Server). So, I can only guess what's happening "behind the curtain", but this is what I'm observing. Plus, I think that if the WHERE clause were applied to the results of the VIEW, that would require storing those results in temp space, and for large tables would be very slow. I believe that's the whole reason that VIEWs' underlying queries can be merged/rewritten with the "calling" query? Thanks, Gordon. -- It doesn't get any easier, you just go faster. -- Greg LeMond