Calculation of unused columns

From: Volker Grabsch <vog(at)notjusthosting(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Calculation of unused columns
Date: 2009-10-17 22:58:16
Message-ID: 20091017225816.GA21163@flap
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Dear PostgreSQL developers,

I'm confused about the absence of a very simple optimization
in PostgreSQL. Suppose we have a VIEW where some columns are
expensive to be calculated:

CREATE VIEW a AS
SELECT
(... expensive calculation ...) as expensive,
count(*) as cheap
FROM
x;

where "x" is a sufficiently large table. I would expect the
following query to be very fast:

SELECT cheap FROM a;

However, it takes the same time as "SELECT * FROM a;".

In other words: The column "expensive" is calculated although
it hasn't been asked for. Of course, there are work-arounds
for that, but I wonder why PostgreSQL doesn't perform this
small optimization by itself.

I checked that behaviour with PostgreSQL 8.3.7 (Debian/Etch)
and 8.4.1 (Debian/Lenny).

Greets,

Volker

--
Volker Grabsch
---<<(())>>---
Administrator
NotJustHosting GbR

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2009-10-18 00:07:21 Re: Calculation of unused columns
Previous Message Jeff Janes 2009-10-17 21:24:40 Re: Indexes on low cardinality columns