Re: session persistent data for plperl - Mailing list pgsql-hackers

From Thomas Hallgren
Subject Re: session persistent data for plperl
Date
Msg-id c05t4e$21v8$1@news.hub.org
Whole thread Raw
In response to session persistent data for plperl  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: session persistent data for plperl  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: session persistent data for plperl  (Andrew Dunstan <andrew@dunslane.net>)
List 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@dunslane.net> wrote in message
news:402672F4.4050905@dunslane.net...
>
> 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
>




pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: session persistent data for plperl
Next
From: Tom Lane
Date:
Subject: Re: RFC: Security documentation