Re: Note about comparation PL/SQL packages and our schema/extensions

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Note about comparation PL/SQL packages and our schema/extensions
Date: 2015-11-05 12:31:44
Message-ID: CAMsr+YEzL9oOwWRv7ub7U-X8R+HQkXcxbiFC5iptW7GvDs3+-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 5 November 2015 at 14:36, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> 1. The encapsulation and local scope - all objects in schema are accessible
> from other objects in schema by default (can be rewritten by explicit
> granting). Local objects are visible only from objects in schema. This needs
> enhancing of our search_path mechanism.

Yep. It's as if, within function packagename.funcname, packagename is
implicitly prefixed to search_path .

I can see that being handy, but not especially important.

> 2. The schema variables - a server side session (can be emulated now) and
> server side local schema session variables (doesn't exist) is pretty useful
> for storing some temp data or high frequent change data - and can
> significantly increase speed of some use cases. Now we emulate it via PLPerl
> shared array, but the encapsulation is missing.

This is the feature I feel we could really use.

I see *lots* of people emulating session variables by (ab)using custom
GUCs. The missing-ok variant of current_setting helps with this to the
point where it's fairly OK now.

The main advantage package variables have - IMO - are package
permissions. You can define a variable that is writeable only by
functions within a package. That's really handy for things like row
security since it lets you have variables you can only set via a
function that can do things like refuse to run again with different
args, validate input, etc. So you can do expensive work once, then
cheap row security checks against the preset variable. Or use it for
things like "current customer" settings when using pooled connections.

It might make sense to extend custom GUCs for this rather than invent
a new mechanism, since GUCs have lots of useful properties like
global, db, user, session and transaction scoping, etc. I'm not really
sure... I just agree that it's a good idea to be able to have
something with similar capabilities to package variables. Especially
security properties.

> 3. The initialization routines - the routines called when any object from
> schema is used first time.

... which is somewhat similar to having an "on session start" trigger.
Also an oft-wanted feature.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2015-11-05 12:42:50 Re: Request: pg_cancel_backend variant that handles 'idle in transaction' sessions
Previous Message Fabien COELHO 2015-11-05 12:00:04 Re: extend pgbench expressions with functions