Re: View columns calculated

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Peter Darley" <pdarley(at)kinesis-cem(dot)com>
Cc: "Pgsql-Performance" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: View columns calculated
Date: 2004-04-13 21:23:36
Message-ID: 26711.1081891416@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"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.)

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Pailloncy Jean-Gérard 2004-04-14 12:39:21
Previous Message Joshua D. Drake 2004-04-13 20:59:13 Re: configure shmmax on MAC OS X