Re: [9.0] On temporary tables

From: Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: [9.0] On temporary tables
Date: 2010-10-01 09:20:36
Message-ID: AANLkTinVZMkUspPBpn5HzX2z014aeOV0BhLd1RyxaBN3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2010/9/30 Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it>:
> 2010/9/30 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> Vincenzo Romano <vincenzo(dot)romano(at)notorand(dot)it> writes:
>>> create or replace function session_init()
>>> returns void
>>> language plpgsql
>>> as $body$
>>> declare
>>>   t text;
>>> begin
>>>   select valu into t from session where name='SESSION_ID';
>>>   if not found then
>>>     create temporary table session ( like public.session including all );
>>>     insert into session values ( 'SESSION_ID',current_user );
>>>   end if;
>>> end;
>>> $body$;
>>
>>> The idea is to create a temporary table to store session variables
>>> only of there's no temporary table with that name.
>>
>> That isn't going to work tremendously well.  plpgsql will cache a plan
>> for that SELECT on first use, and creation of the temp table is not an
>> event that will cause replanning of a select that doesn't already use
>> the temp table.

Quoting from documentation (v9.0.0 at chapter 35.6, v8.4.4 at chapter 34.6)
"A VOLATILE function can do anything, including modifying the
database. It can return different
results on successive calls with the same arguments. The optimizer
makes no assumptions about
the behavior of such functions. A query using a volatile function will
re-evaluate the function at
every row where its value is needed."

So, my question below stands still.

> Is the planner caching the plan even in case of VOLATILE functions?

I was expecting a volatile function not to be planned at definition
time, but rather at
execution time.
Is this assumption wrong?

--
Vincenzo Romano at NotOrAnd Information Technologies
Software Hardware Networking Training Support Security
--
NON QVIETIS MARIBVS NAVTA PERITVS

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dave Page 2010-10-01 09:27:34 Re: PostgreSQL 9.0 (x86-64) and Windows 7 (x86-64) - Unable to install
Previous Message Vishnu S. 2010-10-01 09:14:31 Slony-I cluster creation Help.