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 wrote: > Robert Haas wrote: >> 2010/11/25 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

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

2011-03-10 Thread Bruce Momjian
Robert Haas wrote: > 2010/11/25 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 avo

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

2010-11-27 Thread Robert Haas
2010/11/25 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".

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 cons

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 wrote: >> Bruce Momjian 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 expectat

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

2010-11-24 Thread Marti Raudsepp
On Wed, Nov 24, 2010 at 21:52, Tom Lane wrote: > Bruce Momjian 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 can be folded to > constants

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

2010-11-24 Thread Tom Lane
Bruce Momjian 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 cases) checking for

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

2010-11-24 Thread Bruce Momjian
Tom Lane wrote: > Bruce Momjian 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

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

2010-11-24 Thread Tom Lane
Bruce Momjian 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 advance of th

[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 <= to_date('20