Skip site navigation (1) Skip section navigation (2)

Re: View columns calculated

From: Enrico Weigelt <weigelt(at)metux(dot)de>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: View columns calculated
Date: 2005-03-24 13:48:05
Message-ID: 20050324134805.GC31203@nibiru.borg.metux.de (view raw or flat)
Thread:
Lists: pgsql-performance
* Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Peter Darley" <pdarley(at)kinesis-cem(dot)com> 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(at)metux(dot)de
  cellphone: +49 174 7066481
---------------------------------------------------------------------
 -- DSL ab 0 Euro. -- statische IP -- UUCP -- Hosting -- Webshops --
---------------------------------------------------------------------

In response to

pgsql-performance by date

Next:From: Patrick VedrinesDate: 2005-03-24 14:04:08
Subject: Re: CPU 0.1% IOWAIT 99% for decisonnal queries
Previous:From: Alvaro HerreraDate: 2005-03-24 13:42:40
Subject: Re: clear function cache (WAS: SQL function inlining)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group