Calculation of unused columns - Mailing list pgsql-performance

From Volker Grabsch
Subject Calculation of unused columns
Date
Msg-id 20091017225816.GA21163@flap
Whole thread Raw
Responses Re: Calculation of unused columns
List 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

pgsql-performance by date:

Previous
From: Jeff Janes
Date:
Subject: Re: Indexes on low cardinality columns
Next
From: Tom Lane
Date:
Subject: Re: Calculation of unused columns