pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Darley <pdarley@kinesis-cem.com>
Cc: Pgsql-Performance <pgsql-performance@postgresql.org>
Subject: Re: View columns calculated
Date: Tue, 13 Apr 2004 17:23:36 -0400
Message-ID: <26711.1081891416@sss.pgh.pa.us> (raw)
In-Reply-To: <PDEOIIFFBIAABMGNJAGPEEGJDEAA.pdarley@kinesis-cem.com>
References: <PDEOIIFFBIAABMGNJAGPEEGJDEAA.pdarley@kinesis-cem.com>

"Peter Darley" <pdarley@kinesis-cem.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



view thread (3+ messages)  latest in thread

Message-ID: <26711.1081891416@sss.pgh.pa.us>
Permalink:  ../26711.1081891416@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/26711.1081891416@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pdarley@kinesis-cem.com
  Subject: Re: View columns calculated
  In-Reply-To: <26711.1081891416@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox