function(contants) evaluated for every row

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: function(contants) evaluated for every row
Date: 2010-11-24 19:36:08
Message-ID: 201011241936.oAOJa8h04792@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
-------------------------------------------------------------------------------------------------------------------------------

Seq Scan 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(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-11-24 19:52:22 Re: function(contants) evaluated for every row
Previous Message Andres Freund 2010-11-24 19:32:20 Re: profiling connection overhead