X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DB29253432 for ; Thu, 24 Mar 2005 13:48:13 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21306-07 for ; Thu, 24 Mar 2005 13:48:04 +0000 (GMT) Received: from metux.de (seven.metux.de [193.16.1.1]) by svr1.postgresql.org (Postfix) with ESMTP id 7B9E852A50 for ; Thu, 24 Mar 2005 13:48:02 +0000 (GMT) Received: (from weigelt@localhost) by metux.de (8.12.10/8.12.10) id j2ODm5bu030161 for pgsql-performance@postgresql.org; Thu, 24 Mar 2005 14:48:05 +0100 Date: Thu, 24 Mar 2005 14:48:05 +0100 From: Enrico Weigelt To: pgsql-performance@postgresql.org Subject: Re: View columns calculated Message-ID: <20050324134805.GC31203@nibiru.borg.metux.de> Reply-To: weigelt@metux.de References: <26711.1081891416@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <26711.1081891416@sss.pgh.pa.us> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/507 X-Sequence-Number: 11212 * Tom Lane wrote: > "Peter Darley" writes: > > I have a question about views: I want to have a fairly wide view (lots of > > columns) where most of the columns have some heavyish calculations in them, > > but I'm concerned that it will have to calculate every column even when I'm > > not selecting them. So, the question is, if I have 5 columns in a view but > > only select 1 column, is the system smart enough to not calculate the unused > > columns, > > It depends on what the rest of your view looks like. If the view is > simple enough to be "flattened" into the parent query then the unused > columns will disappear into the ether. If it's not flattenable then > they will get evaluated. You can check by seeing whether an EXPLAIN > shows a separate "subquery scan" node corresponding to the view. > (Without bothering to look at the code, an unflattenable view is one > that uses GROUP BY, DISTINCT, aggregates, ORDER BY, LIMIT, UNION, > INTERSECT, EXCEPT, probably a couple other things.) What about functions ? I'm using several (immutable) functions for mapping IDs to names, etc. cu -- --------------------------------------------------------------------- Enrico Weigelt == metux IT service phone: +49 36207 519931 www: http://www.metux.de/ fax: +49 36207 519932 email: contact@metux.de cellphone: +49 174 7066481 --------------------------------------------------------------------- -- DSL ab 0 Euro. -- statische IP -- UUCP -- Hosting -- Webshops -- ---------------------------------------------------------------------