how much volatile is a function

Started by Anibal David Acostaover 13 years ago4 messagesgeneral
Jump to latest
#1Anibal David Acosta
aa@devshock.com

I have a table, this table are rarely changed (added or deleted).

My function receive parameters and do a query to the table.

Does postgres re run the query on each function call, or has some kind of
"flag" indicating that table as not been changed and return cached result of
a previous call if the call has same parameters?

Thanks!

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Anibal David Acosta (#1)
Re: how much volatile is a function

From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Anibal David Acosta
Sent: Thursday, July 12, 2012 2:39 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] how much volatile is a function

I have a table, this table are rarely changed (added or deleted).
My function receive parameters and do a query to the table.

Does postgres re run the query on each function call, or has some kind of
"flag" indicating that table as not been changed and return cached result of
a previous call if the call has same parameters?

Thanks!

==============================================

See here:

http://www.postgresql.org/docs/9.1/interactive/sql-createfunction.html

Read the difference between IMMUTABLE, STABLE, and VOLATILE

David J.

#3Sergey Konoplev
sergey.konoplev@postgresql-consulting.com
In reply to: Anibal David Acosta (#1)
Re: how much volatile is a function

On Thu, Jul 12, 2012 at 10:38 PM, Anibal David Acosta <aa@devshock.com> wrote:

Does postgres re run the query on each function call, or has some kind of
“flag” indicating that table as not been changed and return cached result of
a previous call if the call has same parameters?

It does re-run it on each call.

--
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: gray.ru@gmail.com Skype: gray-hemp Phone: +79160686204

#4Sergey Konoplev
sergey.konoplev@postgresql-consulting.com
In reply to: Sergey Konoplev (#3)
Re: how much volatile is a function

On Thu, Jul 12, 2012 at 10:55 PM, Sergey Konoplev
<sergey.konoplev@postgresql-consulting.com> wrote:

On Thu, Jul 12, 2012 at 10:38 PM, Anibal David Acosta <aa@devshock.com> wrote:

Does postgres re run the query on each function call, or has some kind of
“flag” indicating that table as not been changed and return cached result of
a previous call if the call has same parameters?

It does re-run it on each call.

ps. Do not get confused with IMMUTABLE, STABLE and VOLATILE flags. It
is kind of promising to the planner that the function will behave like
specified.

--
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: gray.ru@gmail.com Skype: gray-hemp Phone: +79160686204

--
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: gray.ru@gmail.com Skype: gray-hemp Phone: +79160686204