X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 8D580D1DCF5 for ; Tue, 13 Apr 2004 18:23:38 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 08836-07 for ; Tue, 13 Apr 2004 18:23:38 -0300 (ADT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id B975CD1DB87 for ; Tue, 13 Apr 2004 18:23:35 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i3DLNaUe026712; Tue, 13 Apr 2004 17:23:36 -0400 (EDT) To: "Peter Darley" Cc: "Pgsql-Performance" Subject: Re: View columns calculated In-reply-to: References: Comments: In-reply-to "Peter Darley" message dated "Tue, 13 Apr 2004 13:49:53 -0700" Date: Tue, 13 Apr 2004 17:23:36 -0400 Message-ID: <26711.1081891416@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/160 X-Sequence-Number: 6460 "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.) regards, tom lane