function(contants) evaluated for every row - Mailing list pgsql-hackers

From Bruce Momjian
Subject function(contants) evaluated for every row
Date
Msg-id 201011241936.oAOJa8h04792@momjian.us
Whole thread Raw
Responses Re: function(contants) evaluated for every row
List pgsql-hackers
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', 'YYYY-MM-DD') AND     x <= to_date('2001-01-01',
'YYYY-MM-DD');                                                         QUERY
PLAN-------------------------------------------------------------------------------------------------------------------------------
SeqScan on test  (cost=0.00..58.00 rows=12 width=4)   Filter: ((x >= to_date('2001-01-01'::text, 'YYYY-MM-DD'::text))
AND(x<= to_date('2001-01-01'::text, 'YYYY-MM-DD'::text)))(2 rows)
 

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?

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com
 + It's impossible for everything to be true. +


pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: profiling connection overhead
Next
From: Tom Lane
Date:
Subject: Re: function(contants) evaluated for every row