Re: [HACKERS] function(contants) evaluated for every row

2011-03-10 Thread Bruce Momjian
Robert Haas wrote: 2010/11/25 pasman pasma?ski pasma...@gmail.com: I've seen this as well be a performance issue, in particular with partitioned tables. Out of habit I now write functions that always cache the value of the function in a variable and use the variable in the actual query to

Re: [HACKERS] function(contants) evaluated for every row

2011-03-10 Thread Robert Haas
On Thu, Mar 10, 2011 at 7:32 PM, Bruce Momjian br...@momjian.us wrote: Robert Haas wrote: 2010/11/25 pasman pasma?ski pasma...@gmail.com: I've seen this as well be a performance issue, in particular with partitioned tables. Out of habit I now write functions that always cache the value of

Re: [HACKERS] function(contants) evaluated for every row

2010-11-27 Thread Robert Haas
2010/11/25 pasman pasmański pasma...@gmail.com: I've seen this as well be a performance issue, in particular with partitioned tables. Out of habit I now write functions that always cache the value of the function in a variable and use the variable in the actual query to avoid this particular

Re: [HACKERS] function(contants) evaluated for every row

2010-11-25 Thread pasman pasmański
I've seen this as well be a performance issue, in particular with partitioned tables. Out of habit I now write functions that always cache the value of the function in a variable and use the variable in the actual query to avoid this particular gotcha. subquery may be used to cache constants:

[HACKERS] function(contants) evaluated for every row

2010-11-24 Thread Bruce Momjian
Someone offlist reported query slowness because we don't convert function calls with all-constant parameters to be a constants before we start a sequential scan: EXPLAIN SELECT * FROM test WHERE x = to_date('2001-01-01', '-MM-DD') AND x =

Re: [HACKERS] function(contants) evaluated for every row

2010-11-24 Thread Tom Lane
Bruce Momjian br...@momjian.us writes: Notice the to_date()'s were not converted to constants in EXPLAIN so they are evaluated for every row. to_date() is marked STABLE. Is this something we should improve? No. This is per expectation. Only IMMUTABLE functions can be folded to constants in

Re: [HACKERS] function(contants) evaluated for every row

2010-11-24 Thread Bruce Momjian
Tom Lane wrote: Bruce Momjian br...@momjian.us writes: Notice the to_date()'s were not converted to constants in EXPLAIN so they are evaluated for every row. to_date() is marked STABLE. Is this something we should improve? No. This is per expectation. Only IMMUTABLE functions can be

Re: [HACKERS] function(contants) evaluated for every row

2010-11-24 Thread Tom Lane
Bruce Momjian br...@momjian.us writes: I realize they can't be converted to constants before the query starts but is there a reason we can't convert those functions to constants in the executor before a table scan? Other than the significant number of cycles that would be wasted (in most

Re: [HACKERS] function(contants) evaluated for every row

2010-11-24 Thread Marti Raudsepp
On Wed, Nov 24, 2010 at 21:52, Tom Lane t...@sss.pgh.pa.us wrote: Bruce Momjian br...@momjian.us writes: Notice the to_date()'s were not converted to constants in EXPLAIN so they are evaluated for every row.  to_date() is marked STABLE. No.  This is per expectation.  Only IMMUTABLE functions

Re: [HACKERS] function(contants) evaluated for every row

2010-11-24 Thread Michael Glaesemann
On Nov 24, 2010, at 15:28 , Marti Raudsepp wrote: On Wed, Nov 24, 2010 at 21:52, Tom Lane t...@sss.pgh.pa.us wrote: Bruce Momjian br...@momjian.us writes: Notice the to_date()'s were not converted to constants in EXPLAIN so they are evaluated for every row. to_date() is marked STABLE.