Feature request: optimizer improvement - Mailing list pgsql-hackers

From Joe Love
Subject Feature request: optimizer improvement
Date
Msg-id CAK3BLoSan3o2a9kLVDetkor-zyqn-1jmc0Y-rPtiS9a+uFL-uA@mail.gmail.com
Whole thread Raw
Responses Handle LIMIT/OFFSET before select clause (was: Feature request: optimizer improvement)
List pgsql-hackers
In postgres 9.2 I have a function that is relatively expensive.  When I write a query such as:

select expensive_function(o.id),o.* from offeirng o where valid='Y' order by name limit 1;

the query runs slow and appears to be running the function on each ID, which in this case should be totally unnecessary as it really only needs to run on 1 row.

When I rewrite the query like so:

select expensive_function(o.id), o.*
from (select *offering where valid='Y' order by name limit 1) o;

the expensive function only runs once and thus, much faster. I would think that the optimizer could handle this situation, especially when limit or offset is used and the expensive function is not used in a group by, order by or where.

pgsql-hackers by date:

Previous
From: Antonin Houska
Date:
Subject: Re: Reference to parent query from ANY sublink
Next
From: Kevin Grittner
Date:
Subject: Re: [BUGS] BUG #8542: Materialized View with another column_name does not work?