Re: Views- Advantages and Disadvantages

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Views- Advantages and Disadvantages
Date: 2007-05-10 17:23:09
Message-ID: 17452.1178817789@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Leif B. Kristensen" <leif(at)solumslekt(dot)org> writes:
> [ this query got slow in 8.2: ]
> $query = "select person_id, pb_date from tmg_persons
> where father_id = $p or mother_id = $p
> order by pb_date";

> tmg_persons is a view involving several function calls, and is a legacy
> from an earlier, flatter data model where the 'persons' table actually
> had this structure. I'm still using it in my Web application, and the
> primary function of the view is to make an easy export:

> CREATE OR REPLACE VIEW tmg_persons AS
> SELECT
> person_id,
> get_parent(person_id,1) AS father_id,
> get_parent(person_id,2) AS mother_id,
> last_edit,
> get_pbdate(person_id) AS pb_date,
> get_pddate(person_id) AS pd_date,
> gender AS s,
> living AS l,
> is_public AS p
> FROM persons;

Are get_parent() and/or get_pbdate() marked volatile by any chance?
8.2 is more conservative about optimizing sub-selects involving volatile
functions than previous releases were, because we got complaints about
surprising behavior when a volatile function is executed more or fewer
times than the text of the query would suggest. If they are really
stable or immutable, marking them so would probably help here. (If they
fetch from another table, stable is the right marking.)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Leif B. Kristensen 2007-05-10 17:43:28 Re: Views- Advantages and Disadvantages
Previous Message David Wall 2007-05-10 16:39:34 Re: Replication for PG 8 recommendations