dynamic-static date - Mailing list pgsql-bugs

From Tomasz Myrta
Subject dynamic-static date
Date
Msg-id 3B9F537A.9230A1@lamer.pl
Whole thread Raw
Responses Re: dynamic-static date  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
I have something like this:

billy=# EXPLAIN SELECT * from kursy where id_trasy=1 and
data_kursu=date('2001-12-12');
NOTICE:  QUERY PLAN:
Index Scan using pp on kursy  (cost=0.00..51.55 rows=1 width=18)

billy=# EXPLAIN SELECT * from kursy where id_trasy=1
and data_kursu='2001-12-12';
NOTICE:  QUERY PLAN:
Index Scan using pp on kursy  (cost=0.00..2.02 rows=1 width=18)

Why the first expression is 25 times slower?
I suppose, that planner thinks, that date('2001-12-12') is a dynamic
variable - is it true? I found this problem when i had to add date and
integer. Little "iscachable" function helped me, but I still don't know
why it happened.

CREATE FUNCTION date_sum(date,integer) returns date AS'
BEGIN
  return $1+$2;
END;
'LANGUAGE 'plpgsql' WITH (iscachable);

pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: Bug #449: there is a problem with foreign key
Next
From: Stephan Szabo
Date:
Subject: Re: Bug #449: there is a problem with foreign key