Re: Index optimization ? - Mailing list pgsql-general

From Tom Lane
Subject Re: Index optimization ?
Date
Msg-id 10434.1105813669@sss.pgh.pa.us
Whole thread Raw
In response to Index optimization ?  (Bo Lorentsen <bl@netgroup.dk>)
Responses Re: Index optimization ?
Re: Index optimization ?
List pgsql-general
Bo Lorentsen <bl@netgroup.dk> writes:
> select * from sale where id = currval( 'sale_id_seq' );

This is not legally optimizable into an indexscan, because currval() is
a volatile function.  (It's easy to construct cases where its value
actually does change from row to row --- just use a nextval() as well.)

You can fake it out in a couple of ways --- the recommended method is to
wrap currval in a user-defined function that is misleadingly marked
stable.  I think it still works to just put the call in a sub-select:
    select * from sale where id = (select currval( 'sale_id_seq' ));
but I take no responsibility if future improvements in the planner break
that trick.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Pgsql taking a *lot* of CPU time (unkillable).
Next
From: Michael Fuhr
Date:
Subject: Re: Index optimization ?