Re: session persistent data for plperl

From: "Thomas Hallgren" <thhal(at)mailblocks(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: session persistent data for plperl
Date: 2004-02-08 17:54:48
Message-ID: c05t4e$21v8$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

What about transactions? Let's say the first call was in a transaction
that's been rolled back. Semantically, that means the call never happened.
If you maintain the session data in a table, everything is fine of course.
But if it's in memory the solution has some rather nasty implications to it.

This is one scenario where I think it would be useful if the backend
provided some transaction callback mechanisms (discussed in this group
earlier under topic "Transaction callback"). That would enable the
implementation of "transaction aware session persistent data" in memory.

Regards,

- thomas

"Andrew Dunstan" <andrew(at)dunslane(dot)net> wrote in message
news:402672F4(dot)4050905(at)dunslane(dot)net(dot)(dot)(dot)
>
> The attached tiny patch (not intended for application yet) provides a
> space for plperl functions to create and share session persistent data,
> which I should think would increase the utility of plperl. Essentially
> it creates a hash called %session_globals which it then injects into the
> safe container where plperl functions live.
>
> Comments are welcome - this is just a proof of concept. If this seems
> good to people, I will try to use a similar mechanism to "register"
> plperl functions so they can call each other.
>
> cheers
>
> andrew
>
> (stupid) example use (using dollar quoting in psql ;-) ):
>
> andrew=# create function perlfunc() returns text language plperl as $$
> andrew$# if (!exists $session_globals{x}) { $session_globals{x} =
> 'abcxyz'; }
> andrew$# return $session_globals{x}++;
> andrew$# $$;
> CREATE FUNCTION
> andrew=# select perlfunc();
> perlfunc
> ----------
> abcxyz
> (1 row)
>
> andrew=# select perlfunc();
> perlfunc
> ----------
> abcxza
> (1 row)
>
> andrew=# create function perlfunc2() returns text language plperl as $$
> andrew$# if (!exists $session_globals{x}) { $session_globals{x} =
> 'abcxyz'; }
> andrew$# $session_globals{x} = reverse $session_globals{x};
> andrew$# return $session_globals{x}++;
> andrew$# $$;
> CREATE FUNCTION
> andrew=# select perlfunc2();
> perlfunc2
> -----------
> bzxcba
> (1 row)
>
> andrew=# select perlfunc2();
> perlfunc2
> -----------
> bbcxzb
> (1 row)
>
> andrew=# select perlfunc();
> perlfunc
> ----------
> bbcxzc
> (1 row)
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2004-02-08 18:04:54 Re: session persistent data for plperl
Previous Message Andrew Dunstan 2004-02-08 17:33:40 session persistent data for plperl