Skip site navigation (1) Skip section navigation (2)

Re: function(contants) evaluated for every row

From: pasman pasmański <pasman(dot)p(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: function(contants) evaluated for every row
Date: 2010-11-25 09:57:26
Message-ID: AANLkTi=9YJuaB7-qto9fTN74wak8FJA59P1wrSCn9-zg@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
>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:

SELECT a_date
  FROM test
  WHERE a_date=(SELECT current_date);


"Seq Scan on test1  (cost=0.01..10.76 rows=5 width=4)"
"  Filter: (a_date = $0)"
"  InitPlan 1 (returns $0)"
"    ->  Result  (cost=0.00..0.01 rows=1 width=0)"


------------
pasman

Responses

pgsql-hackers by date

Next:From: Itagaki TakahiroDate: 2010-11-25 09:58:53
Subject: Re: dblink versus long connection strings
Previous:From: Maciek SakrejdaDate: 2010-11-25 09:56:02
Subject: Re: [JDBC] JDBC and Binary protocol error, for some statements

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group