Re: proposal: schema variables

Lists: pgsql-hackerspgsql-performance
From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal: schema variables
Date: 2017-10-26 07:21:24
Message-ID: CAFj8pRDY+m9OOxfO10R7J0PAkCCauM-TweaTrdsrsLGMb1VbEQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi,

I propose a new database object - a variable. The variable is persistent
object, that holds unshared session based not transactional in memory value
of any type. Like variables in any other languages. The persistence is
required for possibility to do static checks, but can be limited to session
- the variables can be temporal.

My proposal is related to session variables from Sybase, MSSQL or MySQL
(based on prefix usage @ or @@), or package variables from Oracle (access
is controlled by scope), or schema variables from DB2. Any design is coming
from different sources, traditions and has some advantages or
disadvantages. The base of my proposal is usage schema variables as session
variables for stored procedures. It should to help to people who try to
port complex projects to PostgreSQL from other databases.

The Sybase (T-SQL) design is good for interactive work, but it is weak for
usage in stored procedures - the static check is not possible. Is not
possible to set some access rights on variables.

The ADA design (used on Oracle) based on scope is great, but our
environment is not nested. And we should to support other PL than PLpgSQL
more strongly.

There is not too much other possibilities - the variable that should be
accessed from different PL, different procedures (in time) should to live
somewhere over PL, and there is the schema only.

The variable can be created by CREATE statement:

CREATE VARIABLE public.myvar AS integer;
CREATE VARIABLE myschema.myvar AS mytype;

CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
[ DEFAULT expression ] [[NOT] NULL]
[ ON TRANSACTION END { RESET | DROP } ]
[ { VOLATILE | STABLE } ];

It is dropped by command DROP VARIABLE [ IF EXISTS] varname.

The access rights is controlled by usual access rights - by commands
GRANT/REVOKE. The possible rights are: READ, WRITE

The variables can be modified by SQL command SET (this is taken from
standard, and it natural)

SET varname = expression;

Unfortunately we use the SET command for different purpose. But I am
thinking so we can solve it with few tricks. The first is moving our GUC to
pg_catalog schema. We can control the strictness of SET command. In one
variant, we can detect custom GUC and allow it, in another we can disallow
a custom GUC and allow only schema variables. A new command LET can be
alternative.

The variables should be used in queries implicitly (without JOIN)

SELECT varname;

The SEARCH_PATH is used, when varname is located. The variables can be used
everywhere where query parameters are allowed.

I hope so this proposal is good enough and simple.

Comments, notes?

regards

Pavel


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-26 22:07:33
Message-ID: 20171026220732.GI4496@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Oct 26, 2017 at 09:21:24AM +0200, Pavel Stehule wrote:
> Comments, notes?

I like it.

I would further like to move all of postgresql.conf into the database,
as much as possible, as well as pg_ident.conf and pg_hba.conf.

Variables like current_user have a sort of nesting context
functionality: calling a SECURITY DEFINER function "pushes" a new value
onto current_user, then when the function returns the new value of
current_user is "popped" and the previous value restored.

It might be nice to be able to generalize this.

Questions that then arise:

- can one see up the stack?
- are there permissions issues with seeing up the stack?

I recently posted proposing a feature such that SECURITY DEFINER
functions could observe the _caller_'s current_user.

Nico
--


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Nico Williams <nico(at)cryptonector(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-27 05:08:43
Message-ID: CAFj8pRAemkdaDuoRQzrhs2GU59Bb_yHuquJC6nyrwGHfVdLuLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2017-10-27 0:07 GMT+02:00 Nico Williams <nico(at)cryptonector(dot)com>:

> On Thu, Oct 26, 2017 at 09:21:24AM +0200, Pavel Stehule wrote:
> > Comments, notes?
>
> I like it.
>
> I would further like to move all of postgresql.conf into the database,
> as much as possible, as well as pg_ident.conf and pg_hba.conf.
>
> Variables like current_user have a sort of nesting context
> functionality: calling a SECURITY DEFINER function "pushes" a new value
> onto current_user, then when the function returns the new value of
> current_user is "popped" and the previous value restored.
>

My proposal doesn't expecting with nesting, because there is only one scope
- schema / session - but I don't think so it is necessary

current_user is a function - it is based on parser magic in Postgres. The
origin from Oracle uses the feature of ADA language. When function has no
parameters then parenthesis are optional. So current_user, current_time are
functions current_user(), current_time().

> It might be nice to be able to generalize this.
>
> Questions that then arise:
>
> - can one see up the stack?
> - are there permissions issues with seeing up the stack?
>

these variables are pined to schema - so there is not any relation to
stack. It is like global variables.

Theoretically we can introduce "functional" variables, where the value is
based on immediate evaluation of expression. It can be very similar to
current current_user.

>
>
> I recently posted proposing a feature such that SECURITY DEFINER
> functions could observe the _caller_'s current_user.
>

your use case is good example - this proposed feature doesn't depend on
stack, depends on security context (security context stack) what is super
set of call stack

Regards

Pavel

> Nico
> --
>


From: Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp>
To: pavel(dot)stehule(at)gmail(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2017-10-27 05:30:11
Message-ID: 20171027.143011.1825346140110310923.t-ishii@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> Hi,
>
> I propose a new database object - a variable. The variable is persistent
> object, that holds unshared session based not transactional in memory value
> of any type. Like variables in any other languages. The persistence is
> required for possibility to do static checks, but can be limited to session
> - the variables can be temporal.
>
> My proposal is related to session variables from Sybase, MSSQL or MySQL
> (based on prefix usage @ or @@), or package variables from Oracle (access
> is controlled by scope), or schema variables from DB2. Any design is coming
> from different sources, traditions and has some advantages or
> disadvantages. The base of my proposal is usage schema variables as session
> variables for stored procedures. It should to help to people who try to
> port complex projects to PostgreSQL from other databases.
>
> The Sybase (T-SQL) design is good for interactive work, but it is weak for
> usage in stored procedures - the static check is not possible. Is not
> possible to set some access rights on variables.
>
> The ADA design (used on Oracle) based on scope is great, but our
> environment is not nested. And we should to support other PL than PLpgSQL
> more strongly.
>
> There is not too much other possibilities - the variable that should be
> accessed from different PL, different procedures (in time) should to live
> somewhere over PL, and there is the schema only.
>
> The variable can be created by CREATE statement:
>
> CREATE VARIABLE public.myvar AS integer;
> CREATE VARIABLE myschema.myvar AS mytype;
>
> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
> [ DEFAULT expression ] [[NOT] NULL]
> [ ON TRANSACTION END { RESET | DROP } ]
> [ { VOLATILE | STABLE } ];
>
> It is dropped by command DROP VARIABLE [ IF EXISTS] varname.
>
> The access rights is controlled by usual access rights - by commands
> GRANT/REVOKE. The possible rights are: READ, WRITE
>
> The variables can be modified by SQL command SET (this is taken from
> standard, and it natural)
>
> SET varname = expression;
>
> Unfortunately we use the SET command for different purpose. But I am
> thinking so we can solve it with few tricks. The first is moving our GUC to
> pg_catalog schema. We can control the strictness of SET command. In one
> variant, we can detect custom GUC and allow it, in another we can disallow
> a custom GUC and allow only schema variables. A new command LET can be
> alternative.
>
> The variables should be used in queries implicitly (without JOIN)
>
> SELECT varname;
>
> The SEARCH_PATH is used, when varname is located. The variables can be used
> everywhere where query parameters are allowed.
>
> I hope so this proposal is good enough and simple.
>
> Comments, notes?

Just q quick follow up. Looks like a greate feature!

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp


From: "Tsunakawa, Takayuki" <tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com>
To: 'Pavel Stehule' <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-27 05:47:29
Message-ID: 0A3221C70F24FB45833433255569204D1F80CE8C@G01JPEXMBYT05
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

From: pgsql-hackers-owner(at)postgresql(dot)org
> [mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of Pavel Stehule
> I propose a new database object - a variable. The variable is persistent
> object, that holds unshared session based not transactional in memory value
> of any type. Like variables in any other languages. The persistence is
> required for possibility to do static checks, but can be limited to session
> - the variables can be temporal.
>
>
> My proposal is related to session variables from Sybase, MSSQL or MySQL
> (based on prefix usage @ or @@), or package variables from Oracle (access
> is controlled by scope), or schema variables from DB2. Any design is coming
> from different sources, traditions and has some advantages or disadvantages.
> The base of my proposal is usage schema variables as session variables for
> stored procedures. It should to help to people who try to port complex
> projects to PostgreSQL from other databases.

Very interesting. I hope I could join the review and testing.

How do you think this would contribute to easing the port of Oracle PL/SQL procedures? Would the combination of orafce and this feature promote auto-translation of PL/SQL procedures? I'm curious what will be the major road blocks after adding the schema variable.

Regards
Takayuki Tsunakawa


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "Tsunakawa, Takayuki" <tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-27 06:16:56
Message-ID: CAFj8pRBFiNRKe3EqLmouyPJzzQvcWTfw++x1uEcRCey4rbwCvQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-10-27 7:47 GMT+02:00 Tsunakawa, Takayuki <
tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com>:

> From: pgsql-hackers-owner(at)postgresql(dot)org
> > [mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of Pavel Stehule
> > I propose a new database object - a variable. The variable is persistent
> > object, that holds unshared session based not transactional in memory
> value
> > of any type. Like variables in any other languages. The persistence is
> > required for possibility to do static checks, but can be limited to
> session
> > - the variables can be temporal.
> >
> >
> > My proposal is related to session variables from Sybase, MSSQL or MySQL
> > (based on prefix usage @ or @@), or package variables from Oracle (access
> > is controlled by scope), or schema variables from DB2. Any design is
> coming
> > from different sources, traditions and has some advantages or
> disadvantages.
> > The base of my proposal is usage schema variables as session variables
> for
> > stored procedures. It should to help to people who try to port complex
> > projects to PostgreSQL from other databases.
>
> Very interesting. I hope I could join the review and testing.
>

you are welcome. I wrote a prototype last year based on envelope functions.
But the integration must be much more close to SQL to be some clear benefit
of this feature. So there is lot of work. I hope so I have a prototype
after this winter. It is my plan for winter.

>
> How do you think this would contribute to easing the port of Oracle PL/SQL
> procedures? Would the combination of orafce and this feature promote
> auto-translation of PL/SQL procedures? I'm curious what will be the major
> road blocks after adding the schema variable.
>

It depends on creativity of PL/SQL developers. Usual .. 80% application is
possible to migrate with current GUC - some work does ora2pg. But GUC is
little bit slower (not too important) and is not simple possibility to
secure it.

So work with variables will be similar like GUC, but significantly more
natural (not necessary to build wrap functions). It should be much better
when value is of some composite type. The migrations will need some
inteligence still, but less work and code will be more readable and cleaner.

I talked already about "schema pined" functions (schema private/public
objects) - but I didn't think about it more deeply. There can be special
access right to schema variables, the pined schema can be preferred before
search_path. With this feature the schema will have very similar behave
like Oracle Modules. Using different words - we can implement scope access
rights based on schemas. But it is far horizon. What is important -
proposal doesn't block any future enhancing in this case, and is consistent
with current state. In future you can work with schema private functions,
tables, variables, sequences. So variables are nothing special.

Regards

Pavel

Regards
> Takayuki Tsunakawa
>
>
>


From: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2017-10-27 13:38:40
Message-ID: cfca987e-8316-9f9d-6a85-f894e66b44c2@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Le 26/10/2017 à 09:21, Pavel Stehule a écrit :
> Hi,
>
> I propose a  new database object - a variable. The variable is
> persistent object, that holds unshared session based not transactional
> in memory value of any type. Like variables in any other languages.
> The persistence is required for possibility to do static checks, but
> can be limited to session - the variables can be temporal.
>
> My proposal is related to session variables from Sybase, MSSQL or
> MySQL (based on prefix usage @ or @@), or package variables from
> Oracle (access is controlled by scope), or schema variables from DB2.
> Any design is coming from different sources, traditions and has some
> advantages or disadvantages. The base of my proposal is usage schema
> variables as session variables for stored procedures. It should to
> help to people who try to port complex projects to PostgreSQL from
> other databases.
>
> The Sybase  (T-SQL) design is good for interactive work, but it is
> weak for usage in stored procedures - the static check is not
> possible. Is not possible to set some access rights on variables.
>
> The ADA design (used on Oracle) based on scope is great, but our
> environment is not nested. And we should to support other PL than
> PLpgSQL more strongly.
>
> There is not too much other possibilities - the variable that should
> be accessed from different PL, different procedures (in time) should
> to live somewhere over PL, and there is the schema only.
>
> The variable can be created by CREATE statement:
>
> CREATE VARIABLE public.myvar AS integer;
> CREATE VARIABLE myschema.myvar AS mytype;
>
> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
>   [ DEFAULT expression ] [[NOT] NULL]
>   [ ON TRANSACTION END { RESET | DROP } ]
>   [ { VOLATILE | STABLE } ];
>
> It is dropped by command DROP VARIABLE  [ IF EXISTS] varname.
>
> The access rights is controlled by usual access rights - by commands
> GRANT/REVOKE. The possible rights are: READ, WRITE
>
> The variables can be modified by SQL command SET (this is taken from
> standard, and it natural)
>
> SET varname = expression;
>
> Unfortunately we use the SET command for different purpose. But I am
> thinking so we can solve it with few tricks. The first is moving our
> GUC to pg_catalog schema. We can control the strictness of SET
> command. In one variant, we can detect custom GUC and allow it, in
> another we can disallow a custom GUC and allow only schema variables.
> A new command LET can be alternative.
>
> The variables should be used in queries implicitly (without JOIN)
>
> SELECT varname;
>
> The SEARCH_PATH is used, when varname is located. The variables can be
> used everywhere where query parameters are allowed.
>
> I hope so this proposal is good enough and simple.
>
> Comments, notes?
>
> regards
>
> Pavel
>
>

Great feature that will help for migration. How will you handle CONSTANT
declaration? With Oracle it is possible to declare a constant as follow:

  varname     CONSTANT INTEGER    := 500;

for a variable that can't be changed. Do you plan to add a CONSTANT or
READONLY keyword or do you want use GRANT on the object to deal with
this case?

Regards

--
Gilles Darold
Consultant PostgreSQL
http://dalibo.com - http://dalibo.org


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-27 14:09:36
Message-ID: CAFj8pRCw5ok00vacRFDT8XpZQC5B=evKE+-TebEKM8-b+AzL8A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-10-27 15:38 GMT+02:00 Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>:

> Le 26/10/2017 à 09:21, Pavel Stehule a écrit :
> > Hi,
> >
> > I propose a new database object - a variable. The variable is
> > persistent object, that holds unshared session based not transactional
> > in memory value of any type. Like variables in any other languages.
> > The persistence is required for possibility to do static checks, but
> > can be limited to session - the variables can be temporal.
> >
> > My proposal is related to session variables from Sybase, MSSQL or
> > MySQL (based on prefix usage @ or @@), or package variables from
> > Oracle (access is controlled by scope), or schema variables from DB2.
> > Any design is coming from different sources, traditions and has some
> > advantages or disadvantages. The base of my proposal is usage schema
> > variables as session variables for stored procedures. It should to
> > help to people who try to port complex projects to PostgreSQL from
> > other databases.
> >
> > The Sybase (T-SQL) design is good for interactive work, but it is
> > weak for usage in stored procedures - the static check is not
> > possible. Is not possible to set some access rights on variables.
> >
> > The ADA design (used on Oracle) based on scope is great, but our
> > environment is not nested. And we should to support other PL than
> > PLpgSQL more strongly.
> >
> > There is not too much other possibilities - the variable that should
> > be accessed from different PL, different procedures (in time) should
> > to live somewhere over PL, and there is the schema only.
> >
> > The variable can be created by CREATE statement:
> >
> > CREATE VARIABLE public.myvar AS integer;
> > CREATE VARIABLE myschema.myvar AS mytype;
> >
> > CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
> > [ DEFAULT expression ] [[NOT] NULL]
> > [ ON TRANSACTION END { RESET | DROP } ]
> > [ { VOLATILE | STABLE } ];
> >
> > It is dropped by command DROP VARIABLE [ IF EXISTS] varname.
> >
> > The access rights is controlled by usual access rights - by commands
> > GRANT/REVOKE. The possible rights are: READ, WRITE
> >
> > The variables can be modified by SQL command SET (this is taken from
> > standard, and it natural)
> >
> > SET varname = expression;
> >
> > Unfortunately we use the SET command for different purpose. But I am
> > thinking so we can solve it with few tricks. The first is moving our
> > GUC to pg_catalog schema. We can control the strictness of SET
> > command. In one variant, we can detect custom GUC and allow it, in
> > another we can disallow a custom GUC and allow only schema variables.
> > A new command LET can be alternative.
> >
> > The variables should be used in queries implicitly (without JOIN)
> >
> > SELECT varname;
> >
> > The SEARCH_PATH is used, when varname is located. The variables can be
> > used everywhere where query parameters are allowed.
> >
> > I hope so this proposal is good enough and simple.
> >
> > Comments, notes?
> >
> > regards
> >
> > Pavel
> >
> >
>
> Great feature that will help for migration. How will you handle CONSTANT
> declaration? With Oracle it is possible to declare a constant as follow:
>
>
> varname CONSTANT INTEGER := 500;
>
>
> for a variable that can't be changed. Do you plan to add a CONSTANT or
> READONLY keyword or do you want use GRANT on the object to deal with
> this case?
>

Plpgsql declaration supports CONSTANT

I forgot it. Thank you

Pavel

>
> Regards
>
> --
> Gilles Darold
> Consultant PostgreSQL
> http://dalibo.com - http://dalibo.org
>
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Chris Travers <chris(dot)travers(at)adjust(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-28 14:24:43
Message-ID: CAN-RpxD0_PFcyM4Lj=a9eQ3MQEiw2_eZwK2peo73hMV0cABmTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Oct 26, 2017 at 9:21 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

> Hi,
>
> I propose a new database object - a variable. The variable is persistent
> object, that holds unshared session based not transactional in memory value
> of any type. Like variables in any other languages. The persistence is
> required for possibility to do static checks, but can be limited to session
> - the variables can be temporal.
>
> My proposal is related to session variables from Sybase, MSSQL or MySQL
> (based on prefix usage @ or @@), or package variables from Oracle (access
> is controlled by scope), or schema variables from DB2. Any design is coming
> from different sources, traditions and has some advantages or
> disadvantages. The base of my proposal is usage schema variables as session
> variables for stored procedures. It should to help to people who try to
> port complex projects to PostgreSQL from other databases.
>
> The Sybase (T-SQL) design is good for interactive work, but it is weak
> for usage in stored procedures - the static check is not possible. Is not
> possible to set some access rights on variables.
>
> The ADA design (used on Oracle) based on scope is great, but our
> environment is not nested. And we should to support other PL than PLpgSQL
> more strongly.
>
> There is not too much other possibilities - the variable that should be
> accessed from different PL, different procedures (in time) should to live
> somewhere over PL, and there is the schema only.
>
> The variable can be created by CREATE statement:
>
> CREATE VARIABLE public.myvar AS integer;
> CREATE VARIABLE myschema.myvar AS mytype;
>
> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
> [ DEFAULT expression ] [[NOT] NULL]
> [ ON TRANSACTION END { RESET | DROP } ]
> [ { VOLATILE | STABLE } ];
>
> It is dropped by command DROP VARIABLE [ IF EXISTS] varname.
>
> The access rights is controlled by usual access rights - by commands
> GRANT/REVOKE. The possible rights are: READ, WRITE
>
> The variables can be modified by SQL command SET (this is taken from
> standard, and it natural)
>
> SET varname = expression;
>
> Unfortunately we use the SET command for different purpose. But I am
> thinking so we can solve it with few tricks. The first is moving our GUC to
> pg_catalog schema. We can control the strictness of SET command. In one
> variant, we can detect custom GUC and allow it, in another we can disallow
> a custom GUC and allow only schema variables. A new command LET can be
> alternative.
>
> The variables should be used in queries implicitly (without JOIN)
>
> SELECT varname;
>
> The SEARCH_PATH is used, when varname is located. The variables can be
> used everywhere where query parameters are allowed.
>
> I hope so this proposal is good enough and simple.
>
> Comments, notes?
>

I have a question on this. Since one can issue set commands on arbitrary
settings (and later ALTER database/role/system on settings you have created
in the current session) I am wondering how much overlap there is between a
sort of extended GUC with custom settings and variables.

Maybe it would be simpler to treat variables and GUC settings to be similar
and see what can be done to extend GUC in this way?

I mean if instead we allowed restricting SET to known settings then we
could have a CREATE SETTING command which would behave like this and then
use SET the same way across both.

In essence I am wondering if this really needs to be as separate from GUC
as you are proposing.

If done this way then:

1. You could issue grant or revoke on GUC settings, allowing some users
but not others to set things like work_mem for their queries
2. You could specify allowed types in custom settings.
3. In a subsequent stage you might be able to SELECT .... INTO
setting_name FROM ....; allowing access to setting writes based on queries.

> regards
>
> Pavel
>
>
>

--
Best Regards,
Chris Travers
Database Administrator

Tel: +49 162 9037 210 | Skype: einhverfr | www.adjust.com
Saarbrücker Straße 37a, 10405 Berlin


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Chris Travers <chris(dot)travers(at)adjust(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-28 14:56:49
Message-ID: CAFj8pRAizy8cFWhf-J9DK-_iZU=VqkwweWL_J9d8Nv2Zep+=Lg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2017-10-28 16:24 GMT+02:00 Chris Travers <chris(dot)travers(at)adjust(dot)com>:

>
>
> On Thu, Oct 26, 2017 at 9:21 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>> Hi,
>>
>> I propose a new database object - a variable. The variable is persistent
>> object, that holds unshared session based not transactional in memory value
>> of any type. Like variables in any other languages. The persistence is
>> required for possibility to do static checks, but can be limited to session
>> - the variables can be temporal.
>>
>> My proposal is related to session variables from Sybase, MSSQL or MySQL
>> (based on prefix usage @ or @@), or package variables from Oracle (access
>> is controlled by scope), or schema variables from DB2. Any design is coming
>> from different sources, traditions and has some advantages or
>> disadvantages. The base of my proposal is usage schema variables as session
>> variables for stored procedures. It should to help to people who try to
>> port complex projects to PostgreSQL from other databases.
>>
>> The Sybase (T-SQL) design is good for interactive work, but it is weak
>> for usage in stored procedures - the static check is not possible. Is not
>> possible to set some access rights on variables.
>>
>> The ADA design (used on Oracle) based on scope is great, but our
>> environment is not nested. And we should to support other PL than PLpgSQL
>> more strongly.
>>
>> There is not too much other possibilities - the variable that should be
>> accessed from different PL, different procedures (in time) should to live
>> somewhere over PL, and there is the schema only.
>>
>> The variable can be created by CREATE statement:
>>
>> CREATE VARIABLE public.myvar AS integer;
>> CREATE VARIABLE myschema.myvar AS mytype;
>>
>> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
>> [ DEFAULT expression ] [[NOT] NULL]
>> [ ON TRANSACTION END { RESET | DROP } ]
>> [ { VOLATILE | STABLE } ];
>>
>> It is dropped by command DROP VARIABLE [ IF EXISTS] varname.
>>
>> The access rights is controlled by usual access rights - by commands
>> GRANT/REVOKE. The possible rights are: READ, WRITE
>>
>> The variables can be modified by SQL command SET (this is taken from
>> standard, and it natural)
>>
>> SET varname = expression;
>>
>> Unfortunately we use the SET command for different purpose. But I am
>> thinking so we can solve it with few tricks. The first is moving our GUC to
>> pg_catalog schema. We can control the strictness of SET command. In one
>> variant, we can detect custom GUC and allow it, in another we can disallow
>> a custom GUC and allow only schema variables. A new command LET can be
>> alternative.
>>
>> The variables should be used in queries implicitly (without JOIN)
>>
>> SELECT varname;
>>
>> The SEARCH_PATH is used, when varname is located. The variables can be
>> used everywhere where query parameters are allowed.
>>
>> I hope so this proposal is good enough and simple.
>>
>> Comments, notes?
>>
>
>
> I have a question on this. Since one can issue set commands on arbitrary
> settings (and later ALTER database/role/system on settings you have created
> in the current session) I am wondering how much overlap there is between a
> sort of extended GUC with custom settings and variables.
>
> Maybe it would be simpler to treat variables and GUC settings to be
> similar and see what can be done to extend GUC in this way?
>
> I mean if instead we allowed restricting SET to known settings then we
> could have a CREATE SETTING command which would behave like this and then
> use SET the same way across both.
>
> In essence I am wondering if this really needs to be as separate from GUC
> as you are proposing.
>
> If done this way then:
>
> 1. You could issue grant or revoke on GUC settings, allowing some users
> but not others to set things like work_mem for their queries
> 2. You could specify allowed types in custom settings.
> 3. In a subsequent stage you might be able to SELECT .... INTO
> setting_name FROM ....; allowing access to setting writes based on queries.
>
>
The creating database objects and necessary infrastructure is the most
simple task of this project. I'll be more happy if there are zero
intersection because variables and GUC are designed for different purposes.
But due SET keyword the intersection there is.

When I thinking about it, I have only one, but important reason, why I
prefer design new type of database object -the GUC are stack based with
different default granularity - global, database, user, session, function.
This can be unwanted behave for variables - it can be source of hard to
detected bugs. I afraid so this behave can be too messy for usage as
variables.

@1 I have not clean opinion about it - not sure if rights are good enough -
probably some user limits can be more practical - but can be hard to choose
result when some user limits and GUC will be against
@2 With variables typed custom GUC are not necessary
@3 Why you need it? It is possible with set_config function now.

Regards

Pavel

>
>
>> regards
>>
>> Pavel
>>
>>
>>
>
>
> --
> Best Regards,
> Chris Travers
> Database Administrator
>
> Tel: +49 162 9037 210 <+49%20162%209037210> | Skype: einhverfr |
> www.adjust.com
> Saarbrücker Straße 37a, 10405 Berlin
> <https://maps.google.com/?q=Saarbr%C3%BCcker+Stra%C3%9Fe+37a,+10405+Berlin&entry=gmail&source=g>
>
>


From: Chris Travers <chris(dot)travers(at)adjust(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-29 08:51:55
Message-ID: CAN-RpxA3rnL3z5c=HOnJ+7QNNYh0z1WhggEpo6PLdeXKDaA6+g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sat, Oct 28, 2017 at 4:56 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

>
>>
> The creating database objects and necessary infrastructure is the most
> simple task of this project. I'll be more happy if there are zero
> intersection because variables and GUC are designed for different purposes.
> But due SET keyword the intersection there is.
>
> When I thinking about it, I have only one, but important reason, why I
> prefer design new type of database object -the GUC are stack based with
> different default granularity - global, database, user, session, function.
> This can be unwanted behave for variables - it can be source of hard to
> detected bugs. I afraid so this behave can be too messy for usage as
> variables.
>
> @1 I have not clean opinion about it - not sure if rights are good enough
> - probably some user limits can be more practical - but can be hard to
> choose result when some user limits and GUC will be against
>

I was mostly thinking that users can probably set things like work_mem and
possibly this might be a problem.

> @2 With variables typed custom GUC are not necessary
>

I don't know about that. For example with the geoip2lookup extension it is
nice that you could set the preferred language for translation on a per
user basis or the mmdb path on a per-db basis.

> @3 Why you need it? It is possible with set_config function now.
>

Yeah you could do it safely with set_config and a CTE, but suppose I have:

with a (Id, value) as (values (1::Int, 'foo'), (2, 'bar'), (3, 'baz'))
SELECT set_config('custom_val', value) from a where id = 2;

What is the result out of this? I would *expect* that this would probably
run set_config 3 times and filter the output.

>
> Regards
>
> Pavel
>
>
>
>
>>
>>
>>> regards
>>>
>>> Pavel
>>>
>>>
>>>
>>
>>
>> --
>> Best Regards,
>> Chris Travers
>> Database Administrator
>>
>> Tel: +49 162 9037 210 <+49%20162%209037210> | Skype: einhverfr |
>> www.adjust.com
>> Saarbrücker Straße 37a, 10405 Berlin
>> <https://maps.google.com/?q=Saarbr%C3%BCcker+Stra%C3%9Fe+37a,+10405+Berlin&entry=gmail&source=g>
>>
>>
>

--
Best Regards,
Chris Travers
Database Administrator

Tel: +49 162 9037 210 | Skype: einhverfr | www.adjust.com
Saarbrücker Straße 37a, 10405 Berlin


From: Hannu Krosing <hannu(dot)krosing(at)2ndquadrant(dot)com>
To: Chris Travers <chris(dot)travers(at)adjust(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-29 10:47:58
Message-ID: CAHDDfCnOQqSy5VzHHe0iiRrAdQYFq2GXzwY8GpLGMUQ5dYxYCw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

but you can always do

with a (id, value) as (
values (1, 'foo'), (2, 'bar'), (3, 'baz')
)
select set_config('custom.value',(select value from a where id = 2),true);

if you are worried about the evaluation order

On 29 October 2017 at 09:51, Chris Travers <chris(dot)travers(at)adjust(dot)com> wrote:

>
>
> On Sat, Oct 28, 2017 at 4:56 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>>
>>>
>> The creating database objects and necessary infrastructure is the most
>> simple task of this project. I'll be more happy if there are zero
>> intersection because variables and GUC are designed for different purposes.
>> But due SET keyword the intersection there is.
>>
>> When I thinking about it, I have only one, but important reason, why I
>> prefer design new type of database object -the GUC are stack based with
>> different default granularity - global, database, user, session, function.
>> This can be unwanted behave for variables - it can be source of hard to
>> detected bugs. I afraid so this behave can be too messy for usage as
>> variables.
>>
>> @1 I have not clean opinion about it - not sure if rights are good enough
>> - probably some user limits can be more practical - but can be hard to
>> choose result when some user limits and GUC will be against
>>
>
> I was mostly thinking that users can probably set things like work_mem and
> possibly this might be a problem.
>
>
>> @2 With variables typed custom GUC are not necessary
>>
>
> I don't know about that. For example with the geoip2lookup extension it
> is nice that you could set the preferred language for translation on a per
> user basis or the mmdb path on a per-db basis.
>
>
>> @3 Why you need it? It is possible with set_config function now.
>>
>
> Yeah you could do it safely with set_config and a CTE, but suppose I have:
>
> with a (Id, value) as (values (1::Int, 'foo'), (2, 'bar'), (3, 'baz'))
> SELECT set_config('custom_val', value) from a where id = 2;
>
> What is the result out of this? I would *expect* that this would probably
> run set_config 3 times and filter the output.
>
>
>>
>> Regards
>>
>> Pavel
>>
>>
>>
>>
>>>
>>>
>>>> regards
>>>>
>>>> Pavel
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Best Regards,
>>> Chris Travers
>>> Database Administrator
>>>
>>> Tel: +49 162 9037 210 <+49%20162%209037210> | Skype: einhverfr |
>>> www.adjust.com
>>> Saarbrücker Straße 37a, 10405 Berlin
>>> <https://maps.google.com/?q=Saarbr%C3%BCcker+Stra%C3%9Fe+37a,+10405+Berlin&entry=gmail&source=g>
>>>
>>>
>>
>
>
> --
> Best Regards,
> Chris Travers
> Database Administrator
>
> Tel: +49 162 9037 210 <+49%20162%209037210> | Skype: einhverfr |
> www.adjust.com
> Saarbrücker Straße 37a, 10405 Berlin
> <https://maps.google.com/?q=Saarbr%C3%BCcker+Stra%C3%9Fe+37a,+10405+Berlin&entry=gmail&source=g>
>
>


From: srielau <serge(at)rielau(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2017-10-30 21:42:40
Message-ID: 1509399760322-0.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Pavel,

I wouldn't put in the DROP option.
Or at least not in that form of syntax.

By convention CREATE persists DDL and makes object definitions visible
across sessions.
DECLARE defines session private objects which cannot collide with other
sessions.

If you want variables with a short lifetime that get dropped at the end of
the transaction that by definition would imply a session private object. So
it ought to be DECLARE'd.

As far as I can see PG has been following this practice so far.

Cheers
Serge Rielau
Salesforce.com

--
Sent from: http://www.postgresql-archive.org/PostgreSQL-hackers-f1928748.html


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: srielau <serge(at)rielau(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-31 20:33:35
Message-ID: CAFj8pRC3jq38zpNRJjQepkQKogfKC=0teb4OviZ7RwZ4je8ymQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2017-10-30 22:42 GMT+01:00 srielau <serge(at)rielau(dot)com>:

> Pavel,
>
> I wouldn't put in the DROP option.
> Or at least not in that form of syntax.
>
> By convention CREATE persists DDL and makes object definitions visible
> across sessions.
> DECLARE defines session private objects which cannot collide with other
> sessions.
>
> If you want variables with a short lifetime that get dropped at the end of
> the transaction that by definition would imply a session private object. So
> it ought to be DECLARE'd.
>
> As far as I can see PG has been following this practice so far.
>

I am thinking so there is little bit overlap between DECLARE and CREATE
TEMP VARIABLE command. With DECLARE command, you are usually has not any
control when variable will be destroyed. For CREATE TEMP xxxx is DROP IF
EXISTS, but it should not be used.

It should be very similar to our current temporary tables, that are created
in session related temp schema.

I can imagine, so DECLARE command will be introduced as short cut for
CREATE TEMP VARIABLE, but in this moment I would not to open this topic. I
afraid of bikeshedding and I hope so CREATE TEMP VAR is anough.

Regards

Pavel

> Cheers
> Serge Rielau
> Salesforce.com
>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-hackers-
> f1928748.html
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Serge Rielau <serge(at)rielau(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-31 21:08:18
Message-ID: 5665be80-1772-4998-8dbc-3bd071c0d9ad@rielau.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Pavel, I can imagine, so DECLARE command will be introduced as short cut
for CREATE TEMP VARIABLE, but in this moment I would not to open this
topic. I afraid of bikeshedding and I hope so CREATE TEMP VAR is anough.
Language is important because language stays. You choice of syntax will
outlive your code and possibly yourself.
My 2 cents Serge


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Serge Rielau <serge(at)rielau(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-10-31 21:10:43
Message-ID: CAFj8pRB9YEzD_-qno8Y2Xj08f4gu2LYJFBd1QDW82EKPW-vmsQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-10-31 22:08 GMT+01:00 Serge Rielau <serge(at)rielau(dot)com>:

> Pavel,
>
> I can imagine, so DECLARE command will be introduced as short cut for
> CREATE TEMP VARIABLE, but in this moment I would not to open this topic. I
> afraid of bikeshedding and I hope so CREATE TEMP VAR is anough.
>
> Language is important because language stays.
> You choice of syntax will outlive your code and possibly yourself.
>

sure. But in this moment I don't see difference between DECLARE VARIABLE
and CREATE TEMP VARIABLE different than "TEMP" keyword.

Regards

Pavel

> My 2 cents
> Serge
>


From: srielau <serge(at)rielau(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2017-10-31 21:28:37
Message-ID: 1509485317393-0.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Pavel,

There is no
DECLARE TEMP CURSOR
or
DECLARE TEMP variable in PLpgSQL
and
CREATE TEMP TABLE has a different meaning from what I understand you
envision for variables.

But maybe I'm mistaken. Your original post did not describe the entire
syntax:
CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
[ DEFAULT expression ] [[NOT] NULL]
[ ON TRANSACTION END { RESET | DROP } ]
[ { VOLATILE | STABLE } ];

Especially the TEMP is not spelled out and how its presence affects or
doesn't ON TRANSACTION END.
So may be if you elaborate I understand where you are coming from.

--
Sent from: http://www.postgresql-archive.org/PostgreSQL-hackers-f1928748.html


From: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2017-10-31 22:36:53
Message-ID: 9f1f9d20-e913-82fb-c654-ae8c07537fee@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Le 31/10/2017 à 22:28, srielau a écrit :
> Pavel,
>
> There is no
> DECLARE TEMP CURSOR
> or
> DECLARE TEMP variable in PLpgSQL
> and
> CREATE TEMP TABLE has a different meaning from what I understand you
> envision for variables.
>
> But maybe I'm mistaken. Your original post did not describe the entire
> syntax:
> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
> [ DEFAULT expression ] [[NOT] NULL]
> [ ON TRANSACTION END { RESET | DROP } ]
> [ { VOLATILE | STABLE } ];
>
> Especially the TEMP is not spelled out and how its presence affects or
> doesn't ON TRANSACTION END.
> So may be if you elaborate I understand where you are coming from.

I think that the TEMP keyword can be removed. If I understand well the
default scope for variable is the session, every transaction in a
session will see the same value. For the transaction level, probably the
reason of the TEMP keyword, I think the [ ON TRANSACTION END { RESET |
DROP } ] will allow to restrict the scope to this transaction level
without needing the TEMP keyword. When a variable is created in a
transaction, it is temporary if "ON TRANSACTION END DROP" is used
otherwise it will persist after the transaction end. I guess that this
is the same as using TEMP keyword?

--
Gilles Darold
Consultant PostgreSQL
http://dalibo.com - http://dalibo.org


From: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2017-10-31 23:02:26
Message-ID: c48dc141-776e-2284-15fa-3863f7b6a1b4@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Le 31/10/2017 à 23:36, Gilles Darold a écrit :
> Le 31/10/2017 à 22:28, srielau a écrit :
>> Pavel,
>>
>> There is no
>> DECLARE TEMP CURSOR
>> or
>> DECLARE TEMP variable in PLpgSQL
>> and
>> CREATE TEMP TABLE has a different meaning from what I understand you
>> envision for variables.
>>
>> But maybe I'm mistaken. Your original post did not describe the entire
>> syntax:
>> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
>> [ DEFAULT expression ] [[NOT] NULL]
>> [ ON TRANSACTION END { RESET | DROP } ]
>> [ { VOLATILE | STABLE } ];
>>
>> Especially the TEMP is not spelled out and how its presence affects or
>> doesn't ON TRANSACTION END.
>> So may be if you elaborate I understand where you are coming from.
> I think that the TEMP keyword can be removed. If I understand well the
> default scope for variable is the session, every transaction in a
> session will see the same value. For the transaction level, probably the
> reason of the TEMP keyword, I think the [ ON TRANSACTION END { RESET |
> DROP } ] will allow to restrict the scope to this transaction level
> without needing the TEMP keyword. When a variable is created in a
> transaction, it is temporary if "ON TRANSACTION END DROP" is used
> otherwise it will persist after the transaction end. I guess that this
> is the same as using TEMP keyword?

I forgot to say that in the last case the DECLARE statement can be used
so I don't see the reason of this kind of "temporary" variables.

Maybe the variable object like used in DB2 and defined in document :
https://www.ibm.com/support/knowledgecenter/en/SSEPEK_11.0.0/sqlref/src/tpc/db2z_sql_createvariable.html
could be enough to cover our needs.

--
Gilles Darold
Consultant PostgreSQL
http://dalibo.com - http://dalibo.org


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: srielau <serge(at)rielau(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-01 04:15:58
Message-ID: CAFj8pRAnkj68ORyU7d3CtUER4-=c3oD0eU8=OLjA2UFv3orx2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-10-31 22:28 GMT+01:00 srielau <serge(at)rielau(dot)com>:

> Pavel,
>
> There is no
> DECLARE TEMP CURSOR
> or
> DECLARE TEMP variable in PLpgSQL
> and
>

sure .. DECLARE TEMP has no sense, I talked about similarity DECLARE and
CREATE TEMP

CREATE TEMP TABLE has a different meaning from what I understand you
> envision for variables.
>
> But maybe I'm mistaken. Your original post did not describe the entire
> syntax:
> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
> [ DEFAULT expression ] [[NOT] NULL]
> [ ON TRANSACTION END { RESET | DROP } ]
> [ { VOLATILE | STABLE } ];
>
> Especially the TEMP is not spelled out and how its presence affects or
> doesn't ON TRANSACTION END.
> So may be if you elaborate I understand where you are coming from.
>

TEMP has same functionality (and implementation) like our temp tables - so
at session end the temp variables are destroyed, but it can be assigned to
transaction.

>
>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-hackers-
> f1928748.html
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Serge Rielau <serge(at)rielau(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-01 05:07:59
Message-ID: baaf22da-867a-4b7d-a2fb-7fa9b510c150@rielau.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

" Although the syntax of CREATE TEMPORARY TABLE resembles that of the SQL standard, the effect is not the same. In the standard, temporary tables are defined just once and automatically exist (starting with empty contents) in every session that needs them. PostgreSQL instead requires each session to issue its own CREATE TEMPORARY TABLE command for each temporary table to be used. This allows different sessions to use the same temporary table name for different purposes, whereas the standard's approach constrains all instances of a given temporary table name to have the same table structure.”
Yeah, that’s a DECLAREd table in my book. No wonder we didn’t link up.
Cheers Serge


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Serge Rielau <serge(at)rielau(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-01 05:56:03
Message-ID: CAFj8pRCH1OCuSpjOkt3UhW9h3QwG0pikp+kge7Nx+JJ=Z_bPrg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-11-01 6:07 GMT+01:00 Serge Rielau <serge(at)rielau(dot)com>:

> "Although the syntax of CREATE TEMPORARY TABLE resembles that of the SQL
> standard, the effect is not the same. In the standard, temporary tables are
> defined just once and automatically exist (starting with empty contents) in
> every session that needs them. PostgreSQL instead requires each session
> to issue its own CREATE TEMPORARY TABLE command for each temporary table
> to be used. This allows different sessions to use the same temporary table
> name for different purposes, whereas the standard's approach constrains all
> instances of a given temporary table name to have the same table structure.”
> Yeah, that’s a DECLAREd table in my book. No wonder we didn’t link up.
>

This is known discussion about local / global temp tables in PostgresSQL.
And ToDo point: implementation of global temp tables in Postgres.

This temporary behave is marginal part of proposal - so I can to remove it
from proposal - and later open discussion about CREATE TEMPORARY VARIABLE
versus DECLARE VARIABLE

Regards

Pavel

Serge

>


From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-01 18:03:28
Message-ID: 58C95E69-F94E-46E0-98B5-8F52454B4403@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


> Comments, notes?

How would variables behave on transaction rollback?

CREATE TEMP VARIABLE myvar;
SET myvar := 1;
BEGIN;
SET myvar := 2;
COMMIT;
BEGIN;
SET myvar := 3;
ROLLBACK;
SELECT myvar;

How would variables behave when modified in a procedure
that aborts rather than returning cleanly?

mark


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Mark Dilger <hornschnorter(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-01 19:19:48
Message-ID: CAFj8pRC3Eq1xGZ9F7LsqXnyh_851EL7ReoZfE0BxJm4GFVMk7w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-11-01 19:03 GMT+01:00 Mark Dilger <hornschnorter(at)gmail(dot)com>:

>
> > Comments, notes?
>
> How would variables behave on transaction rollback?
>
> CREATE TEMP VARIABLE myvar;
> SET myvar := 1;
> BEGIN;
> SET myvar := 2;
> COMMIT;
> BEGIN;
> SET myvar := 3;
> ROLLBACK;
> SELECT myvar;
>
> How would variables behave when modified in a procedure
> that aborts rather than returning cleanly?
>
>
The result is 3

When you create variable like you did, then there are not any relation
between variable content and transactions. Almost every where session -
package - schema variables are untransactional. It can be changed, but with
negative impact on performance - so I propose relative simply solution -
reset to default on rollback, when variables was changed in transaction -
but it is not default behave.

Variables are variables like you know from PlpgSQL. But the holder is not
the plpgsql function. The holder is a schema in this case. The variable
(meta) is permanent. The content of variable is session based
untransactional.

Regards

Pavel

> mark
>


From: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-01 22:13:47
Message-ID: f6bd1e6f-80a6-2bb8-dd7e-8a692ce21cdf@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Le 01/11/2017 à 05:15, Pavel Stehule a écrit :
>
>
> 2017-10-31 22:28 GMT+01:00 srielau <serge(at)rielau(dot)com
> <mailto:serge(at)rielau(dot)com>>:
>
> Pavel,
>
> There is no
> DECLARE TEMP CURSOR
> or
> DECLARE TEMP variable in PLpgSQL
> and
>
>
> sure .. DECLARE TEMP has no sense, I talked about similarity DECLARE
> and CREATE TEMP
>
>
> CREATE TEMP TABLE has a different meaning from what I understand you
> envision for variables.
>
> But maybe I'm mistaken. Your original post did not describe the entire
> syntax:
> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
>   [ DEFAULT expression ] [[NOT] NULL]
>   [ ON TRANSACTION END { RESET | DROP } ]
>   [ { VOLATILE | STABLE } ];
>
> Especially the TEMP is not spelled out and how its presence affects or
> doesn't ON TRANSACTION END.
> So may be if you elaborate I understand where you are coming from.
>
>
> TEMP has same functionality (and implementation) like our temp tables
> - so at session end the temp variables are destroyed, but it can be
> assigned to transaction.

Oh ok, I understand thanks for the precision.

--
Gilles Darold
Consultant PostgreSQL
http://dalibo.com - http://dalibo.org


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 12:35:54
Message-ID: CA+TgmoaZ0iymUS_ZM6LW2yWjabwQs4K8=4GYR1+u-V7ROPz0nA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Oct 26, 2017 at 12:51 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> The variables can be modified by SQL command SET (this is taken from
> standard, and it natural)
>
> SET varname = expression;

Overloading SET to handle both variables and GUCs seems likely to
create problems, possibly including security problems. For example,
maybe a security-definer function could leave behind variables to
trick the calling code into failing to set GUCs that it intended to
set. Or maybe creating a variable at the wrong time will just break
things randomly.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


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: proposal: schema variables
Date: 2017-11-02 15:07:55
Message-ID: CAMsr+YF86Gcd3bTXbga7S2HXsVRAy_qkq1NQm1usmdxi4pbu1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 26 October 2017 at 15:21, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hi,
>
> I propose a new database object - a variable.

Didn't we have a pretty long discussion about this already in

Yeah.

https://www.postgresql.org/message-id/flat/CAMsr%2BYF0G8_FehQyFS8gSfnEer9OPsMOvpfniDJOVGQzJzHzsw%40mail(dot)gmail(dot)com#CAMsr+YF0G8_FehQyFS8gSfnEer9OPsMOvpfniDJOVGQzJzHzsw(at)mail(dot)gmail(dot)com

It'd be nice if you summarised any outcomes from that and addressed
it, rather than taking this as a new topic.

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


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 15:35:07
Message-ID: 20171102153505.GP4496@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Nov 02, 2017 at 06:05:54PM +0530, Robert Haas wrote:
> On Thu, Oct 26, 2017 at 12:51 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> > The variables can be modified by SQL command SET (this is taken from
> > standard, and it natural)
> >
> > SET varname = expression;
>
> Overloading SET to handle both variables and GUCs seems likely to
> create problems, possibly including security problems. For example,
> maybe a security-definer function could leave behind variables to
> trick the calling code into failing to set GUCs that it intended to
> set. Or maybe creating a variable at the wrong time will just break
> things randomly.

That's already true of GUCs, since there are no access controls on
set_config()/current_setting().

Presumably "schema variables" would really just be GUC-like and not at
all like lexically scoped variables. And also subject to access
controls, thus an overall improvement on set_config()/current_setting().

With access controls, GUCs could become schema variables, and settings
from postgresql.conf could move into the database itself (which I think
would be nice).

Nico
--


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Nico Williams <nico(at)cryptonector(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 15:40:36
Message-ID: CAFj8pRCzLyni0JBMvjqNA7ey1c-0EEJKSAJJ8rHmSwxfFP1rBA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-11-02 16:35 GMT+01:00 Nico Williams <nico(at)cryptonector(dot)com>:

> On Thu, Nov 02, 2017 at 06:05:54PM +0530, Robert Haas wrote:
> > On Thu, Oct 26, 2017 at 12:51 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> > > The variables can be modified by SQL command SET (this is taken from
> > > standard, and it natural)
> > >
> > > SET varname = expression;
> >
> > Overloading SET to handle both variables and GUCs seems likely to
> > create problems, possibly including security problems. For example,
> > maybe a security-definer function could leave behind variables to
> > trick the calling code into failing to set GUCs that it intended to
> > set. Or maybe creating a variable at the wrong time will just break
> > things randomly.
>
> That's already true of GUCs, since there are no access controls on
> set_config()/current_setting().
>
> Presumably "schema variables" would really just be GUC-like and not at
> all like lexically scoped variables. And also subject to access
> controls, thus an overall improvement on set_config()/current_setting().
>
> With access controls, GUCs could become schema variables, and settings
> from postgresql.conf could move into the database itself (which I think
> would be nice).
>

I am sorry, but I don't plan it. the behave of GUC is too different than
behave of variables. But I am planning so system GUC can be "moved" to
pg_catalog to be possibility to specify any object exactly.

Regards

Pavel

>
> Nico
> --
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 15:42:20
Message-ID: CAFj8pRBf3T4NCmcWLTFShFW2aeSMFw8LCXRbDKyz4HdPpmtT3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-11-02 16:07 GMT+01:00 Craig Ringer <craig(at)2ndquadrant(dot)com>:

> On 26 October 2017 at 15:21, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> > Hi,
> >
> > I propose a new database object - a variable.
>
> Didn't we have a pretty long discussion about this already in
>
> Yeah.
>
> https://www.postgresql.org/message-id/flat/CAMsr%2BYF0G8_
> FehQyFS8gSfnEer9OPsMOvpfniDJOVGQzJzHzsw%40mail.gmail.com#CAMsr+YF0G8_
> FehQyFS8gSfnEer9OPsMOvpfniDJOVGQzJzHzsw(at)mail(dot)gmail(dot)com
>
> It'd be nice if you summarised any outcomes from that and addressed
> it, rather than taking this as a new topic.
>

I am sorry. This thread follow mentioned and I started with small
recapitulation.

Regards

Pavel

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nico Williams <nico(at)cryptonector(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 15:48:44
Message-ID: 28927.1509637724@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Nico Williams <nico(at)cryptonector(dot)com> writes:
> With access controls, GUCs could become schema variables, and settings
> from postgresql.conf could move into the database itself (which I think
> would be nice).

People re-propose some variant of that every so often, but it never works,
because it ignores the fact that some of the GUCs' values are needed
before you can access system catalogs at all, or in places where relying
on system catalog access would be a bad idea.

Sure, we could have two completely different configuration mechanisms
so that some of the variables could be "inside the database", but that
doesn't seem like a net improvement to me. The point of the Grand Unified
Configuration mechanism was to be unified, after all.

I'm on board with having a totally different mechanism for session
variables. The fact that people have been abusing GUC to store
user-defined variables doesn't make it a good way to do that.

regards, tom lane


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 15:49:20
Message-ID: CAFj8pRCwTf6kqk8Z+5x8y6F=-S1gP2JTchKnjf2ixf2AMMpahw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2017-11-02 13:35 GMT+01:00 Robert Haas <robertmhaas(at)gmail(dot)com>:

> On Thu, Oct 26, 2017 at 12:51 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> > The variables can be modified by SQL command SET (this is taken from
> > standard, and it natural)
> >
> > SET varname = expression;
>
> Overloading SET to handle both variables and GUCs seems likely to
> create problems, possibly including security problems. For example,
> maybe a security-definer function could leave behind variables to
> trick the calling code into failing to set GUCs that it intended to
> set. Or maybe creating a variable at the wrong time will just break
> things randomly.
>

The syntax CREATE OR REPLACE FUNCTION xxx $$ ... $$ SET GUC=, ... is always
related only to GUC. So there should not be any security risk.

It is another reason why GUC and variables should be separated.

I know so there is risk of possibility of collision. There are two
possibilities

a) use different keyword - but it is out of SQL/PSM and out of another
databases.

b) detect possible collision and raise error when assignment is ambiguous.
I am thinking about similar solution used in plpgsql, where is a
possibility of collision between SQL identifier and plpgsql variable.

Regards

Pavel

>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Nico Williams <nico(at)cryptonector(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 17:21:54
Message-ID: CA+TgmoYXZMFp9KuVbkOYeTcSb1wqJifFKSnaamBbzfs3sRvi1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Nov 2, 2017 at 9:05 PM, Nico Williams <nico(at)cryptonector(dot)com> wrote:
>> Overloading SET to handle both variables and GUCs seems likely to
>> create problems, possibly including security problems. For example,
>> maybe a security-definer function could leave behind variables to
>> trick the calling code into failing to set GUCs that it intended to
>> set. Or maybe creating a variable at the wrong time will just break
>> things randomly.
>
> That's already true of GUCs, since there are no access controls on
> set_config()/current_setting().

No, it isn't. Right now, SET always refers to a GUC, never a
variable, so there's no possibility of getting confused about whether
it's intending to change a GUC or an eponymous variable. Once you
make SET able to change either one of two different kinds of objects,
then that possibility does exist.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-02 18:52:39
Message-ID: 20171102185237.GQ4496@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Nov 02, 2017 at 11:48:44AM -0400, Tom Lane wrote:
> Nico Williams <nico(at)cryptonector(dot)com> writes:
> > With access controls, GUCs could become schema variables, and settings
> > from postgresql.conf could move into the database itself (which I think
> > would be nice).
>
> People re-propose some variant of that every so often, but it never works,
> because it ignores the fact that some of the GUCs' values are needed
> before you can access system catalogs at all, or in places where relying
> on system catalog access would be a bad idea.

ISTM that it should be possible to break the chicken-egg issue by having
the config variables stored in such a way that knowing only the pgdata
directory path should suffice to find them. That's effectively the case
already in that postgresql.conf is found... there.

One could do probably this as a PoC entirely as a SQL-coded VIEW that
reads and writes (via the adminpack module's pg_catalog.pg_file_write())
postgresql.conf (without preserving comments, or with some rules
regarding comments so that they are effectively attached to params).

Nico
--


From: Chris Travers <chris(dot)travers(at)adjust(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Nico Williams <nico(at)cryptonector(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-03 12:58:02
Message-ID: CAN-RpxCAHPujQPA9cRrqOABEX2g5Y1p3hasGMp=EE8hagw7cjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Some thoughts on this.

On Thu, Nov 2, 2017 at 4:48 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Nico Williams <nico(at)cryptonector(dot)com> writes:
> > With access controls, GUCs could become schema variables, and settings
> > from postgresql.conf could move into the database itself (which I think
> > would be nice).
>
> People re-propose some variant of that every so often, but it never works,
> because it ignores the fact that some of the GUCs' values are needed
> before you can access system catalogs at all, or in places where relying
> on system catalog access would be a bad idea.
>

I think the basic point one should get here is that no matter the
unification, you still have some things in the db and some things out.

I would rather look at how the GUC could be improved on a functional/use
case level before we look at the question of a technical solution.

One major use case today would be restricting how high various users can
set something like work_mem or the like. As it stands, there isn't really
a way to control this with any granularity. So some of the proposals
regarding granting access to a session variable would be very handy in
granting access to a GUC variable.

>
> Sure, we could have two completely different configuration mechanisms
> so that some of the variables could be "inside the database", but that
> doesn't seem like a net improvement to me. The point of the Grand Unified
> Configuration mechanism was to be unified, after all.
>

+1

>
> I'm on board with having a totally different mechanism for session
> variables. The fact that people have been abusing GUC to store
> user-defined variables doesn't make it a good way to do that.
>

What about having a more clunky syntax as:

SET VARIABLE foo='bar';

Perhaps one can have a short form of:

SET VAR foo = 'bar';

vs

SET foo = 'bar'; -- GUC

>
> regards, tom lane
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

--
Best Regards,
Chris Travers
Database Administrator

Tel: +49 162 9037 210 | Skype: einhverfr | www.adjust.com
Saarbrücker Straße 37a, 10405 Berlin


From: Pavel Golub <pavel(at)microolap(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-13 12:15:00
Message-ID: 623395617.20171113141500@gf.microolap.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hello, Pavel.

You wrote:

PS> Hi,

PS> I propose a  new database object - a variable. The variable is
PS> persistent object, that holds unshared session based not
PS> transactional in memory value of any type. Like variables in any
PS> other languages. The persistence is required for possibility to do
PS> static checks, but can be limited to session - the variables can be temporal.

Great idea.

PS> My proposal is related to session variables from Sybase, MSSQL or
PS> MySQL (based on prefix usage @ or @@), or package variables from
PS> Oracle (access is controlled by scope), or schema variables from
PS> DB2. Any design is coming from different sources, traditions and
PS> has some advantages or disadvantages. The base of my proposal is
PS> usage schema variables as session variables for stored procedures.
PS> It should to help to people who try to port complex projects to PostgreSQL from other databases.

PS> The Sybase  (T-SQL) design is good for interactive work, but it
PS> is weak for usage in stored procedures - the static check is not
PS> possible. Is not possible to set some access rights on variables.

PS> The ADA design (used on Oracle) based on scope is great, but our
PS> environment is not nested. And we should to support other PL than PLpgSQL more strongly.

PS> There is not too much other possibilities - the variable that
PS> should be accessed from different PL, different procedures (in
PS> time) should to live somewhere over PL, and there is the schema only.

PS> The variable can be created by CREATE statement:

PS> CREATE VARIABLE public.myvar AS integer;
PS> CREATE VARIABLE myschema.myvar AS mytype;

PS> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
PS>   [ DEFAULT expression ] [[NOT] NULL]
PS>   [ ON TRANSACTION END { RESET | DROP } ]
PS>   [ { VOLATILE | STABLE } ];

PS> It is dropped by command DROP VARIABLE  [ IF EXISTS] varname.

PS> The access rights is controlled by usual access rights - by
PS> commands GRANT/REVOKE. The possible rights are: READ, WRITE

PS> The variables can be modified by SQL command SET (this is taken from standard, and it natural)

PS> SET varname = expression;

I propose LET keyword for this to distinguish GUC from variables, e.g.

LET varname = expression;

PS> Unfortunately we use the SET command for different purpose. But I
PS> am thinking so we can solve it with few tricks. The first is
PS> moving our GUC to pg_catalog schema. We can control the strictness
PS> of SET command. In one variant, we can detect custom GUC and allow
PS> it, in another we can disallow a custom GUC and allow only schema
PS> variables. A new command LET can be alternative.

PS> The variables should be used in queries implicitly (without JOIN)

PS> SELECT varname;

PS> The SEARCH_PATH is used, when varname is located. The variables
PS> can be used everywhere where query parameters are allowed.

PS> I hope so this proposal is good enough and simple.

PS> Comments, notes?

PS> regards

PS> Pavel

--
With best wishes,
Pavel mailto:pavel(at)gf(dot)microolap(dot)com


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2017-11-13 12:30:58
Message-ID: CAFj8pRDdS7ViLBJ6eA93u=C_x15EBv2deiNQDGkBS=LNrjzLLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2017-11-13 13:15 GMT+01:00 Pavel Golub <pavel(at)microolap(dot)com>:

> Hello, Pavel.
>
> You wrote:
>
> PS> Hi,
>
> PS> I propose a new database object - a variable. The variable is
> PS> persistent object, that holds unshared session based not
> PS> transactional in memory value of any type. Like variables in any
> PS> other languages. The persistence is required for possibility to do
> PS> static checks, but can be limited to session - the variables can be
> temporal.
>
> Great idea.
>
> PS> My proposal is related to session variables from Sybase, MSSQL or
> PS> MySQL (based on prefix usage @ or @@), or package variables from
> PS> Oracle (access is controlled by scope), or schema variables from
> PS> DB2. Any design is coming from different sources, traditions and
> PS> has some advantages or disadvantages. The base of my proposal is
> PS> usage schema variables as session variables for stored procedures.
> PS> It should to help to people who try to port complex projects to
> PostgreSQL from other databases.
>
> PS> The Sybase (T-SQL) design is good for interactive work, but it
> PS> is weak for usage in stored procedures - the static check is not
> PS> possible. Is not possible to set some access rights on variables.
>
> PS> The ADA design (used on Oracle) based on scope is great, but our
> PS> environment is not nested. And we should to support other PL than
> PLpgSQL more strongly.
>
> PS> There is not too much other possibilities - the variable that
> PS> should be accessed from different PL, different procedures (in
> PS> time) should to live somewhere over PL, and there is the schema only.
>
> PS> The variable can be created by CREATE statement:
>
> PS> CREATE VARIABLE public.myvar AS integer;
> PS> CREATE VARIABLE myschema.myvar AS mytype;
>
> PS> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
> PS> [ DEFAULT expression ] [[NOT] NULL]
> PS> [ ON TRANSACTION END { RESET | DROP } ]
> PS> [ { VOLATILE | STABLE } ];
>
>
> PS> It is dropped by command DROP VARIABLE [ IF EXISTS] varname.
>
> PS> The access rights is controlled by usual access rights - by
> PS> commands GRANT/REVOKE. The possible rights are: READ, WRITE
>
> PS> The variables can be modified by SQL command SET (this is taken from
> standard, and it natural)
>
> PS> SET varname = expression;
>
> I propose LET keyword for this to distinguish GUC from variables, e.g.
>
> LET varname = expression;
>

It is one possible variant. I plan to implement more variants and then
choose one.

Regards

Pavel

>
> PS> Unfortunately we use the SET command for different purpose. But I
> PS> am thinking so we can solve it with few tricks. The first is
> PS> moving our GUC to pg_catalog schema. We can control the strictness
> PS> of SET command. In one variant, we can detect custom GUC and allow
> PS> it, in another we can disallow a custom GUC and allow only schema
> PS> variables. A new command LET can be alternative.
>
>
>
> PS> The variables should be used in queries implicitly (without JOIN)
>
>
> PS> SELECT varname;
>
>
> PS> The SEARCH_PATH is used, when varname is located. The variables
> PS> can be used everywhere where query parameters are allowed.
>
>
>
> PS> I hope so this proposal is good enough and simple.
>
>
> PS> Comments, notes?
>
>
> PS> regards
>
>
> PS> Pavel
>
>
>
>
>
>
> --
> With best wishes,
> Pavel mailto:pavel(at)gf(dot)microolap(dot)com
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-02-02 22:06:44
Message-ID: CAFj8pRBfb-GTZSHSRVTpMzGr26-7e-_RmOmRpmuk+xuDTgC=mA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I wrote proof concept of schema variables. The patch is not nice, but the
functionality is almost complete (for scalars only) and can be good enough
for playing with this concept.

I recap a goals (the order is random):

1. feature like PL/SQL package variables (with similar content life cycle)
2. available from any PL used by PostgreSQL, data can be shared between
different PL
3. possibility to store short life data in fast secured storage
4. possibility to pass parameters and results to/from anonymous blocks
5. session variables with possibility to process static code check
6. multiple API available from different environments - SQL commands, SQL
functions, internal functions
7. data are stored in binary form

Example:

CREATE VARIABLE public.foo AS integer;

LET foo = 10 + 20;

DO $$
declare x int = random() * 1000;
BEGIN
RAISE NOTICE '%', foo;
LET foo = x + 100;
END;
$$;

SELECT public.foo + 10;
SELECT * FROM data WHERE col = foo;

All implemented features are described by regress tests

Interesting note - it is running without any modification of plpgsql code.

Regards

Pavel

Attachment Content-Type Size
schema-variables-poc.patch text/x-patch 118.1 KB

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-02-03 00:48:05
Message-ID: CAKFQuwa00-4HTujbnYNy_OdZ2OfjUO3AX4R91DbQ1wPBZegCfg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

​I've done a non-compilation documentation review, the diff from the poc
patch and the diff from master are attached.

Comments are inter-twined in the patch in xml comment format; though I
reiterate (some of?) them below.

On Fri, Feb 2, 2018 at 3:06 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

> Hi
>
> I wrote proof concept of schema variables. The patch is not nice, but the
> functionality is almost complete (for scalars only) and can be good enough
> for playing with this concept.
>
> I recap a goals (the order is random):
>
> 1. feature like PL/SQL package variables (with similar content life cycle)
> 2. available from any PL used by PostgreSQL, data can be shared between
> different PL
> 3. possibility to store short life data in fast secured storage
>

​The generic use of the word secure here bothers me. I'm taking it to be
"protected by grant/revoke"-based privileges; plus session-locality.

4. possibility to pass parameters and results to/from anonymous blocks
> 5. session variables with possibility to process static code check
>

What does "process static code check" means here?​

> 6. multiple API available from different environments - SQL commands, SQL
> functions, internal functions
>

I made the public aspect of this explicit in the CREATE VARIABLE doc
(though as noted below it probably belongs in section II)

> 7. data are stored in binary form
>

Thoughts during my review:

There is, for me, a cognitive dissonance between "schema variable" and
"variable value" - I'm partial to the later. Since we use "setting" for
GUCs the term variable here hopefully wouldn't cause ambiguity...

I've noticed that we don't seem to have or enforce any policy on how to
communicate "SQL standards compatibility" to the user...

We are missing the ability to alter ownership (or at least its
undocumented), and if that brings into existing ALTER VARIABLE we should
probably add ALTER TYPE TO new_type USING (cast) for completeness.

Its left for the reader to presume that because these are schema
"relations" that namespace resolution via search_path works the same as any
other relation.

I think I've answered my own question regarding DISCARD in that "variables"
discards values while if TEMP is in effect all temp variables are dropped.

Examples abound though it doesn't feel like too much: but saying "The usage
is very simple:" before giving the example in the function section seems to
be outside of our general style. A better preamble than "An example:"
would be nice but the example is so simple I could not think of anything
worth writing.

Its worth considering how both:

https://www.postgresql.org/docs/10/static/ddl.html
and
https://www.postgresql.org/docs/10/static/queries.html

could be updated to incorporate the broad picture of schema variables, with
examples, and leave the reference (SQL and functions) sections mainly
relegated to syntax and reminders.

A moderate number of lines changed are for typos and minor grammar edits.

David J.

Attachment Content-Type Size
schema-variables-poc--dgj-response-diff.patch application/octet-stream 11.5 KB
schema-variables-poc--dgj-response-full.patch application/octet-stream 120.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-02-03 06:58:33
Message-ID: CAFj8pRBchBfyPKAVPnJKhDjh7r6kTJ9L1=etMt-pjdDzpsKOUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2018-02-03 1:48 GMT+01:00 David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>:

> ​I've done a non-compilation documentation review, the diff from the poc
> patch and the diff from master are attached.
>
> Comments are inter-twined in the patch in xml comment format; though I
> reiterate (some of?) them below.
>
> On Fri, Feb 2, 2018 at 3:06 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>> Hi
>>
>> I wrote proof concept of schema variables. The patch is not nice, but the
>> functionality is almost complete (for scalars only) and can be good enough
>> for playing with this concept.
>>
>> I recap a goals (the order is random):
>>
>> 1. feature like PL/SQL package variables (with similar content life cycle)
>> 2. available from any PL used by PostgreSQL, data can be shared between
>> different PL
>> 3. possibility to store short life data in fast secured storage
>>
>
> ​The generic use of the word secure here bothers me. I'm taking it to be
> "protected by grant/revoke"-based privileges; plus session-locality.
>

I have not a problem with any other formulation.

>
> 4. possibility to pass parameters and results to/from anonymous blocks
>> 5. session variables with possibility to process static code check
>>
>
> What does "process static code check" means here?​
>

It mean the possibility to check validity of code without code execution.
You can use plpgsql_check for example.

>
>
>> 6. multiple API available from different environments - SQL commands, SQL
>> functions, internal functions
>>
>
> I made the public aspect of this explicit in the CREATE VARIABLE doc
> (though as noted below it probably belongs in section II)
> ​
>
>> 7. data are stored in binary form
>>
>
> Thoughts during my review:
>
> There is, for me, a cognitive dissonance between "schema variable" and
> "variable value" - I'm partial to the later. Since we use "setting" for
> GUCs the term variable here hopefully wouldn't cause ambiguity...
>

The "schema" is important in this case. 1) it is a analogy to "package
variable", 2) not necessary, but probably often it will be used together
with PLpgSQL. There are variables too. "Session variables" doesn't well
specify the implementation. The session variables can be GUC, psql client
variables or some custom implementation in Postgres or package variables in
Oracle.

> I've noticed that we don't seem to have or enforce any policy on how to
> communicate "SQL standards compatibility" to the user...
>
> We are missing the ability to alter ownership (or at least its
> undocumented), and if that brings into existing ALTER VARIABLE we should
> probably add ALTER TYPE TO new_type USING (cast) for completeness.
>

good note. I didn't test it. I am not sure, what variants of ALTER should
be supported. Type of variables is interface. Probably we can allow to add
new field, but change type or remove field can break other object. So it
can be prohibited like we doesn't support ALTER on views. ALTERing is
another and pretty complex topic, and I don't think it is necessary to
solve it now. This feature can be valuable without ALTER support, and
nothing block later ALTER VARIABLE implementation.

This design allows lot of interesting features (that can be implemented
step by step)

1. support for default expression
2. support for constraints and maybe triggers
3. reset on transaction end
4. initialization of session start - via default expression or triggers it
can be way how to start code on session start.

>
> Its left for the reader to presume that because these are schema
> "relations" that namespace resolution via search_path works the same as any
> other relation.
>
> I think I've answered my own question regarding DISCARD in that
> "variables" discards values while if TEMP is in effect all temp variables
> are dropped.
>

DISCARD should to remove TEMP variables and should to remove content of all
variables.

>
> Examples abound though it doesn't feel like too much: but saying "The
> usage is very simple:" before giving the example in the function section
> seems to be outside of our general style. A better preamble than "An
> example:" would be nice but the example is so simple I could not think of
> anything worth writing.
>

This doc is just design frame. I invite any enhancing because this feature
can be difficult for some people, because mix persistent object with
temporal/session content - and term "variable" can be used in relation
algebra in different semantic. It is natural for people with stored
procedures experience - mainly with Oracle, but for any other can be little
bit difficult. I believe so there should be more practical examples -
related to RLS for example.

>
> Its worth considering how both:
>
> https://www.postgresql.org/docs/10/static/ddl.html
> and
> https://www.postgresql.org/docs/10/static/queries.html
>
> could be updated to incorporate the broad picture of schema variables,
> with examples, and leave the reference (SQL and functions) sections mainly
> relegated to syntax and reminders.
>
> A moderate number of lines changed are for typos and minor grammar edits.
>

Thank you very much

Regards

Pavel

> David J.
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-02-07 06:34:44
Message-ID: CAFj8pRCTsxzsxX1cWgX3cjqsSZb=gqOMd3-2FdbGz5a2+shGMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

updated patch with your changes in documentation and pg_dump (initial)
support

Main issue of this patch is storage. We can reuse local buffers used for
temp tables. But it does allocation by 8KB and it creates temp files for
every object. That is too big overhead. Storing just in session memory is
too simple - then there should be lot of new code used, when variable will
be dropped.

I have ideas how to allow work with mix of scalar and composite types - so
it will be next step of this prototype.

Regards

Pavel

>

Attachment Content-Type Size
schema-variables-poc-180207-01-diff application/octet-stream 131.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-08 18:00:36
Message-ID: CAFj8pRA6YWwV=sZj5iSgDUixr-S+u9W2+v0BJqqxHQDXS2oZww@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2018-02-07 7:34 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

> Hi
>
> updated patch with your changes in documentation and pg_dump (initial)
> support
>
> Main issue of this patch is storage. We can reuse local buffers used for
> temp tables. But it does allocation by 8KB and it creates temp files for
> every object. That is too big overhead. Storing just in session memory is
> too simple - then there should be lot of new code used, when variable will
> be dropped.
>
> I have ideas how to allow work with mix of scalar and composite types - so
> it will be next step of this prototype.
>
> Regards
>
> Pavel
>

new update - rebased, + some initial support for composite values on right
side and custom types, arrays are supported too.

omega=# CREATE VARIABLE xx AS (a int, b numeric);
CREATE VARIABLE
omega=# LET xx = (10, 20)::xx;
LET
omega=# SELECT xx;
+---------+
| xx |
+---------+
| (10,20) |
+---------+
(1 row)

omega=# SELECT xx.a + xx.b;
+----------+
| ?column? |
+----------+
| 30 |
+----------+
(1 row)

omega=# \d xx
schema variable "public.xx"
+--------+---------+
| Column | Type |
+--------+---------+
| a | integer |
| b | numeric |
+--------+---------+

Regards

Pavel

Attachment Content-Type Size
schema-variables-poc-180308-01-diff application/octet-stream 164.0 KB

From: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-12 06:49:29
Message-ID: dde8f23f-a15f-e88b-482e-5c26cce14cca@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi,

I plan to make usability and feature test review in several days.

Is there any chances that it will work on replicas?
Such possibility is very helpful in generating reports.
Now, LET command produces an error:

ERROR:  cannot execute LET in a read-only transaction

But if we say that variables are non-transactional ?

-----
Pavel Luzanov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

On 08.03.2018 21:00, Pavel Stehule wrote:
> Hi
>
> 2018-02-07 7:34 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com
> <mailto:pavel(dot)stehule(at)gmail(dot)com>>:
>
> Hi
>
> updated patch with your changes in documentation and pg_dump
> (initial) support
>
> Main issue of this patch is storage. We can reuse local buffers
> used for temp tables. But it does allocation by 8KB and it creates
> temp files for every object. That is too big overhead. Storing
> just in session memory is too simple - then there should be lot of
> new code used, when variable will be dropped.
>
> I have ideas how to allow work with mix of scalar and composite
> types - so it will be next step of this prototype.
>
> Regards
>
> Pavel
>
>
> new update - rebased, + some initial support for composite values on
> right side and custom types, arrays are supported too.
>
> omega=# CREATE VARIABLE xx AS (a int, b numeric);
> CREATE VARIABLE
> omega=# LET xx = (10, 20)::xx;
> LET
> omega=# SELECT xx;
> +---------+
> |   xx    |
> +---------+
> | (10,20) |
> +---------+
> (1 row)
>
> omega=# SELECT xx.a + xx.b;
> +----------+
> | ?column? |
> +----------+
> |       30 |
> +----------+
> (1 row)
>
> omega=# \d xx
> schema variable "public.xx"
> +--------+---------+
> | Column |  Type   |
> +--------+---------+
> | a      | integer |
> | b      | numeric |
> +--------+---------+
>
>
> Regards
>
> Pavel
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-12 06:54:26
Message-ID: CAFj8pRDLBtPM9PAVx-VFtLyZJktKL5R4hX4V4O4KvcyjbOPRbw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-03-12 7:49 GMT+01:00 Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>:

> Hi,
>
> I plan to make usability and feature test review in several days.
>
> Is there any chances that it will work on replicas?
> Such possibility is very helpful in generating reports.
> Now, LET command produces an error:
>
> ERROR: cannot execute LET in a read-only transaction
>
>

> But if we say that variables are non-transactional ?
>

sure, it should to work. Now, I am try to solve a issues on concept level -
the LET code is based on DML code base, so probably there is check for rw
transactions. But it is useless for LET command.

Regards

Pavel

>
> -----
> Pavel Luzanov
> Postgres Professional: http://www.postgrespro.com
> The Russian Postgres Company
>
> On 08.03.2018 21:00, Pavel Stehule wrote:
>
> Hi
>
> 2018-02-07 7:34 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>
>> Hi
>>
>> updated patch with your changes in documentation and pg_dump (initial)
>> support
>>
>> Main issue of this patch is storage. We can reuse local buffers used for
>> temp tables. But it does allocation by 8KB and it creates temp files for
>> every object. That is too big overhead. Storing just in session memory is
>> too simple - then there should be lot of new code used, when variable will
>> be dropped.
>>
>> I have ideas how to allow work with mix of scalar and composite types -
>> so it will be next step of this prototype.
>>
>> Regards
>>
>> Pavel
>>
>
> new update - rebased, + some initial support for composite values on right
> side and custom types, arrays are supported too.
>
> omega=# CREATE VARIABLE xx AS (a int, b numeric);
> CREATE VARIABLE
> omega=# LET xx = (10, 20)::xx;
> LET
> omega=# SELECT xx;
> +---------+
> | xx |
> +---------+
> | (10,20) |
> +---------+
> (1 row)
>
> omega=# SELECT xx.a + xx.b;
> +----------+
> | ?column? |
> +----------+
> | 30 |
> +----------+
> (1 row)
>
> omega=# \d xx
> schema variable "public.xx"
> +--------+---------+
> | Column | Type |
> +--------+---------+
> | a | integer |
> | b | numeric |
> +--------+---------+
>
>
> Regards
>
> Pavel
>
>
>
>


From: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-12 15:38:39
Message-ID: ef39f19b-9d5c-78d1-6afa-adbe1288a20b@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


On 12.03.2018 09:54, Pavel Stehule wrote:
>
> 2018-03-12 7:49 GMT+01:00 Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru
> <mailto:p(dot)luzanov(at)postgrespro(dot)ru>>:
>
>
> Is there any chances that it will work on replicas?
>
> ...
>
> sure, it should to work. Now, I am try to solve a issues on concept
> level - the LET code is based on DML code base, so probably there is
> check for rw transactions. But it is useless for LET command.

Very, very good!

As I understand, the work on this patch now in progress and it not in
commitfest.
Please explain what features of schema variables I can review now.

From first post of this thread the syntax of the CREATE VARIABLE command:
CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
  [ DEFAULT expression ] [[NOT] NULL]
  [ ON TRANSACTION END { RESET | DROP } ]
  [ { VOLATILE | STABLE } ];

But in psql I see only:
\h create variable
Command:     CREATE VARIABLE
Description: define a new permissioned typed schema variable
Syntax:
CREATE VARIABLE [ IF NOT EXISTS ] name [ AS ] data_type ]

I can include DEFAULT clause in CREATE VARIABLE command, but the value
not used:
postgres=# create variable i int default 0;
CREATE VARIABLE
postgres=# select i;
 i
---

(1 row)

postgres=# \d+ i
 schema variable "public.i"
 Column |  Type   | Storage
--------+---------+---------
 i      | integer | plain

BTW, I found an error in handling of table aliases:

postgres=# create variable x text;
CREATE VARIABLE
postgres=# select * from pg_class AS x where x.relname = 'x';
ERROR:  type text is not composite

It thinks that x.relname is an attribute of x variable instead of an
alias for pg_class table.

-----
Pavel Luzanov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-12 16:13:40
Message-ID: CAFj8pRAY1KL-yA+ENCdOv+iJgVua773B_rq+Q=gkeUWg5yoLMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-03-12 16:38 GMT+01:00 Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>:

>
> On 12.03.2018 09:54, Pavel Stehule wrote:
>
>
> 2018-03-12 7:49 GMT+01:00 Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>:
>
>>
>> Is there any chances that it will work on replicas?
>>
> ...
>
> sure, it should to work. Now, I am try to solve a issues on concept level
> - the LET code is based on DML code base, so probably there is check for rw
> transactions. But it is useless for LET command.
>
>
> Very, very good!
>
> As I understand, the work on this patch now in progress and it not in
> commitfest.
> Please explain what features of schema variables I can review now.
>
> From first post of this thread the syntax of the CREATE VARIABLE command:
> CREATE [TEMP] VARIABLE [IF NOT EXISTS] name AS type
> [ DEFAULT expression ] [[NOT] NULL]
> [ ON TRANSACTION END { RESET | DROP } ]
> [ { VOLATILE | STABLE } ];
>

Now, it is too early for review - it is in development. Some features are
not implemented yet - DEFAULTs, ON TRANSACTION END .., others has not sense
(what I know now VOLATILE, STABLE). Schema variables are passed as
parameters to query, so the behave is like any other params - it is STABLE
only.

>
> But in psql I see only:
> \h create variable
> Command: CREATE VARIABLE
> Description: define a new permissioned typed schema variable
> Syntax:
> CREATE VARIABLE [ IF NOT EXISTS ] name [ AS ] data_type ]
>
> I can include DEFAULT clause in CREATE VARIABLE command, but the value not
> used:
> postgres=# create variable i int default 0;
> CREATE VARIABLE
> postgres=# select i;
> i
> ---
>
> (1 row)
>
> postgres=# \d+ i
> schema variable "public.i"
> Column | Type | Storage
> --------+---------+---------
> i | integer | plain
>
>
defaults are not implemented yet

>
> BTW, I found an error in handling of table aliases:
>
> postgres=# create variable x text;
> CREATE VARIABLE
> postgres=# select * from pg_class AS x where x.relname = 'x';
> ERROR: type text is not composite
>
> It thinks that x.relname is an attribute of x variable instead of an alias
> for pg_class table.
>
>
It is not well handled collision. This should be detected and prohibited.
In this case, because x is scalar, then x.xx has not sense, and then it
should not be handled like variable. So the current design is not too
practical - it generates more collisions than it is necessary and still,
there are some errors.

Now, there is one important question - storage - Postgres stores all
objects to files - only memory storage is not designed yet. This is part,
where I need a help.

Regards

Pavel

>
> -----
> Pavel Luzanov
> Postgres Professional: http://www.postgrespro.com
> The Russian Postgres Company
>
>


From: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2018-03-13 09:54:30
Message-ID: 1520934870491-0.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Pavel Stehule wrote
> Now, there is one important question - storage - Postgres stores all
> objects to files - only memory storage is not designed yet. This is part,
> where I need a help.

O, I do not feel confident in such questions.
May be some ideas you can get from extension with similar functionality:
https://github.com/postgrespro/pg_variables

-----
Pavel Luzanov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent from: http://www.postgresql-archive.org/PostgreSQL-hackers-f1928748.html


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2018-03-13 18:44:01
Message-ID: CAFj8pRBytUgvCUEh4LQT4iDF=9+uPCB-7irFVAS+wjV54_xUOw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-03-13 10:54 GMT+01:00 Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>:

> Pavel Stehule wrote
> > Now, there is one important question - storage - Postgres stores all
> > objects to files - only memory storage is not designed yet. This is part,
> > where I need a help.
>
> O, I do not feel confident in such questions.
> May be some ideas you can get from extension with similar functionality:
> https://github.com/postgrespro/pg_variables

Unfortunately not - it doesn't implement this functionality

Regards

Pavel

>
>
> -----
> Pavel Luzanov
> Postgres Professional: http://www.postgrespro.com
> The Russian Postgres Company
>
>
>
> --
> Sent from: http://www.postgresql-archive.org/PostgreSQL-hackers-
> f1928748.html
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-20 17:38:47
Message-ID: CAFj8pRAHK-6fPiyBGtTCjm4EOXc5ixgjL5ji5933cV3sS58nrQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I am sending new update. The code is less ugly, and the current
functionality is +/- final for first stage. It should be good enough for
playing and testing this concept.

What is supported:

1. scalar, composite and array variables
2. composite can be defined on place or some composite type can be used
3. variable, or any field of variable, can have defined default value
4. variable is database object - the access rights are required
5. the values are stored in binary form with defined typmod

An usage is very simple:

postgres=# create variable foo as numeric default 0;
CREATE VARIABLE
postgres=# select foo;
┌─────┐
│ foo │
╞═════╡
│ 0 │
└─────┘
(1 row)

postgres=# let foo = pi();
LET
postgres=# select foo;
┌──────────────────┐
│ foo │
╞══════════════════╡
│ 3.14159265358979 │
└──────────────────┘
(1 row)

postgres=# create variable boo as (x numeric default 0, y numeric default
0);
CREATE VARIABLE
postgres=# let boo.x = 100;
LET
postgres=# select boo;
┌─────────┐
│ boo │
╞═════════╡
│ (100,0) │
└─────────┘
(1 row)

postgres=# select boo.x;
┌─────┐
│ x │
╞═════╡
│ 100 │
└─────┘
(1 row)

Please try it.

Regards

Pavel

Attachment Content-Type Size
schema-variables-poc-180320-01-diff application/octet-stream 174.0 KB
schema_variables.out application/octet-stream 8.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-21 05:24:16
Message-ID: CAFj8pRBStff3KBB3m005D8+mQc=3tFATB+D_ND9g_mARdO=aXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-03-20 18:38 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

> Hi
>
> I am sending new update. The code is less ugly, and the current
> functionality is +/- final for first stage. It should be good enough for
> playing and testing this concept.
>
> What is supported:
>
> 1. scalar, composite and array variables
> 2. composite can be defined on place or some composite type can be used
> 3. variable, or any field of variable, can have defined default value
> 4. variable is database object - the access rights are required
> 5. the values are stored in binary form with defined typmod
>
> An usage is very simple:
>
> postgres=# create variable foo as numeric default 0;
> CREATE VARIABLE
> postgres=# select foo;
> ┌─────┐
> │ foo │
> ╞═════╡
> │ 0 │
> └─────┘
> (1 row)
>
> postgres=# let foo = pi();
> LET
> postgres=# select foo;
> ┌──────────────────┐
> │ foo │
> ╞══════════════════╡
> │ 3.14159265358979 │
> └──────────────────┘
> (1 row)
>
> postgres=# create variable boo as (x numeric default 0, y numeric default
> 0);
> CREATE VARIABLE
> postgres=# let boo.x = 100;
> LET
> postgres=# select boo;
> ┌─────────┐
> │ boo │
> ╞═════════╡
> │ (100,0) │
> └─────────┘
> (1 row)
>
> postgres=# select boo.x;
> ┌─────┐
> │ x │
> ╞═════╡
> │ 100 │
> └─────┘
> (1 row)
>
> Please try it.
>

small fix - support for SQL functions

>
> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-poc-180321-01-diff application/octet-stream 174.3 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Pavel Golub <pavel(at)gf(dot)microolap(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-03-23 05:37:58
Message-ID: CAFj8pRA6uCbR=rJvnSN1NVe9JAQZrOXzf2xXAKbvNtShG-=2iA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-03-21 6:24 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

>
>
> 2018-03-20 18:38 GMT+01:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>
>> Hi
>>
>> I am sending new update. The code is less ugly, and the current
>> functionality is +/- final for first stage. It should be good enough for
>> playing and testing this concept.
>>
>> What is supported:
>>
>> 1. scalar, composite and array variables
>> 2. composite can be defined on place or some composite type can be used
>> 3. variable, or any field of variable, can have defined default value
>> 4. variable is database object - the access rights are required
>> 5. the values are stored in binary form with defined typmod
>>
>> An usage is very simple:
>>
>> postgres=# create variable foo as numeric default 0;
>> CREATE VARIABLE
>> postgres=# select foo;
>> ┌─────┐
>> │ foo │
>> ╞═════╡
>> │ 0 │
>> └─────┘
>> (1 row)
>>
>> postgres=# let foo = pi();
>> LET
>> postgres=# select foo;
>> ┌──────────────────┐
>> │ foo │
>> ╞══════════════════╡
>> │ 3.14159265358979 │
>> └──────────────────┘
>> (1 row)
>>
>> postgres=# create variable boo as (x numeric default 0, y numeric default
>> 0);
>> CREATE VARIABLE
>> postgres=# let boo.x = 100;
>> LET
>> postgres=# select boo;
>> ┌─────────┐
>> │ boo │
>> ╞═════════╡
>> │ (100,0) │
>> └─────────┘
>> (1 row)
>>
>> postgres=# select boo.x;
>> ┌─────┐
>> │ x │
>> ╞═════╡
>> │ 100 │
>> └─────┘
>> (1 row)
>>
>> Please try it.
>>
>
> small fix - support for SQL functions
>
>

the patch is in commit fest list https://commitfest.postgresql.org/18/1608/

Regards

Pavel

>
>> Regards
>>
>> Pavel
>>
>
>


From: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-04-17 14:14:12
Message-ID: 20180417141410.GA7917@zakirov.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hello Pavel,

On Thu, Oct 26, 2017 at 09:21:24AM +0200, Pavel Stehule wrote:
> I hope so this proposal is good enough and simple.
>
> Comments, notes?

As I understood variables are stored in pg_class table. Did you consider
storing variables in a special catalog table? It can be named as
pg_variable.

pg_variable table requires more code of course, but it would fix the issues:
- pg_class has a lot attributes which are not related with variables,
and I think variables don't need many of them
- in a future variables might want to have some additional attributes
which are not needed for relations, you can easily add them to
pg_variable

What do you think?

--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-04-17 16:28:19
Message-ID: CAFj8pRD3RGW7zoHs2-4FgUKnV7TmHYbZiQYq1KS+KgwS3W30bQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2018-04-17 16:14 GMT+02:00 Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>:

> Hello Pavel,
>
> On Thu, Oct 26, 2017 at 09:21:24AM +0200, Pavel Stehule wrote:
> > I hope so this proposal is good enough and simple.
> >
> > Comments, notes?
>
> As I understood variables are stored in pg_class table. Did you consider
> storing variables in a special catalog table? It can be named as
> pg_variable.
>
> pg_variable table requires more code of course, but it would fix the
> issues:
> - pg_class has a lot attributes which are not related with variables,
> and I think variables don't need many of them
> - in a future variables might want to have some additional attributes
> which are not needed for relations, you can easily add them to
> pg_variable
>
> What do you think?
>

I though about it, and I am inclined to prefer pg_class instead separate
tables.

It true, so there are lot of "unused" attributes for this purpose, but
there is lot of shared attributes, and lot of shared code. Semantically, I
see variables in family of sequences, tables, indexes, views. Now, it
shares code, and I hope in next steps more code can be shared -
constraints, triggers.

There are two objective arguments for using pg_class:

1. unique name in schema - it reduces risk of collisions
2. sharing lot of code

So in this case I don't see well benefits of separate table.

Regards

Pavel

>
> --
> Arthur Zakirov
> Postgres Professional: http://www.postgrespro.com
> Russian Postgres Company
>


From: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-04-18 11:37:11
Message-ID: 20180418113710.GA8232@zakirov.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Tue, Apr 17, 2018 at 06:28:19PM +0200, Pavel Stehule wrote:
> I though about it, and I am inclined to prefer pg_class instead separate
> tables.
>
> It true, so there are lot of "unused" attributes for this purpose, but
> there is lot of shared attributes, and lot of shared code. Semantically, I
> see variables in family of sequences, tables, indexes, views. Now, it
> shares code, and I hope in next steps more code can be shared -
> constraints, triggers.
>
> There are two objective arguments for using pg_class:
>
> 1. unique name in schema - it reduces risk of collisions
> 2. sharing lot of code
>
> So in this case I don't see well benefits of separate table.

Understood. I haven't strong opinion here though. But I thought that
pg_class approach may limit extensibility of variables.

BTW:
- there is unitialized variable 'j' in pg_dump.c:15422
- in tab-complete.c:1268 initialization needs extra NULL before
&Query_for_list_of_variables

Also I think makeRangeVarForTargetOfSchemaVariable() has non friendly
argument names 'field1', 'field2', 'field2'.

--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-04-18 11:54:44
Message-ID: CAFj8pRBLTM6hetPRN1fKv-+MCYZKK9=Rk3n6xhKumt-vxE=E_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I am sending rebased patch

2018-04-18 13:37 GMT+02:00 Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>:

> On Tue, Apr 17, 2018 at 06:28:19PM +0200, Pavel Stehule wrote:
> > I though about it, and I am inclined to prefer pg_class instead separate
> > tables.
> >
> > It true, so there are lot of "unused" attributes for this purpose, but
> > there is lot of shared attributes, and lot of shared code. Semantically,
> I
> > see variables in family of sequences, tables, indexes, views. Now, it
> > shares code, and I hope in next steps more code can be shared -
> > constraints, triggers.
> >
> > There are two objective arguments for using pg_class:
> >
> > 1. unique name in schema - it reduces risk of collisions
> > 2. sharing lot of code
> >
> > So in this case I don't see well benefits of separate table.
>
> Understood. I haven't strong opinion here though. But I thought that
> pg_class approach may limit extensibility of variables.
>

I didn't touch limit (I don't know if there will be some issue - still is
far to upstream). This is technology, but workable, demo. I though so some
users had a problem to imagine what is persistent variable in my view.

But almost all code and tests can be used for final version - only storage
implementation is nothing more than workaround.

>
> BTW:
> - there is unitialized variable 'j' in pg_dump.c:15422
> - in tab-complete.c:1268 initialization needs extra NULL before
> &Query_for_list_of_variables
>

I found it too today when I did rebase. But thank you for report.

>
> Also I think makeRangeVarForTargetOfSchemaVariable() has non friendly
> argument names 'field1', 'field2', 'field2'.
>

yes, I hadn't better names :(

In this routine I am doing diagnostic what semantic has sense for current
values. the field1, field2 can be schema.variable or variable.field. So
when I used semantic names: schema, varname, fieldname, then it was more
messy (for me).

Regards

Pavel

>
> --
> Arthur Zakirov
> Postgres Professional: http://www.postgrespro.com
> Russian Postgres Company
>

Attachment Content-Type Size
schema-variables-poc-180418-01-diff application/octet-stream 174.1 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-04-20 15:32:07
Message-ID: CA+Tgmoaf44_UONp7zHgmkRwFNPbr7-7XnuZYu_JqSdZMrLi3cA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Tue, Apr 17, 2018 at 12:28 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> It true, so there are lot of "unused" attributes for this purpose, but there
> is lot of shared attributes, and lot of shared code. Semantically, I see
> variables in family of sequences, tables, indexes, views. Now, it shares
> code, and I hope in next steps more code can be shared - constraints,
> triggers.

I dunno, it seems awfully different to me. There's only one "column",
right? What code is really shared here? Are constraints and triggers
even desirable feature for variables? What would be the use case?

I think stuffing this into pg_class is pretty strange.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-04-20 17:45:06
Message-ID: CAFj8pRCptLktoDiCYK_rL2OgOGR-+B1QrNUGcK+Mkqi+KhWj+g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-04-20 17:32 GMT+02:00 Robert Haas <robertmhaas(at)gmail(dot)com>:

> On Tue, Apr 17, 2018 at 12:28 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> > It true, so there are lot of "unused" attributes for this purpose, but
> there
> > is lot of shared attributes, and lot of shared code. Semantically, I see
> > variables in family of sequences, tables, indexes, views. Now, it shares
> > code, and I hope in next steps more code can be shared - constraints,
> > triggers.
>
> I dunno, it seems awfully different to me. There's only one "column",
> right? What code is really shared here? Are constraints and triggers
> even desirable feature for variables? What would be the use case?
>

The schema variable can hold composite value. The patch allows to use any
composite type or adhoc composite values

DECLARE x AS compositetype;
DECLARE x AS (a int, b int, c int);

Constraints are clear, no.

Triggers are strange maybe, but why not - it can be used like enhanced
constraints, can be used for some value calculations, ..

> I think stuffing this into pg_class is pretty strange.
>

It will be if variable is just scalar value without any possibilities. But
then there is only low benefit

The access rights implementation is shared with other from pg_class too.

Regards

Pavel

>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-04-29 12:34:41
Message-ID: CAFj8pRBFwJRaPm2qnSLaKvNyi_tpck+qJr2PMad=h7JGuL9uaQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I am sending rebased patch to master

Regards

Pavel

Attachment Content-Type Size
schema-variables-poc-180429-01-diff application/octet-stream 174.1 KB

From: Fabrízio Mello <fabriziomello(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal: schema variables
Date: 2018-04-30 17:28:31
Message-ID: 152510931168.14385.1065744798869976489.pgcf@coridan.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: not tested
Spec compliant: not tested
Documentation: not tested

1) There are some errors applying the patch against the current master:

fabrizio(at)macanudo:/d/postgresql (master)
$ git apply /tmp/schema-variables-poc-180429-01-diff
/tmp/schema-variables-poc-180429-01-diff:2305: trailing whitespace.

/tmp/schema-variables-poc-180429-01-diff:2317: indent with spaces.
We can support UPDATE and SELECT commands on variables.
/tmp/schema-variables-poc-180429-01-diff:2319: indent with spaces.
possible syntaxes:
/tmp/schema-variables-poc-180429-01-diff:2321: indent with spaces.
-- there can be a analogy with record functions
/tmp/schema-variables-poc-180429-01-diff:2322: indent with spaces.
SELECT varname;
warning: squelched 14 whitespace errors
warning: 19 lines add whitespace errors.

2) There are some warnings when during build process

schemavar.c:383:18: warning: expression which evaluates to zero treated as a null pointer constant of type 'HeapTuple' (aka 'struct HeapTupleData *')
[-Wnon-literal-null-conversion]
HeapTuple tp = InvalidOid;
^~~~~~~~~~
../../../src/include/postgres_ext.h:36:21: note: expanded from macro 'InvalidOid'
#define InvalidOid ((Oid) 0)
^~~~~~~~~
1 warning generated.
tab-complete.c:1268:21: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
{"VARIABLE", NULL, &Query_for_list_of_variables},
^
tab-complete.c:1268:21: note: (near initialization for ‘words_after_create[48].vquery’)
llvmjit_expr.c: In function ‘llvm_compile_expr’:
llvmjit_expr.c:253:3: warning: enumeration value ‘EEOP_PARAM_SCHEMA_VARIABLE’ not handled in switch [-Wswitch]
switch (opcode)
^


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-05-01 01:56:45
Message-ID: 1f204fb8-afe6-006d-853b-4da05b416840@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 4/20/18 13:45, Pavel Stehule wrote:
> I dunno, it seems awfully different to me.  There's only one "column",
> right?  What code is really shared here?  Are constraints and triggers
> even desirable feature for variables?  What would be the use case?
>
>
> The schema variable can hold composite value. The patch allows to use
> any composite type or adhoc composite values
>
> DECLARE x AS compositetype;
> DECLARE x AS (a int, b int, c int);

I'm not sure that this anonymous composite type thing is such a good
idea. Such a variable will then be incompatible with anything else,
because it's of a different type.

In any case, I find that a weak argument for storing this in pg_class.
You could just as well create these pg_class entries implicitly and link
them from "pg_variable", same as composite types have a main entry in
pg_type and additional stuff in pg_class.

> I think stuffing this into pg_class is pretty strange.
>
> It will be if variable is just scalar value without any possibilities.
> But then there is only low benefit
>
> The access rights implementation is shared with other from pg_class too.

In DB2, the privileges for variables are named READ and WRITE. That
would make more sense to me than reusing the privilege names for tables.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-05-01 03:11:27
Message-ID: CAFj8pRB+ER3huHOZK_fMAdG=oSTx2U1Kq+MqUX4Y+jw2ZbaRFw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2018-05-01 3:56 GMT+02:00 Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com
>:

> On 4/20/18 13:45, Pavel Stehule wrote:
> > I dunno, it seems awfully different to me. There's only one
> "column",
> > right? What code is really shared here? Are constraints and
> triggers
> > even desirable feature for variables? What would be the use case?
> >
> >
> > The schema variable can hold composite value. The patch allows to use
> > any composite type or adhoc composite values
> >
> > DECLARE x AS compositetype;
> > DECLARE x AS (a int, b int, c int);
>
> I'm not sure that this anonymous composite type thing is such a good
> idea. Such a variable will then be incompatible with anything else,
> because it's of a different type.
>

Using anonymous composite type variable is just shortcut for situations
when mentioned feature is not a problem. These variables are global, so
there can be only one variable of some specific composite type, and
incompatibility with others is not a issue.

This feature can be interesting for short live temp variables - these
variables can be used for parametrization of anonymous block.

But this feature is not significant, and can be removed from patch.

> In any case, I find that a weak argument for storing this in pg_class.
> You could just as well create these pg_class entries implicitly and link
> them from "pg_variable", same as composite types have a main entry in
> pg_type and additional stuff in pg_class.
>
> > I think stuffing this into pg_class is pretty strange.
> >
> > It will be if variable is just scalar value without any possibilities.
> > But then there is only low benefit
> >
> > The access rights implementation is shared with other from pg_class too.
>
> In DB2, the privileges for variables are named READ and WRITE. That
> would make more sense to me than reusing the privilege names for tables.
>
>
good idea

Regards

Pavel

> --
> Peter Eisentraut http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>


From: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-06-27 10:21:16
Message-ID: 28924bcc-9242-9798-e4e8-9d83cea3fef6@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi,

I'm reviewing the patch as it was flagged in the current commit fest.
Here are my feedback:

 - The patch need to be rebased due to changes in file
src/sgml/catalogs.sgml

 - Some compilation warning must be fixed:

analyze.c: In function ‘transformLetStmt’:
analyze.c:1568:17: warning: variable ‘rte’ set but not used
[-Wunused-but-set-variable]
  RangeTblEntry *rte;
                 ^~~
tab-complete.c:1268:21: warning: initialization from incompatible
pointer type [-Wincompatible-pointer-types]
  {"VARIABLE", NULL, &Query_for_list_of_variables},

In the last warning a NULL is missing, should be written:
{"VARIABLE", NULL, NULL, &Query_for_list_of_variables},

 - How about Peter's suggestion?:
    "In DB2, the privileges for variables are named READ and WRITE.
That would make more sense to me than reusing the privilege names for
tables.
    The patch use SELECT and UPDATE which make sense too for SELECT but
less for UPDATE.

 - The implementation of "ALTER VARIABLE varname SET SCHEMA
schema_name;" is missing

 - ALTER VARIABLE var1 OWNER TO gilles; ok but not documented and
missing in regression test

 - ALTER VARIABLE var1 RENAME TO var2; ok but not documented and
missing in regression test

More generally I think that some comments must be rewritten, especially
those talking about a PoC. In documentation there is HTML comments that
can be removed.

Comment at end of file src/backend/commands/schemavar.c generate some
"indent with spaces" errors with git apply but perhaps the comment can
be entirely removed or undocumented details moved to the right place.

Otherwise all regression tests passed without issue and especially your
new regression tests about schema variables.

I have a patch rebased, let me known if you want me to post the new diff.

--
Gilles Darold
Consultant PostgreSQL
http://dalibo.com - http://dalibo.org


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-06-27 11:22:10
Message-ID: CAFj8pRBRxJ09ibuZT+KK3E+vc3-sXAz7HrbW3oVie7FwQRU-uQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2018-06-27 12:21 GMT+02:00 Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>:

> Hi,
>
> I'm reviewing the patch as it was flagged in the current commit fest. Here
> are my feedback:
>
> - The patch need to be rebased due to changes in file
> src/sgml/catalogs.sgml
>
> - Some compilation warning must be fixed:
>
> analyze.c: In function ‘transformLetStmt’:
> analyze.c:1568:17: warning: variable ‘rte’ set but not used
> [-Wunused-but-set-variable]
> RangeTblEntry *rte;
> ^~~
> tab-complete.c:1268:21: warning: initialization from incompatible pointer
> type [-Wincompatible-pointer-types]
> {"VARIABLE", NULL, &Query_for_list_of_variables},
>
> In the last warning a NULL is missing, should be written: {"VARIABLE",
> NULL, NULL, &Query_for_list_of_variables},
>
>
> - How about Peter's suggestion?:
> "In DB2, the privileges for variables are named READ and WRITE. That
> would make more sense to me than reusing the privilege names for tables.
>
The patch use SELECT and UPDATE which make sense too for SELECT but
> less for UPDATE.
>
> - The implementation of "ALTER VARIABLE varname SET SCHEMA schema_name;"
> is missing
>
> - ALTER VARIABLE var1 OWNER TO gilles; ok but not documented and missing
> in regression test
>
> - ALTER VARIABLE var1 RENAME TO var2; ok but not documented and missing
> in regression test
>
> More generally I think that some comments must be rewritten, especially
> those talking about a PoC. In documentation there is HTML comments that can
> be removed.
>
> Comment at end of file src/backend/commands/schemavar.c generate some
> "indent with spaces" errors with git apply but perhaps the comment can be
> entirely removed or undocumented details moved to the right place.
>
> Otherwise all regression tests passed without issue and especially your
> new regression tests about schema variables.
>
> I have a patch rebased, let me known if you want me to post the new diff.
>

I plan significant refactoring of this patch for next commitfest. There was
anotherstrong Peter's and Robert comments

1. The schema variables should to have own system table
2. The composite schema variables should to use explicitly defined
composite type
3. The memory management is not nice - transactional drop table with
content is implemented ugly.

I hope, so I can start on these issues next month.

Thank you for review - I'll recheck ALTER commands.

Regards

Pavel

>
> --
> Gilles Darold
> Consultant PostgreSQLhttp://dalibo.com - http://dalibo.org
>
>


From: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-06-27 17:15:54
Message-ID: ae98027e-25a7-b229-ffec-b05d68162718@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Le 27/06/2018 à 13:22, Pavel Stehule a écrit :
> Hi
>
> 2018-06-27 12:21 GMT+02:00 Gilles Darold <gilles(dot)darold(at)dalibo(dot)com
> <mailto:gilles(dot)darold(at)dalibo(dot)com>>:
>
> Hi,
>
> I'm reviewing the patch as it was flagged in the current commit
> fest. Here are my feedback:
>
>  - The patch need to be rebased due to changes in file
> src/sgml/catalogs.sgml
>
>  - Some compilation warning must be fixed:
>
> analyze.c: In function ‘transformLetStmt’:
> analyze.c:1568:17: warning: variable ‘rte’ set but not used
> [-Wunused-but-set-variable]
>   RangeTblEntry *rte;
>                  ^~~
> tab-complete.c:1268:21: warning: initialization from
> incompatible pointer type [-Wincompatible-pointer-types]
>   {"VARIABLE", NULL, &Query_for_list_of_variables},
>
> In the last warning a NULL is missing, should be written:
> {"VARIABLE", NULL, NULL, &Query_for_list_of_variables},
>
>
>  - How about Peter's suggestion?:
>     "In DB2, the privileges for variables are named READ and
> WRITE. That would make more sense to me than reusing the privilege
> names for tables.
>
>     The patch use SELECT and UPDATE which make sense too for
> SELECT but less for UPDATE.
>
>  - The implementation of "ALTER VARIABLE varname SET SCHEMA
> schema_name;" is missing
>
>  - ALTER VARIABLE var1 OWNER TO gilles; ok but not documented and
> missing in regression test
>
>  - ALTER VARIABLE var1 RENAME TO var2; ok but not documented and
> missing in regression test
>
> More generally I think that some comments must be rewritten,
> especially those talking about a PoC. In documentation there is
> HTML comments that can be removed.
>
> Comment at end of file src/backend/commands/schemavar.c generate
> some "indent with spaces" errors with git apply but perhaps the
> comment can be entirely removed or undocumented details moved to
> the right place.
>
> Otherwise all regression tests passed without issue and especially
> your new regression tests about schema variables.
>
> I have a patch rebased, let me known if you want me to post the
> new diff.
>
>
> I plan significant refactoring of this patch for next commitfest.
> There was anotherstrong Peter's and Robert comments
>
> 1. The schema variables should to have own system table
> 2. The composite schema variables should to use explicitly defined
> composite type
> 3. The memory management is not nice - transactional drop table with
> content is implemented ugly.
>
> I hope, so I can start on these issues next month.
>
> Thank you for review - I'll recheck ALTER commands.
>
>
> Otherwise all regression tests passed without issue and especially
> your new regression tests about schema variables.
>
> I have a patch rebased, let me known if you want me to post the
> new diff.
>
>
> I plan significant refactoring of this patch for next commitfest.
> There was anotherstrong Peter's and Robert c
> Regards

Ok Pavel, I've changed the status to "Waiting for authors" so that no
one will make an other review until you send a new patch.

--
Gilles Darold
Consultant PostgreSQL
http://dalibo.com - http://dalibo.org


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-06-27 17:17:05
Message-ID: CAFj8pRDvG1AAg1bvvGWtypbK=wd9txLB+YLzH7iEN4tc-GV1dg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-06-27 19:15 GMT+02:00 Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>:

> Le 27/06/2018 à 13:22, Pavel Stehule a écrit :
>
> Hi
>
> 2018-06-27 12:21 GMT+02:00 Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>:
>
>> Hi,
>>
>> I'm reviewing the patch as it was flagged in the current commit fest.
>> Here are my feedback:
>>
>> - The patch need to be rebased due to changes in file
>> src/sgml/catalogs.sgml
>>
>> - Some compilation warning must be fixed:
>>
>> analyze.c: In function ‘transformLetStmt’:
>> analyze.c:1568:17: warning: variable ‘rte’ set but not used
>> [-Wunused-but-set-variable]
>> RangeTblEntry *rte;
>> ^~~
>> tab-complete.c:1268:21: warning: initialization from incompatible pointer
>> type [-Wincompatible-pointer-types]
>> {"VARIABLE", NULL, &Query_for_list_of_variables},
>>
>> In the last warning a NULL is missing, should be written: {"VARIABLE",
>> NULL, NULL, &Query_for_list_of_variables},
>>
>>
>> - How about Peter's suggestion?:
>> "In DB2, the privileges for variables are named READ and WRITE. That
>> would make more sense to me than reusing the privilege names for tables.
>>
> The patch use SELECT and UPDATE which make sense too for SELECT but
>> less for UPDATE.
>>
>> - The implementation of "ALTER VARIABLE varname SET SCHEMA schema_name;"
>> is missing
>>
>> - ALTER VARIABLE var1 OWNER TO gilles; ok but not documented and missing
>> in regression test
>>
>> - ALTER VARIABLE var1 RENAME TO var2; ok but not documented and missing
>> in regression test
>>
>> More generally I think that some comments must be rewritten, especially
>> those talking about a PoC. In documentation there is HTML comments that can
>> be removed.
>>
>> Comment at end of file src/backend/commands/schemavar.c generate some
>> "indent with spaces" errors with git apply but perhaps the comment can be
>> entirely removed or undocumented details moved to the right place.
>>
>> Otherwise all regression tests passed without issue and especially your
>> new regression tests about schema variables.
>>
>> I have a patch rebased, let me known if you want me to post the new diff.
>>
>
> I plan significant refactoring of this patch for next commitfest. There
> was anotherstrong Peter's and Robert comments
>
> 1. The schema variables should to have own system table
> 2. The composite schema variables should to use explicitly defined
> composite type
> 3. The memory management is not nice - transactional drop table with
> content is implemented ugly.
>
> I hope, so I can start on these issues next month.
>
> Thank you for review - I'll recheck ALTER commands.
>
>>
>> Otherwise all regression tests passed without issue and especially your
>> new regression tests about schema variables.
>>
>> I have a patch rebased, let me known if you want me to post the new diff.
>>
>
> I plan significant refactoring of this patch for next commitfest. There
> was anotherstrong Peter's and Robert c
> Regards
>
>
> Ok Pavel, I've changed the status to "Waiting for authors" so that no one
> will make an other review until you send a new patch.
>
sure

Thank you

Pavel

>
> --
> Gilles Darold
> Consultant PostgreSQLhttp://dalibo.com - http://dalibo.org
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-08 20:29:29
Message-ID: CAFj8pRATM44F1ugXxTn6aofxOa=3DZbqOJ17=EVyG+CEzsRQvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-06-27 19:15 GMT+02:00 Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>:

> Le 27/06/2018 à 13:22, Pavel Stehule a écrit :
>
> Hi
>
> 2018-06-27 12:21 GMT+02:00 Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>:
>
>> Hi,
>>
>> I'm reviewing the patch as it was flagged in the current commit fest.
>> Here are my feedback:
>>
>> - The patch need to be rebased due to changes in file
>> src/sgml/catalogs.sgml
>>
>> - Some compilation warning must be fixed:
>>
>> analyze.c: In function ‘transformLetStmt’:
>> analyze.c:1568:17: warning: variable ‘rte’ set but not used
>> [-Wunused-but-set-variable]
>> RangeTblEntry *rte;
>> ^~~
>> tab-complete.c:1268:21: warning: initialization from incompatible pointer
>> type [-Wincompatible-pointer-types]
>> {"VARIABLE", NULL, &Query_for_list_of_variables},
>>
>> In the last warning a NULL is missing, should be written: {"VARIABLE",
>> NULL, NULL, &Query_for_list_of_variables},
>>
>>
>> - How about Peter's suggestion?:
>> "In DB2, the privileges for variables are named READ and WRITE. That
>> would make more sense to me than reusing the privilege names for tables.
>>
> The patch use SELECT and UPDATE which make sense too for SELECT but
>> less for UPDATE.
>>
>> - The implementation of "ALTER VARIABLE varname SET SCHEMA schema_name;"
>> is missing
>>
>> - ALTER VARIABLE var1 OWNER TO gilles; ok but not documented and missing
>> in regression test
>>
>> - ALTER VARIABLE var1 RENAME TO var2; ok but not documented and missing
>> in regression test
>>
>> More generally I think that some comments must be rewritten, especially
>> those talking about a PoC. In documentation there is HTML comments that can
>> be removed.
>>
>> Comment at end of file src/backend/commands/schemavar.c generate some
>> "indent with spaces" errors with git apply but perhaps the comment can be
>> entirely removed or undocumented details moved to the right place.
>>
>> Otherwise all regression tests passed without issue and especially your
>> new regression tests about schema variables.
>>
>> I have a patch rebased, let me known if you want me to post the new diff.
>>
>
> I plan significant refactoring of this patch for next commitfest. There
> was anotherstrong Peter's and Robert comments
>
> 1. The schema variables should to have own system table
> 2. The composite schema variables should to use explicitly defined
> composite type
> 3. The memory management is not nice - transactional drop table with
> content is implemented ugly.
>
> I hope, so I can start on these issues next month.
>
> Thank you for review - I'll recheck ALTER commands.
>
>>
>> Otherwise all regression tests passed without issue and especially your
>> new regression tests about schema variables.
>>
>> I have a patch rebased, let me known if you want me to post the new diff.
>>
>
> I plan significant refactoring of this patch for next commitfest. There
> was anotherstrong Peter's and Robert c
> Regards
>
>
> Ok Pavel, I've changed the status to "Waiting for authors" so that no one
> will make an other review until you send a new patch.
>
I am sending a new update of this feature. The functionality is +/- same
like previous patch, but a implementation is based on own catalog table.

I removed functions for manipulation with schema variables. These functions
can be added later simply. Now If we hold these functions, then we should
to solve often collision inside pg_proc.

Changes:

* own catalog - pg_variable
* the rights are renamed - READ|WRITE
* the code is cleaner

Regards

Pavel

>
> --
> Gilles Darold
> Consultant PostgreSQLhttp://dalibo.com - http://dalibo.org
>
>

Attachment Content-Type Size
schema-variables-180808-01.patch text/x-patch 190.5 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-08 20:35:28
Message-ID: CAFj8pRCN84iKuvP9Mh41=jOMSOCP89z8VvK0sWBnKTptBYPA4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

removed forgotten file

Regards

Pavel

Attachment Content-Type Size
schema-variables-180808-02.patch text/x-patch 181.4 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-11 05:39:49
Message-ID: CAFj8pRDnoA3J2RM=WZJdYBXEiJUOfDv-gyJmp81Pq93jmrBb5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I am sending updated patch. It should to solve almost all Giles's and
Peter's objections.

I am not happy so executor access values of variables directly. It is most
simple implementation - and I hope so it is good enough, but now the access
to variables is too volatile. But it is works good enough for usability
testing.

I am thinking about some cache of used variables in ExprContext, so the
variable in one ExprContext will look like stable - more like PLpgSQL
variables.

Regards

Pavel

Attachment Content-Type Size
schema-variables-180811-01.patch text/x-patch 188.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-11 18:46:34
Message-ID: CAFj8pRCTz_CRez3vFo_Ta_m=KtOxBGHE9+T1QG3UgRbuURfzjA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-08-11 7:39 GMT+02:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

> Hi
>
> I am sending updated patch. It should to solve almost all Giles's and
> Peter's objections.
>
> I am not happy so executor access values of variables directly. It is most
> simple implementation - and I hope so it is good enough, but now the access
> to variables is too volatile. But it is works good enough for usability
> testing.
>
> I am thinking about some cache of used variables in ExprContext, so the
> variable in one ExprContext will look like stable - more like PLpgSQL
> variables.
>

I wrote EState based schema variable values cache, so now the variables in
queries are stable (like PARAM_EXTERN) and can be used for optimization.

Regards

Pavel

>
> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-180811-02.patch text/x-patch 193.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-12 05:35:33
Message-ID: CAFj8pRA_jZYuTRHEMsv8CnZLBqmnS5xRjcZh-uf0nBWA7WrzMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2018-08-11 20:46 GMT+02:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

>
>
> 2018-08-11 7:39 GMT+02:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>
>> Hi
>>
>> I am sending updated patch. It should to solve almost all Giles's and
>> Peter's objections.
>>
>> I am not happy so executor access values of variables directly. It is
>> most simple implementation - and I hope so it is good enough, but now the
>> access to variables is too volatile. But it is works good enough for
>> usability testing.
>>
>> I am thinking about some cache of used variables in ExprContext, so the
>> variable in one ExprContext will look like stable - more like PLpgSQL
>> variables.
>>
>
> I wrote EState based schema variable values cache, so now the variables in
> queries are stable (like PARAM_EXTERN) and can be used for optimization.
>

new update - after cleaning

Regards

Pavel

> Regards
>
> Pavel
>
>
>>
>> Regards
>>
>> Pavel
>>
>
>

Attachment Content-Type Size
schema-variables-180812-01.patch text/x-patch 194.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-14 14:38:56
Message-ID: CAFj8pRD3J+92Va+T=tK0Q14Q4J-CVgKEoXGH8cS3YqRzQcbOUQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I wrote missing collation support

Regards

Pavel

Attachment Content-Type Size
schema-variables-180814-01.patch text/x-patch 197.4 KB

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-21 17:55:57
Message-ID: alpine.DEB.2.21.1808211938510.11873@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


Hello Pavel,

AFAICR, I had an objection on such new objects when you first proposed
something similar in October 2016.

Namely, if session variables are not transactional, they cannot be used to
implement security related auditing features which were advertised as the
motivating use case: an the audit check may fail on a commit because of a
differed constraint, but the variable would keep its "okay" value unduly,
which would create a latent security issue, the audit check having failed
but the variable saying the opposite.

So my point was that they should be transactional by default, although I
would be ok with an option for having a voluntary non transactional
version.

Is this issue addressed somehow with this version?

--
Fabien.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-21 18:48:25
Message-ID: CAFj8pRCRUpNjX9Fb49SaADbRnCE69ndkOvtoeKxwvxetfJ8=kA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi Fabien

Dne út 21. 8. 2018 19:56 uživatel Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
napsal:

>
> Hello Pavel,
>
> AFAICR, I had an objection on such new objects when you first proposed
> something similar in October 2016.
>
> Namely, if session variables are not transactional, they cannot be used to
> implement security related auditing features which were advertised as the
> motivating use case: an the audit check may fail on a commit because of a
> differed constraint, but the variable would keep its "okay" value unduly,
> which would create a latent security issue, the audit check having failed
> but the variable saying the opposite.
>
> So my point was that they should be transactional by default, although I
> would be ok with an option for having a voluntary non transactional
> version.
>
> Is this issue addressed somehow with this ?

1. I respect your opinion, but I dont agree with it. Oracle, db2 has
similar or very similar feature non transactional, and I didnt find any
requests to change it.

2. the prototype implementation was based on relclass items, and some
transactional behave was possible. Peter E. had objections to this design
and proposed own catalog table. I did it. Now, the transactional behave is
harder to implement, although it is not impossible. This patch is not small
now, so I didnt implement it. I have a strong opinion so default behave
have to be non transactional.

Transactional variables significantly increases complexity of this patch,
now is simple, because we can reset variable on drop variable command.
Maybe I miss some simply implementation, but I spent on it more than few
days. Still, any cooperation are welcome.

Regards

Pavel

> --
> Fabien.
>


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-22 07:00:45
Message-ID: alpine.DEB.2.21.1808220831550.10677@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


Hello Pavel,

>> AFAICR, I had an objection on such new objects when you first proposed
>> something similar in October 2016.
>>
>> Namely, if session variables are not transactional, they cannot be used to
>> implement security related auditing features which were advertised as the
>> motivating use case: an the audit check may fail on a commit because of a
>> differed constraint, but the variable would keep its "okay" value unduly,
>> which would create a latent security issue, the audit check having failed
>> but the variable saying the opposite.
>>
>> So my point was that they should be transactional by default, although I
>> would be ok with an option for having a voluntary non transactional
>> version.
>>
>> Is this issue addressed somehow with this ?
>
>
> 1. I respect your opinion, but I dont agree with it. Oracle, db2 has
> similar or very similar feature non transactional, and I didnt find any
> requests to change it.

The argument of authority that "X does it like that" is not a valid answer
to my technical objection about security implications of this feature.

> 2. the prototype implementation was based on relclass items, and some
> transactional behave was possible. Peter E. had objections to this design
> and proposed own catalog table. I did it. Now, the transactional behave is
> harder to implement, although it is not impossible. This patch is not small
> now, so I didnt implement it.

"It is harder to implement" does not look like a valid answer either.

> I have a strong opinion so default behave have to be non transactional.

The fact that you have a "strong opinion" does not really answer my
objection. Moreover, I said that I would be ok with a non transactional
option, provided that a default transactional is available.

> Transactional variables significantly increases complexity of this patch,
> now is simple, because we can reset variable on drop variable command.
> Maybe I miss some simply implementation, but I spent on it more than few
> days. Still, any cooperation are welcome.

"It is simpler to implement this way" is not an answer either, especially
as you said that it could have been on point 2.

As I do not see any clear answer to my objection about security
implications, I understand that it is not addressed by this patch.

At the bare minimum, if this feature ever made it as is, I think that a
clear caveat must be included in the documentation about not using it for
any security-related purpose.

Also, I'm not really sure how useful such a non-transactional object can
be for other purposes: the user should take into account that the
transaction may fail and the value of the session variable be inconsistent
as a result. Sometimes it may not matter, but if it matters there is no
easy way around the fact.

--
Fabien.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-23 05:35:22
Message-ID: CAFj8pRCyvx37Fnw6yHdscGbbGo_Ak3WdeKiZ6arFW8JTA099YA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-08-22 9:00 GMT+02:00 Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>:

>
> Hello Pavel,
>
> AFAICR, I had an objection on such new objects when you first proposed
>>> something similar in October 2016.
>>>
>>> Namely, if session variables are not transactional, they cannot be used
>>> to
>>> implement security related auditing features which were advertised as the
>>> motivating use case: an the audit check may fail on a commit because of a
>>> differed constraint, but the variable would keep its "okay" value unduly,
>>> which would create a latent security issue, the audit check having failed
>>> but the variable saying the opposite.
>>>
>>> So my point was that they should be transactional by default, although I
>>> would be ok with an option for having a voluntary non transactional
>>> version.
>>>
>>> Is this issue addressed somehow with this ?
>>>
>>
>>
>> 1. I respect your opinion, but I dont agree with it. Oracle, db2 has
>> similar or very similar feature non transactional, and I didnt find any
>> requests to change it.
>>
>
> The argument of authority that "X does it like that" is not a valid answer
> to my technical objection about security implications of this feature.
>
> 2. the prototype implementation was based on relclass items, and some
>> transactional behave was possible. Peter E. had objections to this design
>> and proposed own catalog table. I did it. Now, the transactional behave is
>> harder to implement, although it is not impossible. This patch is not
>> small
>> now, so I didnt implement it.
>>
>
> "It is harder to implement" does not look like a valid answer either.
>
> I have a strong opinion so default behave have to be non transactional.
>>
>
> The fact that you have a "strong opinion" does not really answer my
> objection. Moreover, I said that I would be ok with a non transactional
> option, provided that a default transactional is available.
>
> Transactional variables significantly increases complexity of this patch,
>> now is simple, because we can reset variable on drop variable command.
>> Maybe I miss some simply implementation, but I spent on it more than few
>> days. Still, any cooperation are welcome.
>>
>
> "It is simpler to implement this way" is not an answer either, especially
> as you said that it could have been on point 2.
>
>
> As I do not see any clear answer to my objection about security
> implications, I understand that it is not addressed by this patch.
>
>
> At the bare minimum, if this feature ever made it as is, I think that a
> clear caveat must be included in the documentation about not using it for
> any security-related purpose.
>
> Also, I'm not really sure how useful such a non-transactional object can
> be for other purposes: the user should take into account that the
> transaction may fail and the value of the session variable be inconsistent
> as a result. Sometimes it may not matter, but if it matters there is no
> easy way around the fact.
>

I agree, so it should be well documented to be clear, what is possible,
what not, and to be correct expectations.

This feature has two (three) purposes

1. global variables for PL language
2. holding some session based informations, that can be used in security
definer functions.
3. Because it is not transactional, then it allows write operation on read
only hot stand by instances.

It is not transactional safe, but it is secure in sense a possibility to
set a access rights. I understand, so some patterns are not possible, but
when you need hold some keys per session, then this simply solution can be
good enough. The variables are clean after session end.

I think it is possible for some more complex patterns, but then developer
should be smarter, and should to enocode state result to content of
variable. There is strong benefit - read write access to variables is very
cheap and fast.

I invite any patch to doc (or everywhere) with explanation and about
possible risks.

Regards

Pavel

> --
> Fabien.
>


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-23 08:17:28
Message-ID: alpine.DEB.2.21.1808230927090.31897@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


Hello Pavel,

> 2. holding some session based informations, that can be used in security
> definer functions.

Hmmm, I see our disagreement. My point is that this feature is *NOT* fit
for security-related uses because if the transaction fails the variable
would keep the value it had if the transaction had not failed...

> 3. Because it is not transactional, then it allows write operation on read

> It is not transactional safe, but it is secure in sense a possibility to
> set a access rights.

This is a misleading play on words. It is secure wrt to access right, but
unsecure wrt security purposes which is the only point for having such a
feature in the first place.

> I understand, so some patterns are not possible, but when you need hold
> some keys per session, then this simply solution can be good enough.

Security vs "good enough in some cases" looks bad to me.

> I think it is possible for some more complex patterns,

I'm not sure of any pattern which would be correct wrt security if it
depends on the success of a transaction.

> but then developer should be smarter, and should to enocode state result
> to content of variable.

I do not see how the developer can be smarter if they need a transactional
for security but they do not have it.

> There is strong benefit - read write access to variables is very cheap
> and fast.

I'd say that PostgreSQL is about "ACID & security" first, not "cheap &
fast" first.

> I invite any patch to doc (or everywhere) with explanation and about
> possible risks.

Hmmm... You are the one proposing the feature...

Here is something, thanks for adjusting it to the syntax you are proposing
and inserting it where appropriate. Possibly in the corresponding CREATE
doc?

"""
<caution>
<par>
Beware that session variables are not transactional.
This is a concern in a security context where the variable must be set to
some trusted value depending on the success of the transaction:
if the transaction fails, the variable keeps its trusted value unduly.
</par>

<par>
For instance, the following pattern does NOT work:

<programlisting>
CREATE USER auditer;
SET ROLE auditer;
CREATE SESSION VARIABLE is_audited BOOLEAN DEFAULT FALSE ...;
-- ensure that only "auditer" can write "is_audited":
REVOKE ... ON SESSION VARIABLE is_audited FROM ...;

-- create an audit function
CREATE FUNCTION audit_session(...) SECURITY DEFINER AS $$
-- record the session and checks in some place...
-- then tell it was done:
LET is_audited = TRUE;
$$;

-- the intention is that other security definier functions can check that
-- the session is audited by checking on "is_audited", eg:
CREATE FUNCTION only_for_audited(...) SECURITY DEFINER AS $$
IF NOT is_audited THEN RAISE "security error";
-- do protected stuff here.
$$;
</programlisting>

The above pattern can be attacked with the following approach:
<programlisting>
BEGIN;
SELECT audit_session(...);
-- success, "is_audited" is set...
ROLLBACK;
-- the audit login has been reverted, but "is_audited" retains its value.

-- any subsequent operation believes wrongly that the session is audited,
-- but its logging has really been removed by the ROLLBACK.

-- ok but should not:
SELECT only_for_audited(...);
</programlisting>
</par>
</caution>
"""

For the record, I'm "-1" on this feature as proposed, for what it's worth,
because of the misleading security implications. This feature would just
help people have their security wrong.

--
Fabien.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-23 08:44:10
Message-ID: CAFj8pRAcFv09qOcbr09c2AbwZ9DGw5Hs6rPcYoo7r9OLdWWB2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-08-23 10:17 GMT+02:00 Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>:

>
> Hello Pavel,
>
> 2. holding some session based informations, that can be used in security
>> definer functions.
>>
>
> Hmmm, I see our disagreement. My point is that this feature is *NOT* fit
> for security-related uses because if the transaction fails the variable
> would keep the value it had if the transaction had not failed...
>
> 3. Because it is not transactional, then it allows write operation on read
>>
>
> It is not transactional safe, but it is secure in sense a possibility to
>> set a access rights.
>>
>
> This is a misleading play on words. It is secure wrt to access right, but
> unsecure wrt security purposes which is the only point for having such a
> feature in the first place.
>
> I understand, so some patterns are not possible, but when you need hold
>> some keys per session, then this simply solution can be good enough.
>>
>
> Security vs "good enough in some cases" looks bad to me.
>

We don't find a agreement, because you are concentrated on transation, me
on session. And we have different expectations.

> I think it is possible for some more complex patterns,
>>
>
> I'm not sure of any pattern which would be correct wrt security if it
> depends on the success of a transaction.
>
> but then developer should be smarter, and should to enocode state result
>> to content of variable.
>>
>
> I do not see how the developer can be smarter if they need a transactional
> for security but they do not have it.
>
> There is strong benefit - read write access to variables is very cheap and
>> fast.
>>
>
> I'd say that PostgreSQL is about "ACID & security" first, not "cheap &
> fast" first.
>
> I invite any patch to doc (or everywhere) with explanation and about
>> possible risks.
>>
>
> Hmmm... You are the one proposing the feature...
>
> Here is something, thanks for adjusting it to the syntax you are proposing
> and inserting it where appropriate. Possibly in the corresponding CREATE
> doc?
>
> """
> <caution>
> <par>
> Beware that session variables are not transactional.
> This is a concern in a security context where the variable must be set to
> some trusted value depending on the success of the transaction:
> if the transaction fails, the variable keeps its trusted value unduly.
> </par>
>
> <par>
> For instance, the following pattern does NOT work:
>
> <programlisting>
> CREATE USER auditer;
> SET ROLE auditer;
> CREATE SESSION VARIABLE is_audited BOOLEAN DEFAULT FALSE ...;
> -- ensure that only "auditer" can write "is_audited":
> REVOKE ... ON SESSION VARIABLE is_audited FROM ...;
>
> -- create an audit function
> CREATE FUNCTION audit_session(...) SECURITY DEFINER AS $$
> -- record the session and checks in some place...
> -- then tell it was done:
> LET is_audited = TRUE;
> $$;
>
> -- the intention is that other security definier functions can check that
> -- the session is audited by checking on "is_audited", eg:
> CREATE FUNCTION only_for_audited(...) SECURITY DEFINER AS $$
> IF NOT is_audited THEN RAISE "security error";
> -- do protected stuff here.
> $$;
> </programlisting>
>
> The above pattern can be attacked with the following approach:
> <programlisting>
> BEGIN;
> SELECT audit_session(...);
> -- success, "is_audited" is set...
> ROLLBACK;
> -- the audit login has been reverted, but "is_audited" retains its value.
>
> -- any subsequent operation believes wrongly that the session is audited,
> -- but its logging has really been removed by the ROLLBACK.
>
> -- ok but should not:
> SELECT only_for_audited(...);
> </programlisting>
> </par>
> </caution>
> """
>
>
It is good example of not supported pattern. It is not designed for this.
I'll merge this doc.

Note: I am not sure, if I have all relations to described issue, but if I
understand well, then solution can be reset on transaction end, maybe reset
on rollback. This is solvable, I'll look how it is complex.

>
> For the record, I'm "-1" on this feature as proposed, for what it's worth,
> because of the misleading security implications. This feature would just
> help people have their security wrong.
>

I respect your opinion - and I hope so integration of your proposed doc is
good warning for users that would to use not transactional variable like
transactional source.

Regards

Pavel

>
> --
> Fabien.
>
>


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-23 09:46:32
Message-ID: alpine.DEB.2.21.1808231123050.31897@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


>> Security vs "good enough in some cases" looks bad to me.
>
> We don't find a agreement, because you are concentrated on transation,
> me on session. And we have different expectations.

I do not understand your point, as usual. I raise a factual issue about
security, and you do not answer how this can be solved with your proposal,
but appeal to argument of authority and declare your "strong opinion".

I do not see any intrinsic opposition between having session objects and
transactions. Nothing prevents a session object to be transactional beyond
your willingness that it should not be.

Now, I do expect all PostgreSQL features to be security-wise, whatever
their scope.

I do not think that security should be traded for "cheap & fast", esp as
the sole use case for a feature is a security pattern that cannot be
implemented securely with it. This appears to me as a huge contradiction,
hence my opposition against this feature as proposed.

The good news is that I'm a nobody: if a committer is happy with your
patch, it will get committed, you do not need my approval.

--
Fabien.


From: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-23 12:39:07
Message-ID: 66454695-1317-feb8-766a-a8daa75fde06@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


On 23.08.2018 12:46, Fabien COELHO wrote:
> I do not understand your point, as usual. I raise a factual issue
> about security, and you do not answer how this can be solved with your
> proposal, but appeal to argument of authority and declare your "strong
> opinion".
>
> I do not see any intrinsic opposition between having session objects
> and transactions. Nothing prevents a session object to be
> transactional beyond your willingness that it should not be.
>
> Now, I do expect all PostgreSQL features to be security-wise, whatever
> their scope.
>
> I do not think that security should be traded for "cheap & fast", esp
> as the sole use case for a feature is a security pattern that cannot
> be implemented securely with it. This appears to me as a huge
> contradiction, hence my opposition against this feature as proposed.

I can't to agree with your position.

Consider this example.
I want to record some inappropriate user actions to audit table and
rollback transaction.
But aborting transaction will also abort record to audit table.
So, do not use tables, becouse they have security implications.

This is very similar to your approach.

Schema variables is a very needed and important feature, but for others
purposes.

-----
Pavel Luzanov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-08-29 18:10:02
Message-ID: alpine.DEB.2.21.1808291954300.14012@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


Hello Pavel L.

>> I do not understand your point, as usual. I raise a factual issue about
>> security, and you do not answer how this can be solved with your proposal,
>> but appeal to argument of authority and declare your "strong opinion".
>>
>> I do not see any intrinsic opposition between having session objects and
>> transactions. Nothing prevents a session object to be transactional beyond
>> your willingness that it should not be.
>>
>> Now, I do expect all PostgreSQL features to be security-wise, whatever
>> their scope.
>>
>> I do not think that security should be traded for "cheap & fast", esp as
>> the sole use case for a feature is a security pattern that cannot be
>> implemented securely with it. This appears to me as a huge contradiction,
>> hence my opposition against this feature as proposed.
>
> I can't to agree with your position.
>
> Consider this example. I want to record some inappropriate user actions
> to audit table and rollback transaction. But aborting transaction will
> also abort record to audit table. So, do not use tables, becouse they
> have security implications.

Indeed, you cannot record a transaction failure from a transaction.

> This is very similar to your approach.

I understand that your point is that some use case could require a non
transactional session variable. I'm not sure of how the use case would go
on though, because once the "attacker" disconnects, the session variable
disappears, so it does not record that there was a problem.

Anyway, I'm not against having session variables per se. I'm argumenting
that there is a good case to have them transactional by default, and
possibly an option to have them non transactional if this is really needed
by some use case to provide.

The only use case put forward by Pavel S. is the security audit one
where a session variable stores that audit checks have been performed,
which AFAICS cannot be implemented securely with the proposed non
transactional session variables.

--
Fabien.


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-04 07:21:07
Message-ID: CAEZATCVy77hhgTZ1Yrvbp6GbsUuWY0Bw8CLbv_Jr2mAF_bOkBA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

AFAICS this patch does nothing to consider parallel safety -- that is,
as things stand, a variable is allowed in a query that may be
parallelised, but its value is not copied to workers, leading to
incorrect results. For example:

create table foo(a int);
insert into foo select * from generate_series(1,1000000);
create variable zero int;
let zero = 0;

explain (costs off) select count(*) from foo where a%10 = zero;

QUERY PLAN
-----------------------------------------------
Finalize Aggregate
-> Gather
Workers Planned: 2
-> Partial Aggregate
-> Parallel Seq Scan on foo
Filter: ((a % 10) = zero)
(6 rows)

select count(*) from foo where a%10 = zero;

count
-------
38037 -- Different random result each time, should be 100,000
(1 row)

Thoughts?

Regards,
Dean


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-04 13:00:51
Message-ID: CAFj8pRBSQDs3SpJ6EV-SP2Gkoc6OwxzCkB8ka7815o3Tw2TkxQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

2018-09-04 9:21 GMT+02:00 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>:

> AFAICS this patch does nothing to consider parallel safety -- that is,
> as things stand, a variable is allowed in a query that may be
> parallelised, but its value is not copied to workers, leading to
> incorrect results. For example:
>
> create table foo(a int);
> insert into foo select * from generate_series(1,1000000);
> create variable zero int;
> let zero = 0;
>
> explain (costs off) select count(*) from foo where a%10 = zero;
>
> QUERY PLAN
> -----------------------------------------------
> Finalize Aggregate
> -> Gather
> Workers Planned: 2
> -> Partial Aggregate
> -> Parallel Seq Scan on foo
> Filter: ((a % 10) = zero)
> (6 rows)
>
> select count(*) from foo where a%10 = zero;
>
> count
> -------
> 38037 -- Different random result each time, should be 100,000
> (1 row)
>
> Thoughts?
>

The query use copy of values of variables now - but unfortunately, these
values are not passed to workers. Should be fixed.

Thank you for test case.

Pavel

> Regards,
> Dean
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-06 08:30:04
Message-ID: CAFj8pRB+PDcKX0WJqovhxMJb=O=k4qV+EekFDKFpyVSZLzFzfA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

here is updated patch - I wrote some transactional support

I am not sure how these new features are understandable and if these
features does it better or not.

There are possibility to reset to default value when

a) any transaction is finished - the scope of value is limited by
transaction

CREATE VARIABLE foo int ON TRANSACTION END RESET;

b) when transaction finished by rollback

CREATE VARIABLE foo int ON ROLLBACK RESET

Now, when I am thinking about it, the @b is simple, but not too practical -
when some fails, then we lost a value (any transaction inside session can
fails). The @a has sense - the behave is global value (what is not possible
in Postgres now), but this value is destroyed by any unhandled exceptions,
and it cleaned on transaction end. The @b is just for information and for
discussion, but I'll remove it - because it is obscure.

The open question is syntax. PostgreSQL has already ON COMMIT xxx . It is
little bit unclean, because it has semantic "on transaction end", but if I
didn't implement @b, then ON COMMIT syntax can be used.

Regards

Pavel

Attachment Content-Type Size
schema-variables-180906-01.patch text/x-patch 208.8 KB

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-07 12:34:04
Message-ID: alpine.DEB.2.21.1809071413440.26080@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


Hello Pavel,

> here is updated patch - I wrote some transactional support
>
> I am not sure how these new features are understandable and if these
> features does it better or not.

> There are possibility to reset to default value when
>
> a) any transaction is finished - the scope of value is limited by
> transaction
>
> CREATE VARIABLE foo int ON TRANSACTION END RESET;

With this option I understand that it is a "within a transactionnal"
variable, i.e. when the transaction ends, whether commit or rollback, the
variable is reset to a default variable. It is not really a "session"
variable anymore, each transaction has its own value.

-- begin session
-- foo has default value, eg NULL
BEGIN;
LET foo = 1;
COMMIT/ROLLBACK;
-- foo has default value again, NULL

> b) when transaction finished by rollback
>
> CREATE VARIABLE foo int ON ROLLBACK RESET

That is a little bit safer and you are back to a SESSION-scope variable,
which is reset to the default value if the (any) transaction fails?

-- begin session
-- foo has default value, eg NULL
BEGIN;
LET foo = 1;
COMMIT;
-- foo has value 1
BEGIN;
-- foo has value 1...
ROLLBACK;
-- foo has value NULL

c) A more logical (from a transactional point of view - but not necessary
simple to implement, I do not know) feature/variant would be to reset the
value to the one it had at the beginning of the transaction, which is not
necessarily the default.

-- begin session
-- foo has default value, eg NULL
BEGIN;
LET foo = 1;
COMMIT;
-- foo has value 1
BEGIN;
LET foo = 2; (*)
-- foo has value 2
ROLLBACK;
-- foo has value 1 back, change (*) has been reverted

> Now, when I am thinking about it, the @b is simple, but not too practical -
> when some fails, then we lost a value (any transaction inside session can
> fails).

Indeed.

> The @a has sense - the behave is global value (what is not possible
> in Postgres now), but this value is destroyed by any unhandled exceptions,
> and it cleaned on transaction end. The @b is just for information and for
> discussion, but I'll remove it - because it is obscure.

Indeed.

> The open question is syntax. PostgreSQL has already ON COMMIT xxx . It is
> little bit unclean, because it has semantic "on transaction end", but if I
> didn't implement @b, then ON COMMIT syntax can be used.

I was more arguing on the third (c) option, i.e. on rollback the value is
reverted to its value at the beginning of the rollbacked transaction.

At the minimum, ISTM that option (b) is enough to implement the audit
pattern, but it would mean that any session which has a rollback, for any
reason (deadlock, serialization...), would have to be reinitialized, which
would be a drawback.

The to options could be non-transactional session variables "ON ROLLBACK
DO NOT RESET/DO NOTHING", and somehow transactional session variables "ON
ROLLBACK RESET TO DEFAULT" (b) or "ON ROLLBACK RESET TO INITIAL" (c).

--
Fabien.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-07 14:28:00
Message-ID: CAFj8pRD7Updp0-eK2vO11DVn-WUAW3yHSdmTrNTb702KU_nrsw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

2018-09-07 14:34 GMT+02:00 Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>:

>
> Hello Pavel,
>
> here is updated patch - I wrote some transactional support
>>
>> I am not sure how these new features are understandable and if these
>> features does it better or not.
>>
>
> There are possibility to reset to default value when
>>
>> a) any transaction is finished - the scope of value is limited by
>> transaction
>>
>> CREATE VARIABLE foo int ON TRANSACTION END RESET;
>>
>
> With this option I understand that it is a "within a transactionnal"
> variable, i.e. when the transaction ends, whether commit or rollback, the
> variable is reset to a default variable. It is not really a "session"
> variable anymore, each transaction has its own value.
>

yes, the correct name should be "schema variable with transaction scope". I
think it can be useful like short life global variable. These variables can
works like transaction caches.

> -- begin session
> -- foo has default value, eg NULL
> BEGIN;
> LET foo = 1;
> COMMIT/ROLLBACK;
> -- foo has default value again, NULL
>
> b) when transaction finished by rollback
>>
>> CREATE VARIABLE foo int ON ROLLBACK RESET
>>
>
> That is a little bit safer and you are back to a SESSION-scope variable,
> which is reset to the default value if the (any) transaction fails?
>
> -- begin session
> -- foo has default value, eg NULL
> BEGIN;
> LET foo = 1;
> COMMIT;
> -- foo has value 1
> BEGIN;
> -- foo has value 1...
> ROLLBACK;
> -- foo has value NULL
>
> c) A more logical (from a transactional point of view - but not necessary
> simple to implement, I do not know) feature/variant would be to reset the
> value to the one it had at the beginning of the transaction, which is not
> necessarily the default.
>
> -- begin session
> -- foo has default value, eg NULL
> BEGIN;
> LET foo = 1;
> COMMIT;
> -- foo has value 1
> BEGIN;
> LET foo = 2; (*)
> -- foo has value 2
> ROLLBACK;
> -- foo has value 1 back, change (*) has been reverted
>
> Now, when I am thinking about it, the @b is simple, but not too practical -
>> when some fails, then we lost a value (any transaction inside session can
>> fails).
>>
>
> Indeed.
>
> The @a has sense - the behave is global value (what is not possible
>> in Postgres now), but this value is destroyed by any unhandled exceptions,
>> and it cleaned on transaction end. The @b is just for information and for
>> discussion, but I'll remove it - because it is obscure.
>>
>
> Indeed.
>
> The open question is syntax. PostgreSQL has already ON COMMIT xxx . It is
>> little bit unclean, because it has semantic "on transaction end", but if I
>> didn't implement @b, then ON COMMIT syntax can be used.
>>
>
> I was more arguing on the third (c) option, i.e. on rollback the value is
> reverted to its value at the beginning of the rollbacked transaction.
>

> At the minimum, ISTM that option (b) is enough to implement the audit
> pattern, but it would mean that any session which has a rollback, for any
> reason (deadlock, serialization...), would have to be reinitialized, which
> would be a drawback.
>
> The to options could be non-transactional session variables "ON ROLLBACK
> DO NOT RESET/DO NOTHING", and somehow transactional session variables "ON
> ROLLBACK RESET TO DEFAULT" (b) or "ON ROLLBACK RESET TO INITIAL" (c).
>

@b is hardly understandable for not trained people, because any rollback in
session does reset. But people expecting @c, or some near @c.

I understand so you talked about @c. Now I think so it is possible to
implement, but it is not trivial. The transactional behave have to
calculate not only with transactions, but with SAVEPOINTS and ROLLBACK TO
savepoints. On second hand, the implementation will be relatively compact.

I'll hold it in my memory, but there are harder issues (support for
parallelism).

Regards

Pavel

> --
> Fabien.
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-14 21:31:16
Message-ID: CAFj8pRDREykg0hnMBkryBmSTtqEs9QUKUp_447_F5P1j8bkH1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

út 4. 9. 2018 v 9:21 odesílatel Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
napsal:

> AFAICS this patch does nothing to consider parallel safety -- that is,
> as things stand, a variable is allowed in a query that may be
> parallelised, but its value is not copied to workers, leading to
> incorrect results. For example:
>
> create table foo(a int);
> insert into foo select * from generate_series(1,1000000);
> create variable zero int;
> let zero = 0;
>
> explain (costs off) select count(*) from foo where a%10 = zero;
>
> QUERY PLAN
> -----------------------------------------------
> Finalize Aggregate
> -> Gather
> Workers Planned: 2
> -> Partial Aggregate
> -> Parallel Seq Scan on foo
> Filter: ((a % 10) = zero)
> (6 rows)
>
> select count(*) from foo where a%10 = zero;
>
> count
> -------
> 38037 -- Different random result each time, should be 100,000
> (1 row)
>
> Thoughts?
>

This issue should be fixed in attached patch (and more others).

The code is more cleaner now, there are more tests, and documentation is
mostly complete. I am sorry - my English is not good.
New features:

o ON COMMIT DROP and ON TRANSACTION END RESET -- remove temp variable on
commit, reset variable on transaction end (commit, rollback)
o LET var = DEFAULT -- reset specified variable

Regards

Pavel

> Regards,
> Dean
>

Attachment Content-Type Size
schema-variables-20180914-01.patch text/x-patch 235.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-15 16:06:59
Message-ID: CAFj8pRBkPswn0JA8U3vFOdBGqcBu0ZM7jC7JcDdCS1EbZfzb2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> The code is more cleaner now, there are more tests, and documentation is
> mostly complete. I am sorry - my English is not good.
> New features:
>
> o ON COMMIT DROP and ON TRANSACTION END RESET -- remove temp variable on
> commit, reset variable on transaction end (commit, rollback)
> o LET var = DEFAULT -- reset specified variable
>
>
fix some forgotten warnings and dependency issue
few more tests

Regards

Pavel

> Regards
>
> Pavel
>
>
>> Regards,
>> Dean
>>
>

Attachment Content-Type Size
schema-variables-20180915-01.patch.gz application/gzip 60.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-17 19:46:01
Message-ID: CAFj8pRAi2Xd93ae-SsnMOC5W4hWenmkftTnCrHgdcPpvbOs1bg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 15. 9. 2018 v 18:06 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
>
>
>> The code is more cleaner now, there are more tests, and documentation is
>> mostly complete. I am sorry - my English is not good.
>> New features:
>>
>> o ON COMMIT DROP and ON TRANSACTION END RESET -- remove temp variable on
>> commit, reset variable on transaction end (commit, rollback)
>> o LET var = DEFAULT -- reset specified variable
>>
>>
> fix some forgotten warnings and dependency issue
> few more tests
>
>
new update:

o support NOT NULL check
o implementation limited transaction variables - these variables doesn't
respects subtransactions(this is much more complex), drop variable drops
content although the drop can be reverted (maybe this limit will be
removed).

CREATE TRANSACTION VARIABLE fx AS int;

LET fx = 10;
BEGIN
LET fx = 20;
ROLLBACK;

SELECT fx;

Regards

Pavel

> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>>
>>> Regards,
>>> Dean
>>>
>>

Attachment Content-Type Size
schema-variables-20180917-01.patch.gz application/gzip 63.0 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-19 08:30:31
Message-ID: CAFj8pRCZuq=0MRsYrNzBqxPx5fqmKFN3i-BsPo8j=yW6N_=WDA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

new update:

I fixed pg_restore, and I cleaned a code related to transaction processing

There should be a full functionality now.

Regards

Pavel

Attachment Content-Type Size
schema-variables-20180919-01.patch.gz application/gzip 64.3 KB

From: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-19 11:23:06
Message-ID: 20180919112305.GA18604@zakirov.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hello,

On Wed, Sep 19, 2018 at 10:30:31AM +0200, Pavel Stehule wrote:
> Hi
>
> new update:
>
> I fixed pg_restore, and I cleaned a code related to transaction processing
>
> There should be a full functionality now.

I reviewed a little bit the patch. I have a few comments.

> <title><structname>pg_views</structname> Columns</title>

I think there is a typo here. It should be "pg_variable".

> GRANT { READ | WRITE | ALL [ PRIVILEGES ] }

Shouldn't we use here GRANT { SELECT | LET | ... } syntax for the
constistency. Same for REVOKE. I'm not experienced syntax developer
though. But we use SELECT and LET commands when working with variables.
So we should GRANT and REVOKE priveleges for this commands.

> [ { ON COMMIT DROP | ON TRANSACTION END RESET } ]

I think we may join them and have the syntax { ON COMMIT DROP | RESET }
to get more simpler syntax. If we create a variable with ON COMMIT
DROP, PostgreSQL will drop it regardless of whether transaction was
committed or rollbacked:

=# ...
=# begin;
=# create variable int1 int on commit drop;
=# rollback;
=# -- There is no variable int1

CREATE TABLE syntax has similar options [1]. ON COMMIT controls
the behaviour of temporary tables at the end a transaction block,
whether it was committed or rollbacked. But I'm not sure is this a good
example of precedence.

> - ONCOMMIT_DROP /* ON COMMIT DROP */
> + ONCOMMIT_DROP, /* ON COMMIT DROP */
> } OnCommitAction;

There is the extra comma here after ONCOMMIT_DROP.

1 - https://www.postgresql.org/docs/current/static/sql-createtable.html

--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-19 12:08:04
Message-ID: CAFj8pRA-yGAedtHeS4fDzWsJR1WqVu3TXABpF+XYrQE5fd0Dog@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi
st 19. 9. 2018 v 13:23 odesílatel Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
napsal:

> Hello,
>
> On Wed, Sep 19, 2018 at 10:30:31AM +0200, Pavel Stehule wrote:
> > Hi
> >
> > new update:
> >
> > I fixed pg_restore, and I cleaned a code related to transaction
> processing
> >
> > There should be a full functionality now.
>
> I reviewed a little bit the patch. I have a few comments.
>
> > <title><structname>pg_views</structname> Columns</title>
>
> I think there is a typo here. It should be "pg_variable".
>

I'll fix it.

>
> > GRANT { READ | WRITE | ALL [ PRIVILEGES ] }
>
> Shouldn't we use here GRANT { SELECT | LET | ... } syntax for the
> constistency. Same for REVOKE. I'm not experienced syntax developer
> though. But we use SELECT and LET commands when working with variables.
> So we should GRANT and REVOKE priveleges for this commands.
>

I understand to your proposal, - and I have not strong opinion. Originally
I proposed {SELECT|UPDATE), but some people prefer {READ|WRITE}. Now I
prefer Peter's proposal (what is implemented now) - READ|WRITE, because it
is very illustrative - and the mentioned difference is good because the
variables are not tables (by default), are not persistent, so different
rights are good for me. I see "GRANT LET" like very low clear, because
nobody knows what LET command does. Unfortunately we cannot to use standard
"SET" command, because it is used in Postgres for different purpose.
READ|WRITE are totally clear, and for user it is another signal so
variables are different than tables (so it is not one row table).

I prefer current state, but if common opinion will be different, I have not
problem to change it.

> > [ { ON COMMIT DROP | ON TRANSACTION END RESET } ]
>
> I think we may join them and have the syntax { ON COMMIT DROP | RESET }
> to get more simpler syntax. If we create a variable with ON COMMIT
> DROP, PostgreSQL will drop it regardless of whether transaction was
> committed or rollbacked:
>

I though about it too. I'll try to explain my idea. Originally I was
surprised so postgres uses "ON COMMIT" syntax, but in documentation is used
term "at transaction end". But it has some sense. ON COMMIT DROP is allowed
only for temporary tables and ON COMMIT DELETE ROWS is allowed for tables.
With these clauses the PostgreSQL is more aggressive in cleaning. It
doesn't need to calculate with rollback, because the rollback does cleaning
by self. So syntax "ON COMMIT" is fully correct it is related only for
commit event. It has not sense on rollback event (and doesn't change a
behave on rollback event).

The content of variables is not transactional (by default). It is not
destroyed by rollback. So I have to calculate with rollback too. So the
most correct syntax should be "ON COMMIT ON ROLLBACK RESET" what is little
bit messy and I used "ON TRANSACTION END". It should be signal, so this
event is effective on rollback event and it is valid for not transaction
variable. This logic is not valid to transactional variables, where ON
COMMIT RESET has sense. But this behave is not default and then I prefer
more generic syntax.

Again I have not a problem to change it, but I am thinking so current
design is logically correct.

> =# ...
> =# begin;
> =# create variable int1 int on commit drop;
> =# rollback;
> =# -- There is no variable int1
>
>
PostgreSQL catalog is transactional (where the metadata is stored), so when
I am working with metadata, then I use ON COMMIT syntax, because the behave
of ON ROLLBACK cannot be changed.

So I see two different cases - work with catalog (what is transactional)
and work with variable value, what is (like other variables in programming
languages) not transactional. "ON TRANSACTION END RESET" means - does reset
on any transaction end.

I hope so I explained it cleanly - if not, please, ask.

CREATE TABLE syntax has similar options [1]. ON COMMIT controls
> the behaviour of temporary tables at the end a transaction block,
> whether it was committed or rollbacked. But I'm not sure is this a good
> example of precedence.
>
> > - ONCOMMIT_DROP /* ON COMMIT DROP */
> > + ONCOMMIT_DROP, /* ON COMMIT DROP */
> > } OnCommitAction;
>
> There is the extra comma here after ONCOMMIT_DROP.
>

I'll fix it.

Regards

Pavel

>
> 1 - https://www.postgresql.org/docs/current/static/sql-createtable.html
>
> --
> Arthur Zakirov
> Postgres Professional: http://www.postgrespro.com
> Russian Postgres Company
>


From: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-19 12:53:25
Message-ID: 20180919125324.GA31127@zakirov.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Wed, Sep 19, 2018 at 02:08:04PM +0200, Pavel Stehule wrote:
> Unfortunately we cannot to use standard
> "SET" command, because it is used in Postgres for different purpose.
> READ|WRITE are totally clear, and for user it is another signal so
> variables are different than tables (so it is not one row table).
>
> I prefer current state, but if common opinion will be different, I have not
> problem to change it.

I see. I grepped the thread before writhing this but somehow missed the
discussion.

> The content of variables is not transactional (by default). It is not
> destroyed by rollback. So I have to calculate with rollback too. So the
> most correct syntax should be "ON COMMIT ON ROLLBACK RESET" what is little
> bit messy and I used "ON TRANSACTION END". It should be signal, so this
> event is effective on rollback event and it is valid for not transaction
> variable. This logic is not valid to transactional variables, where ON
> COMMIT RESET has sense. But this behave is not default and then I prefer
> more generic syntax.
> ...
> So I see two different cases - work with catalog (what is transactional)
> and work with variable value, what is (like other variables in programming
> languages) not transactional. "ON TRANSACTION END RESET" means - does reset
> on any transaction end.
>
> I hope so I explained it cleanly - if not, please, ask.

I understood what you mean, thank you. I thought that
{ ON COMMIT DROP | ON TRANSACTION END RESET } parameters are used only
for transactional variables in the first place. But is there any sense
in using this parameters with non-transactional variables? That is when
we create non-transactional variable we don't want that the variable
will rollback or reset its value after the end of a transaction.

--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-19 14:36:40
Message-ID: CAFj8pRAHgzY-_F9NWSziWKParY4_wx7-ZuypuQ=CAjkQB+2zyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 19. 9. 2018 v 14:53 odesílatel Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
napsal:

> On Wed, Sep 19, 2018 at 02:08:04PM +0200, Pavel Stehule wrote:
> > Unfortunately we cannot to use standard
> > "SET" command, because it is used in Postgres for different purpose.
> > READ|WRITE are totally clear, and for user it is another signal so
> > variables are different than tables (so it is not one row table).
> >
> > I prefer current state, but if common opinion will be different, I have
> not
> > problem to change it.
>
> I see. I grepped the thread before writhing this but somehow missed the
> discussion.
>
> > The content of variables is not transactional (by default). It is not
> > destroyed by rollback. So I have to calculate with rollback too. So the
> > most correct syntax should be "ON COMMIT ON ROLLBACK RESET" what is
> little
> > bit messy and I used "ON TRANSACTION END". It should be signal, so this
> > event is effective on rollback event and it is valid for not transaction
> > variable. This logic is not valid to transactional variables, where ON
> > COMMIT RESET has sense. But this behave is not default and then I prefer
> > more generic syntax.
> > ...
> > So I see two different cases - work with catalog (what is transactional)
> > and work with variable value, what is (like other variables in
> programming
> > languages) not transactional. "ON TRANSACTION END RESET" means - does
> reset
> > on any transaction end.
> >
> > I hope so I explained it cleanly - if not, please, ask.
>
> I understood what you mean, thank you. I thought that
> { ON COMMIT DROP | ON TRANSACTION END RESET } parameters are used only
> for transactional variables in the first place. But is there any sense
> in using this parameters with non-transactional variables? That is when
> we create non-transactional variable we don't want that the variable
> will rollback or reset its value after the end of a transaction.
>

ON COMMIT DROP is used only for temp variables (transaction or not
transaction). The purpose is same like for tables. Sometimes you can to
have object with shorter life than is session.

ON TRANSACTION END RESET has sense mainly for not transaction variables. I
see two use cases.

1. protect some sensitive data - on transaction end guaranteed reset and
cleaning on end transaction. So you can be sure, so variable is not
initialized (has default value), or you are inside transaction.

2. automatic initialization - ON TRANSACTION END RESET ensure so variable
is in init state for any transaction.

Both cases has sense for transaction or not transaction variables.

I am thinking so transaction life time for content has sense. Is cheaper to
reset variable than drop it (what ON COMMIT DROP does)

What do you think?

Pavel

> --
> Arthur Zakirov
> Postgres Professional: http://www.postgrespro.com
> Russian Postgres Company
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-20 09:08:57
Message-ID: CAFj8pRCO+S9JVi+8L8MT7pcpz2+-orj5ju8k=e+PqZBhdYPhXg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

st 19. 9. 2018 v 13:23 odesílatel Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
napsal:

> Hello,
>
> On Wed, Sep 19, 2018 at 10:30:31AM +0200, Pavel Stehule wrote:
> > Hi
> >
> > new update:
> >
> > I fixed pg_restore, and I cleaned a code related to transaction
> processing
> >
> > There should be a full functionality now.
>
> I reviewed a little bit the patch. I have a few comments.
>
> > <title><structname>pg_views</structname> Columns</title>
>
> I think there is a typo here. It should be "pg_variable".
>

fixed

> > - ONCOMMIT_DROP /* ON COMMIT DROP */
> > + ONCOMMIT_DROP, /* ON COMMIT DROP */
> > } OnCommitAction;
>
> There is the extra comma here after ONCOMMIT_DROP.
>

fixed

Thank you for comments

attached updated patch

> 1 - https://www.postgresql.org/docs/current/static/sql-createtable.html
>
> --
> Arthur Zakirov
> Postgres Professional: http://www.postgrespro.com
> Russian Postgres Company
>

Attachment Content-Type Size
schema-variables-20180920-01.patch.gz application/gzip 64.5 KB

From: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-21 19:46:18
Message-ID: 20180921194617.GA8051@artur-book.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Wed, Sep 19, 2018 at 04:36:40PM +0200, Pavel Stehule wrote:
> ON COMMIT DROP is used only for temp variables (transaction or not
> transaction). The purpose is same like for tables. Sometimes you can to
> have object with shorter life than is session.
>
> ON TRANSACTION END RESET has sense mainly for not transaction variables. I
> see two use cases.
>
> 1. protect some sensitive data - on transaction end guaranteed reset and
> cleaning on end transaction. So you can be sure, so variable is not
> initialized (has default value), or you are inside transaction.
>
> 2. automatic initialization - ON TRANSACTION END RESET ensure so variable
> is in init state for any transaction.
>
> Both cases has sense for transaction or not transaction variables.
>
> I am thinking so transaction life time for content has sense. Is cheaper to
> reset variable than drop it (what ON COMMIT DROP does)
>
> What do you think?

Thanks, I understood the cases.

But I think there is more sense to use these options only with transactional
variables. It is more consistent and simple for me.

As a summary, it is 1 voice vs 1 voice :) So it is better to leave the
syntax as is without changes for now.

--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-22 03:35:45
Message-ID: CAFj8pRAKvrxuoGMLDmz8GCKcLkcekgb0+rStm4qezn65--H3eQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 21. 9. 2018 v 21:46 odesílatel Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
napsal:

> On Wed, Sep 19, 2018 at 04:36:40PM +0200, Pavel Stehule wrote:
> > ON COMMIT DROP is used only for temp variables (transaction or not
> > transaction). The purpose is same like for tables. Sometimes you can to
> > have object with shorter life than is session.
> >
> > ON TRANSACTION END RESET has sense mainly for not transaction variables.
> I
> > see two use cases.
> >
> > 1. protect some sensitive data - on transaction end guaranteed reset and
> > cleaning on end transaction. So you can be sure, so variable is not
> > initialized (has default value), or you are inside transaction.
> >
> > 2. automatic initialization - ON TRANSACTION END RESET ensure so variable
> > is in init state for any transaction.
> >
> > Both cases has sense for transaction or not transaction variables.
> >
> > I am thinking so transaction life time for content has sense. Is cheaper
> to
> > reset variable than drop it (what ON COMMIT DROP does)
> >
> > What do you think?
>
> Thanks, I understood the cases.
>
> But I think there is more sense to use these options only with
> transactional
> variables. It is more consistent and simple for me.
>

I agree so it can be hard to imagine - and if I return back to start
discussion about schema variables - it can be hard because it joins some
concepts - variables has persistent transactional metadata, but the content
is not transactional.

I don't think so the variability is a issue in this case. There is a lot of
examples, so lot of combinations are possible - global temp tables and
package variables (Oracle), local temp tables and local variables
(Postgres), session variables and memory tables (MSSQL). Any combination of
feature has cases where can be very practical and useful.

ON TRANSACTION END RESET can be useful, because we have not a session event
triggers (and in this moment I am not sure if it is necessary and practical
- their usage can be very fragile). But some work can do ON xxx clauses,
that should not to have negative impact on performance or fragility.

ON TRANSACTION END RESET ensure cleaned and initialized to default value
for any transaction. Other possibility is ON COMMAND END RESET (but I would
not to implement it now), ...

> As a summary, it is 1 voice vs 1 voice :) So it is better to leave the
> syntax as is without changes for now.
>

:) now is enough time to think about syntax. Some features can be removed
and returned back later, where this concept will be more absorbed.

Regards

Pavel

>
> --
> Arthur Zakirov
> Postgres Professional: http://www.postgrespro.com
> Russian Postgres Company
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-22 06:00:04
Message-ID: CAFj8pRCB7ZDgTWD2BLaiATFEg_VpVgqTGkJwwd4t1hMTZ=4W=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebased against yesterday changes in tab-complete.c

Regards

Pavel

Attachment Content-Type Size
schema-variables-20180922-01.patch.gz application/gzip 64.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-29 08:34:40
Message-ID: CAFj8pRAc_=XEpS7csp0bozopsCwLc3z-C+_46RUYdPB7kxbNAw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 22. 9. 2018 v 8:00 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> rebased against yesterday changes in tab-complete.c
>

rebased against last changes in master

Regards

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20180929-01.patch.gz application/gzip 64.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-09-29 22:19:23
Message-ID: CAFj8pRBSTLxQXcGXruo3zRDBdk378gA+nsi9FM9SxhV1qa0iCw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 29. 9. 2018 v 10:34 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> so 22. 9. 2018 v 8:00 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> rebased against yesterday changes in tab-complete.c
>>
>
> rebased against last changes in master
>

+ using content of schema variable for estimation
+ subtransaction support

I hope so now, there are almost complete functionality. Please, check it.

Regards

Pavel

>
> Regards
>
> Pavel
>
>
>
>> Regards
>>
>> Pavel
>>
>

Attachment Content-Type Size
schema-variables-20180929-02.patch.gz application/gzip 65.7 KB

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, gilles(dot)darold(at)dalibo(dot)com, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-10-02 23:01:22
Message-ID: CAEepm=2Kpz6tUqzVn26OGVGCj+_q4qSVun25GDLO6+S8_eDrgg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sun, Sep 30, 2018 at 11:20 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> I hope so now, there are almost complete functionality. Please, check it.

Hi Pavel,

FYI there is a regression test failure on Windows:

plpgsql ... FAILED

*** 4071,4077 ****
end;
$$ language plpgsql;
select stacked_diagnostics_test();
- NOTICE: sqlstate: 22012, message: division by zero, context:
[PL/pgSQL function zero_divide() line 4 at RETURN <- SQL statement
"SELECT zero_divide()" <- PL/pgSQL function stacked_diagnostics_test()
line 6 at PERFORM]
+ NOTICE: sqlstate: 42702, message: column reference "v" is ambiguous,
context: [PL/pgSQL function zero_divide() line 4 at RETURN <- SQL
statement "SELECT zero_divide()" <- PL/pgSQL function
stacked_diagnostics_test() line 6 at PERFORM]

https://ci.appveyor.com/project/postgresql-cfbot/postgresql/build/1.0.15234

--
Thomas Munro
http://www.enterprisedb.com


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-10-05 01:34:14
Message-ID: CAFj8pRCTbd2PrwcTd7hj-bctsVD1E5cpke_Z27k-vcgwGvLvLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 3. 10. 2018 v 1:01 odesílatel Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
napsal:

> On Sun, Sep 30, 2018 at 11:20 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> > I hope so now, there are almost complete functionality. Please, check it.
>
> Hi Pavel,
>
> FYI there is a regression test failure on Windows:
>
> plpgsql ... FAILED
>
> *** 4071,4077 ****
> end;
> $$ language plpgsql;
> select stacked_diagnostics_test();
> - NOTICE: sqlstate: 22012, message: division by zero, context:
> [PL/pgSQL function zero_divide() line 4 at RETURN <- SQL statement
> "SELECT zero_divide()" <- PL/pgSQL function stacked_diagnostics_test()
> line 6 at PERFORM]
> + NOTICE: sqlstate: 42702, message: column reference "v" is ambiguous,
> context: [PL/pgSQL function zero_divide() line 4 at RETURN <- SQL
> statement "SELECT zero_divide()" <- PL/pgSQL function
> stacked_diagnostics_test() line 6 at PERFORM]
>
> https://ci.appveyor.com/project/postgresql-cfbot/postgresql/build/1.0.15234

please, check attached patch

Thank you for report

Pavel

>
> --
> Thomas Munro
> http://www.enterprisedb.com
>

Attachment Content-Type Size
schema-variables-20181004-02.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-10-07 17:13:44
Message-ID: CAFj8pRAR03rRfAsbYpsP-NDq3npWZdiQoX9vkrX2HSuA9COuUg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 30. 9. 2018 v 0:19 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> so 29. 9. 2018 v 10:34 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>>
>>
>> so 22. 9. 2018 v 8:00 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> napsal:
>>
>>> Hi
>>>
>>> rebased against yesterday changes in tab-complete.c
>>>
>>
>> rebased against last changes in master
>>
>
> + using content of schema variable for estimation
> + subtransaction support
>
> I hope so now, there are almost complete functionality. Please, check it.
>

new update

minor white space issue
one more regress test and 2 pg_dump tests

Regards

Pavel

>
> Regards
>
> Pavel
>
>
>>
>> Regards
>>
>> Pavel
>>
>>
>>
>>> Regards
>>>
>>> Pavel
>>>
>>

Attachment Content-Type Size
schema-variables-20181007-01.patch.gz application/gzip 48.3 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-10-23 12:50:18
Message-ID: 49131cb01433f0b2343031c7cccbe98e@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> [schema-variables-20181007-01.patch.gz]

Hi,

I tried to test your schema-variables patch but got stuck here instead
(after applying succesfully on top of e6f5d1acc):

make[2]: *** No rule to make target
'../../../src/include/catalog/pg_variable.h', needed by 'bki-stamp'.
Stop.
make[1]: *** [submake-catalog-headers] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [submake-generated-headers] Error 2
Makefile:141: recipe for target 'submake-catalog-headers' failed
src/Makefile.global:370: recipe for target 'submake-generated-headers'
failed

thanks,

Erik Rijkers


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-10-23 18:05:07
Message-ID: CAFj8pRDhpHcU+DC0JHJrsTa__S87DZXqERVQkG+u8E0rzHpcgw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

út 23. 10. 2018 v 14:50 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> > [schema-variables-20181007-01.patch.gz]
>
> Hi,
>
> I tried to test your schema-variables patch but got stuck here instead
> (after applying succesfully on top of e6f5d1acc):
>
> make[2]: *** No rule to make target
> '../../../src/include/catalog/pg_variable.h', needed by 'bki-stamp'.
> Stop.
> make[1]: *** [submake-catalog-headers] Error 2
> make[1]: *** Waiting for unfinished jobs....
> make: *** [submake-generated-headers] Error 2
> Makefile:141: recipe for target 'submake-catalog-headers' failed
> src/Makefile.global:370: recipe for target 'submake-generated-headers'
> failed
>
>
Unfortunately previous patch was completely broken. I am sorry

Please, check this patch.

Regards

Pavel

> thanks,
>
> Erik Rijkers
>

Attachment Content-Type Size
schema-variables-20181023-01.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-11-21 07:24:50
Message-ID: CAFj8pRBrc6AULAT6e4cAbd86Y4qjTP9app=TsU15Hq=_2NNYfA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

just rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20181121-01.patch.gz application/gzip 65.8 KB

From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, dean(dot)a(dot)rasheed(at)gmail(dot)com, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, gilles(dot)darold(at)dalibo(dot)com, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-11-30 23:17:21
Message-ID: CA+q6zcUSMknVb7AMJMW1WaCCzqBH4FiZnpMiDriwer4Z_T84sA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> On Wed, Nov 21, 2018 at 8:25 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> just rebase

Thanks for working on this patch.

I'm a bit confused, but cfbot again says that there are some conflicts.
Probably they are the minor one, from src/bin/psql/help.c

For now I'm moving it to the next CF.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-12-01 06:32:41
Message-ID: CAFj8pRA27EuadmJP=Df-PdYxSJ_x5ySkaRHZzfbjY_Ph7Yc7CQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 1. 12. 2018 v 0:16 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Wed, Nov 21, 2018 at 8:25 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> >
> > just rebase
>
> Thanks for working on this patch.
>
> I'm a bit confused, but cfbot again says that there are some conflicts.
> Probably they are the minor one, from src/bin/psql/help.c
>

rebased again

Regards

Pavel

> For now I'm moving it to the next CF.
>

Attachment Content-Type Size
schema-variables-20181201-01.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-12-31 13:23:44
Message-ID: CAFj8pRAOB0UMA_FJy6dOHLSDEZDN6B9zV33LQFebSEgHQKBY4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 21. 11. 2018 v 8:24 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> just rebase
>
>
rebase

Regards

Pavel

>
> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20181231-01.patch.gz application/gzip 65.4 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-12-31 15:40:24
Message-ID: df879d16a6cf3f7b4bb6f56f036ea2fa@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2018-12-31 14:23, Pavel Stehule wrote:
> st 21. 11. 2018 v 8:24 odesílatel Pavel Stehule
> <pavel(dot)stehule(at)gmail(dot)com>

> [schema-variables-20181231-01.patch.gz]

Hi Pavel,

I gave this a quick try-out with the script I had from previous
versions,
and found these two errors:

------------
drop schema if exists schema1 cascade;
create schema if not exists schema1;
drop variable if exists schema1.myvar1; --> error 49
create variable schema1.myvar1 as text ;
select schema1.myvar1;
let schema1.myvar1 = 'variable value ""';
select schema1.myvar1;
alter variable schema1.myvar1 rename to myvar2;
select schema1.myvar2;
create variable schema1.myvar1 as text ;
let schema1.myvar1 = 'variable value ""';
select schema1.myvar1;
alter variable schema1.myvar1 rename to myvar2; --> error 4287
select schema1.myvar2;
------------

The above, ran with psql -qXa gives the following output:

drop schema if exists schema1 cascade;
create schema if not exists schema1;
drop variable if exists schema1.myvar1; --> error 49
ERROR: unrecognized object type: 49
create variable schema1.myvar1 as text ;
select schema1.myvar1;
myvar1
--------

(1 row)

let schema1.myvar1 = 'variable value ""';
select schema1.myvar1;
myvar1
-------------------
variable value ""
(1 row)

alter variable schema1.myvar1 rename to myvar2;
select schema1.myvar2;
myvar2
-------------------
variable value ""
(1 row)

create variable schema1.myvar1 as text ;
let schema1.myvar1 = 'variable value ""';
select schema1.myvar1;
myvar1
-------------------
variable value ""
(1 row)

alter variable schema1.myvar1 rename to myvar2; --> error 4287
ERROR: unsupported object class 4287
select schema1.myvar2;
myvar2
-------------------
variable value ""
(1 row)

thanks,

Erik Rijkers


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2018-12-31 17:33:30
Message-ID: CAFj8pRDxE1uSup-CLZScXd3=iH7JwK2C6VbV4vbjCyYaXU6PRg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 31. 12. 2018 v 16:40 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> On 2018-12-31 14:23, Pavel Stehule wrote:
> > st 21. 11. 2018 v 8:24 odesílatel Pavel Stehule
> > <pavel(dot)stehule(at)gmail(dot)com>
>
> > [schema-variables-20181231-01.patch.gz]
>
> Hi Pavel,
>
> I gave this a quick try-out with the script I had from previous
> versions,
> and found these two errors:
>
> ------------
> drop schema if exists schema1 cascade;
> create schema if not exists schema1;
> drop variable if exists schema1.myvar1; --> error 49
> create variable schema1.myvar1 as text ;
> select schema1.myvar1;
> let schema1.myvar1 = 'variable value ""';
> select schema1.myvar1;
> alter variable schema1.myvar1 rename to myvar2;
> select schema1.myvar2;
> create variable schema1.myvar1 as text ;
> let schema1.myvar1 = 'variable value ""';
> select schema1.myvar1;
> alter variable schema1.myvar1 rename to myvar2; --> error 4287
> select schema1.myvar2;
> ------------
>
>
> The above, ran with psql -qXa gives the following output:
>
> drop schema if exists schema1 cascade;
> create schema if not exists schema1;
> drop variable if exists schema1.myvar1; --> error 49
> ERROR: unrecognized object type: 49
> create variable schema1.myvar1 as text ;
> select schema1.myvar1;
> myvar1
> --------
>
> (1 row)
>
> let schema1.myvar1 = 'variable value ""';
> select schema1.myvar1;
> myvar1
> -------------------
> variable value ""
> (1 row)
>
> alter variable schema1.myvar1 rename to myvar2;
> select schema1.myvar2;
> myvar2
> -------------------
> variable value ""
> (1 row)
>
> create variable schema1.myvar1 as text ;
> let schema1.myvar1 = 'variable value ""';
> select schema1.myvar1;
> myvar1
> -------------------
> variable value ""
> (1 row)
>
> alter variable schema1.myvar1 rename to myvar2; --> error 4287
> ERROR: unsupported object class 4287
> select schema1.myvar2;
> myvar2
> -------------------
> variable value ""
> (1 row)
>
>
Should be fixed now.

Thank you for report

Pavel

>
> thanks,
>
>
> Erik Rijkers
>
>
>

Attachment Content-Type Size
schema-variables-20181231-02.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-01-22 19:32:46
Message-ID: CAFj8pRCiGW4vF+RZrTC87-44_xf7zALZedQArA0=S7U_dh2qjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebased patch, no other changes

Pavel

Attachment Content-Type Size
schema-variables-20190122-01.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-01-30 16:34:24
Message-ID: CAFj8pRC9Xi=C4BXEXLMw_ba8AQZEs4a2ZGMOg6kpwMeo-wXrAg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

just rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20190130.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-01-31 11:49:27
Message-ID: CAFj8pRAG_u19iL98Pt7Qidqoq-mfKhof6gK4kOT_EBvqnHdrOg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

just rebase

regards

Pavel

Attachment Content-Type Size
schema-variables-20190131.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-03 20:27:13
Message-ID: CAFj8pRBQuKANoiQpUf5eSqummJ2v33UOePcaM7PTHCd9Szk1xg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

čt 31. 1. 2019 v 12:49 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> just rebase
>
> regards
>
> Pavel
>

rebase and fix compilation due changes related pg_dump

Regards

Pavel

Attachment Content-Type Size
schema-variables-20190303.patch.gz application/gzip 66.1 KB

From: David Steele <david(at)pgmasters(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: Re: [HACKERS] proposal: schema variables
Date: 2019-03-07 06:52:16
Message-ID: b4791174-5a8a-f5ca-9641-2533c3424caf@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 3/3/19 10:27 PM, Pavel Stehule wrote:
>
> rebase and fix compilation due changes related pg_dump

This patch hasn't receive any review in a while and I'm not sure if
that's because nobody is interested or the reviewers think it does not
need any more review.

It seems to me that this patch as implemented does not quite satisfy any
one.

I think we need to hear something from the reviewers soon or I'll push
this patch to PG13 as Andres recommends [1].

--
-David
david(at)pgmasters(dot)net

[1]
https://www.postgresql.org/message-id/20190216054526.zss2cufdxfeudr4i%40alap3.anarazel.de


From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: David Steele <david(at)pgmasters(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: Re: [HACKERS] proposal: schema variables
Date: 2019-03-07 08:10:47
Message-ID: alpine.DEB.2.21.1903070853110.30581@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


Hello David,

> This patch hasn't receive any review in a while and I'm not sure if that's
> because nobody is interested or the reviewers think it does not need any more
> review.
>
> It seems to me that this patch as implemented does not quite satisfy any one.
>
> I think we need to hear something from the reviewers soon or I'll push this
> patch to PG13 as Andres recommends [1].

I have discussed the feature extensively with Pavel on the initial thread.

My strong opinion based on the underlying use case is that it that such
session variables should be transactional by default, and Pavel strong
opinion is that they should not, to be closer to Oracle comparable
feature.

According to the documentation, the current implementation does provide a
transactional feature. However, it is not the default behavior, so I'm in
disagreement on a key feature, although I do really appreciate that Pavel
implemented the transactional behavior.

Otherwise, ISTM that they could be named "SESSION VARIABLE" because the
variable only exists in memory, in a session, and we could thing of adding
other kind of variables later on.

I do intend to review it in depth when it is transactional by default.

Anyway, the patch is non trivial and very large, so targetting v12 now is
indeed out of reach.

--
Fabien.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: David Steele <david(at)pgmasters(dot)net>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: Re: [HACKERS] proposal: schema variables
Date: 2019-03-07 08:32:25
Message-ID: CAFj8pRAnq0X_8aw7dCO02JcYcwwYYuNDZGi9JpKKLcxVCH3D+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 7. 3. 2019 v 9:10 odesílatel Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> napsal:

>
> Hello David,
>
> > This patch hasn't receive any review in a while and I'm not sure if
> that's
> > because nobody is interested or the reviewers think it does not need any
> more
> > review.
> >
> > It seems to me that this patch as implemented does not quite satisfy any
> one.
> >
> > I think we need to hear something from the reviewers soon or I'll push
> this
> > patch to PG13 as Andres recommends [1].
>
> I have discussed the feature extensively with Pavel on the initial thread.
>
> My strong opinion based on the underlying use case is that it that such
> session variables should be transactional by default, and Pavel strong
> opinion is that they should not, to be closer to Oracle comparable
> feature.
>
> According to the documentation, the current implementation does provide a
> transactional feature. However, it is not the default behavior, so I'm in
> disagreement on a key feature, although I do really appreciate that Pavel
> implemented the transactional behavior.
>
> Otherwise, ISTM that they could be named "SESSION VARIABLE" because the
> variable only exists in memory, in a session, and we could thing of adding
> other kind of variables later on.
>
> I do intend to review it in depth when it is transactional by default.
>

I am sorry. I cannot to support this request. Variables are not
transactional. My opinion is strong in this part.

I would not to repeat this discussion from start. I am sorry.

Regards

Pavel

> Anyway, the patch is non trivial and very large, so targetting v12 now is
> indeed out of reach.
>
> --
> Fabien.
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: David Steele <david(at)pgmasters(dot)net>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: Re: [HACKERS] proposal: schema variables
Date: 2019-03-07 08:37:58
Message-ID: CAFj8pRAy7qAbtQ9bnMCsDjRZR2T7c-XzQRsOtnngaaZRfG2wkQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

>> My strong opinion based on the underlying use case is that it that such
>> session variables should be transactional by default, and Pavel strong
>> opinion is that they should not, to be closer to Oracle comparable
>> feature.
>
>
It is closer to any known database Oracle, DB2, Firebird, MSSQL, MySQL,

Regards

Pavel


From: David Steele <david(at)pgmasters(dot)net>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-07 09:26:06
Message-ID: 40a63d9f-acb7-d32c-1528-fc699bc1bdd1@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 3/7/19 10:10 AM, Fabien COELHO wrote:
>
> Anyway, the patch is non trivial and very large, so targetting v12 now
> is indeed out of reach.

Agreed. I have set the target version to PG13.

Regards,
--
-David
david(at)pgmasters(dot)net


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-24 05:57:10
Message-ID: CAFj8pRA=9H4ve18H_hqS0OqnBQaxeA7ssP67pOkH86Ax53wU4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase against current master

Regards

Pavel

Attachment Content-Type Size
schema-variables-20190324.patch.gz application/gzip 66.1 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-24 09:25:38
Message-ID: f138cb3d1a536869b1e6f92949065828@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2019-03-24 06:57, Pavel Stehule wrote:
> Hi
>
> rebase against current master
>

I ran into this:

(schema 'varschema2' does not exist):

drop variable varschema2.testv cascade;
ERROR: schema "varschema2" does not exist
create variable if not exists testv as text;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost

(both statements are needed to force the crash)

thanks,

Erik Rijkers


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-24 09:32:53
Message-ID: CAFj8pRA=75-F1HvQhrEFme9RjOKnDjfqGLGg54AnxL53Q4hU=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 24. 3. 2019 v 10:25 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> On 2019-03-24 06:57, Pavel Stehule wrote:
> > Hi
> >
> > rebase against current master
> >
>
> I ran into this:
>
> (schema 'varschema2' does not exist):
>
> drop variable varschema2.testv cascade;
> ERROR: schema "varschema2" does not exist
> create variable if not exists testv as text;
> server closed the connection unexpectedly
> This probably means the server terminated abnormally
> before or while processing the request.
> connection to server was lost
>
>
> (both statements are needed to force the crash)
>

I cannot to reproduce it.

please, try compilation with "make distclean"; configure ..

or if the problem persists, please send test case, or backtrace

Regards

Pavel

>
>
> thanks,
>
> Erik Rijkers
>
>
>


From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-25 19:40:15
Message-ID: e307a007d8e8be8cc9df6fd26c597675@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2019-03-24 10:32, Pavel Stehule wrote:
> ne 24. 3. 2019 v 10:25 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:
>
>> On 2019-03-24 06:57, Pavel Stehule wrote:
>> > Hi
>> >
>> > rebase against current master
>>
>> I ran into this:
>>
>> (schema 'varschema2' does not exist):
>>
>> drop variable varschema2.testv cascade;
>> ERROR: schema "varschema2" does not exist
>> create variable if not exists testv as text;
>> server closed the connection unexpectedly
>> This probably means the server terminated abnormally
>> before or while processing the request.
>> connection to server was lost
>>
>>
>> (both statements are needed to force the crash)
>>
>
> I cannot to reproduce it.
> [backtrace and stuff]

Sorry, I don't have the wherewithal to get more info but I have repeated
this now on 4 different machines (debian jessie/stretch; centos).

I did notice that sometimes those two offending lines
"
drop variable varschema2.testv cascade;
create variable if not exists testv as text;
"
have to be repeated a few times (never more than 4 or 5 times) before
the crash occurs (signal 11: Segmentation fault).

Erik Rijkers


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-26 05:40:22
Message-ID: CAFj8pRCq6+pFzZ7XvkF=o8D7E3R4UO5H=foKPvhyAzv_K4dADQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 24. 3. 2019 v 6:57 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> rebase against current master
>

fixed issue IF NOT EXISTS & related regress tests

Regards

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20190326.patch.gz application/gzip 66.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-03-26 05:41:04
Message-ID: CAFj8pRA2raGgNAsZZPQYkXVS_vN3KLktvNk61fzDqhmLm7Au2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 25. 3. 2019 v 20:40 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> On 2019-03-24 10:32, Pavel Stehule wrote:
> > ne 24. 3. 2019 v 10:25 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:
> >
> >> On 2019-03-24 06:57, Pavel Stehule wrote:
> >> > Hi
> >> >
> >> > rebase against current master
> >>
> >> I ran into this:
> >>
> >> (schema 'varschema2' does not exist):
> >>
> >> drop variable varschema2.testv cascade;
> >> ERROR: schema "varschema2" does not exist
> >> create variable if not exists testv as text;
> >> server closed the connection unexpectedly
> >> This probably means the server terminated abnormally
> >> before or while processing the request.
> >> connection to server was lost
> >>
> >>
> >> (both statements are needed to force the crash)
> >>
> >
> > I cannot to reproduce it.
> > [backtrace and stuff]
>
> Sorry, I don't have the wherewithal to get more info but I have repeated
> this now on 4 different machines (debian jessie/stretch; centos).
>
> I did notice that sometimes those two offending lines
> "
> drop variable varschema2.testv cascade;
> create variable if not exists testv as text;
> "
> have to be repeated a few times (never more than 4 or 5 times) before
> the crash occurs (signal 11: Segmentation fault).
>

Should be fixed now.

Thank you for report

Pavel

>
> Erik Rijkers
>
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-04-02 18:02:12
Message-ID: CAFj8pRB0yi6sZTfB8ODaDWkzriuiSFJvfFn9dKmCHzPsK3bu+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

út 26. 3. 2019 v 6:40 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> ne 24. 3. 2019 v 6:57 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> rebase against current master
>>
>
>
> fixed issue IF NOT EXISTS & related regress tests
>

another rebase

Regards

Pavel

> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>

Attachment Content-Type Size
schema-variables-20190402.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-04-19 06:32:25
Message-ID: CAFj8pRCPYCYZPrS3seNaCXKTmCaxhR=DNPQsBHynBMY3x4WwGg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

fresh rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20180419.patch.gz application/gzip 66.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-05-09 04:34:20
Message-ID: CAFj8pRD__tbzmkr458vgJb2EhVoLk7_r3o8o6qznJiDut2L7kg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebased patch

Regards

Pavel

Attachment Content-Type Size
schema-variables-20190509.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-05-24 17:12:13
Message-ID: CAFj8pRDNGq2gUzRKZgia6javnjEQhzbQX4i-n+A=pP1JnH0evQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

čt 9. 5. 2019 v 6:34 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> rebased patch
>

rebase after pgindent

Regards

Pavel

>
> Regards
>
> Pavel
>
>
>

Attachment Content-Type Size
schema-variables-20190524.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-06-30 03:10:08
Message-ID: CAFj8pRDog1b+66-8ZW0_7JmKr_hbu1fs+CKrEkfS+RU=ZJNdGw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 24. 5. 2019 v 19:12 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> čt 9. 5. 2019 v 6:34 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> rebased patch
>>
>
> rebase after pgindent
>

fresh rebase

Regards

Pavel

> Regards
>
> Pavel
>
>>
>> Regards
>>
>> Pavel
>>
>>
>>

Attachment Content-Type Size
schema-variables-20190630.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-07-16 12:50:49
Message-ID: CAFj8pRBrMMQAacfEzS5t0FE8ruNzDRvFAYiJgTsGwwR6NXygcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 30. 6. 2019 v 5:10 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> pá 24. 5. 2019 v 19:12 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> čt 9. 5. 2019 v 6:34 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> napsal:
>>
>>> Hi
>>>
>>> rebased patch
>>>
>>
>> rebase after pgindent
>>
>
> fresh rebase
>

just rebase again

Regards

Pavel

> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>>>
>>> Regards
>>>
>>> Pavel
>>>
>>>
>>>

Attachment Content-Type Size
schema-variables-20190716.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-08-10 07:10:14
Message-ID: CAFj8pRBmsqOHWJOFx5WSmopHVzTMsp8oRYN5EKnP+5kHBGXekg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

just rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-rebase-20190810.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-10-04 04:12:41
Message-ID: CAFj8pRA9tK92h8bkaN_S-R1ZuayGfwSzDCpLdzbMRCLZwF_xJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

so 10. 8. 2019 v 9:10 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> just rebase
>

fresh rebase

Regards

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20191004.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-10-10 09:41:10
Message-ID: CAFj8pRA5hjcwvjD0LB3d6d16O0WQKxwg9633XeTeEvsLj-8YUw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

minor change - replace heap_tuple_fetch_attr by detoast_external_attr.

Regards

Pavel

pá 4. 10. 2019 v 6:12 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> so 10. 8. 2019 v 9:10 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> just rebase
>>
>
> fresh rebase
>
> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>

Attachment Content-Type Size
schema_variables-20191010.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-11-03 16:27:17
Message-ID: CAFj8pRBaAju_Ki3ENZXK=KqOGgo69ZT=hFSG6=Vd8=eaAHcn6A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 10. 10. 2019 v 11:41 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> minor change - replace heap_tuple_fetch_attr by detoast_external_attr.
>
>
similar update - heap_open, heap_close was replaced by table_open,
table_close

Regards

Pavel

Attachment Content-Type Size
schema_variables-20191103.patch.gz application/gzip 65.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-11-18 18:47:58
Message-ID: CAFj8pRCneJ6iEGyrDtCX=MrqNVLXcSxJwnrqWxuyVTEFMqeYSQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 3. 11. 2019 v 17:27 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 10. 10. 2019 v 11:41 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> minor change - replace heap_tuple_fetch_attr by detoast_external_attr.
>>
>>
> similar update - heap_open, heap_close was replaced by table_open,
> table_close
>

fresh rebase

Regards

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20191118.patch.gz application/gzip 65.5 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: Re: [HACKERS] proposal: schema variables
Date: 2019-12-14 21:43:38
Message-ID: CAFj8pRBNqJ0_mHSFW0ksR90f0eKzk+zABboZ1tmoH6q4T8m0nA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 18. 11. 2019 v 19:47 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> ne 3. 11. 2019 v 17:27 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>>
>>
>> čt 10. 10. 2019 v 11:41 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> napsal:
>>
>>> Hi
>>>
>>> minor change - replace heap_tuple_fetch_attr by detoast_external_attr.
>>>
>>>
>> similar update - heap_open, heap_close was replaced by table_open,
>> table_close
>>
>
> fresh rebase
>

only rebase

Regards

Pavel

> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>

Attachment Content-Type Size
schema-variables-20191214.patch.gz application/gzip 65.5 KB

From: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal: schema variables
Date: 2019-12-22 12:03:10
Message-ID: 157701619041.1198.10146593618667092522.pgcf@coridan.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, failed
Spec compliant: not tested
Documentation: tested, failed

Hi Pavel,

First of all, I would like to congratulate you for this great work. This patch is really cool. The lack of package variables is sometimes a blocking issue for Oracle to Postgres migrations, because the usual emulation with GUC is sometimes not enough, in particular when there are security concerns or when the database is used in a public cloud.

As I look forward to having this patch commited, I decided to spend some time to participate to the review, although I am not a C specialist and I have not a good knowledge of the Postgres internals. Here is my report.

A) Installation

The patch applies correctly and the compilation is fine. The "make check" doesn't report any issue.

B) Basic usage

I tried some simple schema variables use cases. No problem.

C) The interface

The SQL changes look good to me.

However, in the CREATE VARIABLE command, I would replace the "TRANSACTION" word by "TRANSACTIONAL".

I have also tried to replace this word by a ON ROLLBACK clause at the end of the statement, like for ON COMMIT, but I have not found a satisfying wording to propose.

D) Behaviour

I am ok with variables not being transactional by default. That's the most simple, the most efficient, it emulates the package variables of other RDBMS and it will probably fit the most common use cases.

Note that I am not strongly opposed to having by default transactional variables. But I don't know whether this change would be a great work. We would have at least to find another keyword in the CREATE VARIABLE statement. Something like "NON-TRANSACTIONAL VARIABLE" ?

It is possible to create a NOT NULL variable without DEFAULT. When trying to read the variable before a LET statement, one gets an error massage saying that the NULL value is not allowed (and the documentation is clear about this case). Just for the records, I wondered whether it wouldn't be better to forbid a NOT NULL variable creation that wouldn't have a DEFAULT value. But finally, I think this behaviour provides a good way to force the variable initialisation before its use. So let's keep it as is.

E) ACL and Rights

I played a little bit with the GRANT and REVOKE statements.

I have got an error (Issue 1). The following statement chain:
create variable public.sv1 int;
grant read on variable sv1 to other_user;
drop owned by other_user;
reports : ERROR: unexpected object class 4287

I then tried to use DEFAULT PRIVILEGES. Despite this is not documented, I successfuly performed:
alter default privileges in schema public grant read on variables to simple_user;
alter default privileges in schema public grant write on variables to simple_user;

When variables are then created, the grants are properly given.
And the psql \ddp command perfectly returns:
Default access privileges
Owner | Schema | Type | Access privileges
----------+--------+------+-------------------------
postgres | public | | simple_user=SW/postgres
(1 row)

So the ALTER DEFAULT PRIVILEGES documentation chapter has to reflect this new syntax (Issue 2).

BTW, in the ACL, the READ privilege is represented by a S letter. A comment in the source reports that the R letter was used in the past for rule privilege. Looking at the postgres sources, I see that this privilege on rules has been suppressed in 8.2, so 13 years ago. As this R letter would be a so much better choice, I wonder whether it couldn't be reused now for this new purpose. Is it important to keep this letter frozen ?

F) Extension

I then created an extension, whose installation script creates a schema variable and functions that use it. The schema variable is correctly linked to the extension, so that dropping the extension drops the variable.

But there is an issue when dumping the database (Issue 3). The script generated by pg_dump includes the CREATE EXTENSION statement as expected but also a redundant CREATE VARIABLE statement for the variable that belongs to the extension. As a result, one of course gets an error at restore time.

G) Row Level Security

I did a test activating RLS on a table and creating a POLICY that references a schema variable in its USING and WITH CHECK clauses. Everything worked fine.

H) psql

A \dV meta-command displays all the created variables.
I would change a little bit the provided view. More precisely I would:
- rename "Constraint" into "Is nullable" and report it as a boolean
- rename "Special behave" into "Is transactional" and report it as a boolean
- change the order of columns so to have:
Schema | Name | Type | Is nullable | Default | Owner | Is transactional | Transaction end action
"Is nullable" being aside "Default"

I) Performance

I just quickly looked at the performance, and didn't notice any issue.

About variables read performance, I have noticed that:
select sum(1) from generate_series(1,10000000);
and
select sum(sv1) from generate_series(1,10000000);
have similar response times.

About planning, a condition with a variable used as a constant is indexable, as if it were a literal.

J) Documentation

There are some wordings to improve in the documentation. But I am not the best person to give advice about english language ;-).

However, aside the already mentionned lack of changes in the ALTER DEFAULT PRIVILEGES chapter, I also noticed :
- line 50 of the patch, the sentence "(hidden attribute; must be explicitly selected)" looks false as the oid column of pg_variable is displayed, as for other tables of the catalog;
- at several places, the word "behave" should be replaced by "behaviour"
- line 433, a get_schema_variable() function is mentionned; is it a function that can really be called by users ?

May be it would be interesting to also add a chapter in the Section V of the documentation, in order to more globally present the schema variables concept, aside the new or the modified statements.

K) Coding

I am not able to appreciate the way the feature has been coded. So I let this for other reviewers ;-)

To conclude, again, thanks a lot for this feature !
And if I may add this. I dream of an additional feature: adding a SHARED clause to the CREATE VARIABLE statement in order to be able to create memory spaces that could be shared by all connections on the database and accessible in SQL and PL, under the protection of ACL. But that's another story ;-)

Best regards. Philippe.

The new status of this patch is: Waiting on Author


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2019-12-22 18:50:22
Message-ID: CAFj8pRDFj4Xc3PN6uEeHEW-Rz7q-s=1Vd5eqH77ZewGyaTevgA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 22. 12. 2019 v 13:04 odesílatel Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
napsal:

> The following review has been posted through the commitfest application:
> make installcheck-world: tested, passed
> Implements feature: tested, failed
> Spec compliant: not tested
> Documentation: tested, failed
>
> Hi Pavel,
>
> First of all, I would like to congratulate you for this great work. This
> patch is really cool. The lack of package variables is sometimes a blocking
> issue for Oracle to Postgres migrations, because the usual emulation with
> GUC is sometimes not enough, in particular when there are security concerns
> or when the database is used in a public cloud.
>
> As I look forward to having this patch commited, I decided to spend some
> time to participate to the review, although I am not a C specialist and I
> have not a good knowledge of the Postgres internals. Here is my report.
>
> A) Installation
>
> The patch applies correctly and the compilation is fine. The "make check"
> doesn't report any issue.
>
> B) Basic usage
>
> I tried some simple schema variables use cases. No problem.
>
> C) The interface
>
> The SQL changes look good to me.
>
> However, in the CREATE VARIABLE command, I would replace the "TRANSACTION"
> word by "TRANSACTIONAL".
>

There is not technical problem - the problem is in introduction new keyword
"transactional" that is near to "transaction". I am not sure if it is
practical to have two "similar" keyword and how much the CREATE statement
has to use correct English grammar.

I am not native speaker, so I am not able to see how bad is using
"TRANSACTION" instead "TRANSACTIONAL" in this context. So I see a risk to
have two important (it is not syntactic sugar) similar keywords.

Just I afraid so using TRANSACTIONAL instead just TRANSACTION is not too
user friendly. I have not strong opinion about this - and the
implementation is easy, but I am not feel comfortable with introduction
this keyword.

> I have also tried to replace this word by a ON ROLLBACK clause at the end
> of the statement, like for ON COMMIT, but I have not found a satisfying
> wording to propose.
>

>
> D) Behaviour
>
> I am ok with variables not being transactional by default. That's the most
> simple, the most efficient, it emulates the package variables of other
> RDBMS and it will probably fit the most common use cases.
>
> Note that I am not strongly opposed to having by default transactional
> variables. But I don't know whether this change would be a great work. We
> would have at least to find another keyword in the CREATE VARIABLE
> statement. Something like "NON-TRANSACTIONAL VARIABLE" ?
>

Variables almost everywhere (global user settings - GUC is only one planet
exception) are non transactional by default. I don't see any reason
introduce new different design than is wide used.

> It is possible to create a NOT NULL variable without DEFAULT. When trying
> to read the variable before a LET statement, one gets an error massage
> saying that the NULL value is not allowed (and the documentation is clear
> about this case). Just for the records, I wondered whether it wouldn't be
> better to forbid a NOT NULL variable creation that wouldn't have a DEFAULT
> value. But finally, I think this behaviour provides a good way to force the
> variable initialisation before its use. So let's keep it as is.
>

This is a question - and there are two possibilities

postgres=# do $$
declare x int not null;
begin
raise notice '%', x;
end;
$$ ;
ERROR: variable "x" must have a default value, since it's declared NOT NULL
LINE 2: declare x int not null;
^

PLpgSQL requires it. But there is not a possibility to enforce future
setting.

So I know so behave of schema variables is little bit different, but I
think so this difference has interesting use case. You can check if the
variable was modified somewhere or not.

> E) ACL and Rights
>
> I played a little bit with the GRANT and REVOKE statements.
>
> I have got an error (Issue 1). The following statement chain:
> create variable public.sv1 int;
> grant read on variable sv1 to other_user;
> drop owned by other_user;
> reports : ERROR: unexpected object class 4287
>

this is bug and should be fixed

> I then tried to use DEFAULT PRIVILEGES. Despite this is not documented, I
> successfuly performed:
> alter default privileges in schema public grant read on variables to
> simple_user;
> alter default privileges in schema public grant write on variables to
> simple_user;
>
> When variables are then created, the grants are properly given.
> And the psql \ddp command perfectly returns:
> Default access privileges
> Owner | Schema | Type | Access privileges
> ----------+--------+------+-------------------------
> postgres | public | | simple_user=SW/postgres
> (1 row)
>
> So the ALTER DEFAULT PRIVILEGES documentation chapter has to reflect this
> new syntax (Issue 2).
>
> BTW, in the ACL, the READ privilege is represented by a S letter. A
> comment in the source reports that the R letter was used in the past for
> rule privilege. Looking at the postgres sources, I see that this privilege
> on rules has been suppressed in 8.2, so 13 years ago. As this R letter
> would be a so much better choice, I wonder whether it couldn't be reused
> now for this new purpose. Is it important to keep this letter frozen ?
>

I have not a idea why it is. I'll recheck it - but in this moment I prefer
a consistency with existing ACL - it can be in future as one block if it
will be necessary for somebody.

>
> F) Extension
>
> I then created an extension, whose installation script creates a schema
> variable and functions that use it. The schema variable is correctly linked
> to the extension, so that dropping the extension drops the variable.
>
> But there is an issue when dumping the database (Issue 3). The script
> generated by pg_dump includes the CREATE EXTENSION statement as expected
> but also a redundant CREATE VARIABLE statement for the variable that
> belongs to the extension. As a result, one of course gets an error at
> restore time.
>

It is bug and should be fixed

> G) Row Level Security
>
> I did a test activating RLS on a table and creating a POLICY that
> references a schema variable in its USING and WITH CHECK clauses.
> Everything worked fine.
>
> H) psql
>
> A \dV meta-command displays all the created variables.
> I would change a little bit the provided view. More precisely I would:
> - rename "Constraint" into "Is nullable" and report it as a boolean
> - rename "Special behave" into "Is transactional" and report it as a
> boolean
> - change the order of columns so to have:
> Schema | Name | Type | Is nullable | Default | Owner | Is transactional |
> Transaction end action
> "Is nullable" being aside "Default"
>

ok

> I) Performance
>
> I just quickly looked at the performance, and didn't notice any issue.
>
> About variables read performance, I have noticed that:
> select sum(1) from generate_series(1,10000000);
> and
> select sum(sv1) from generate_series(1,10000000);
> have similar response times.
>

> About planning, a condition with a variable used as a constant is
> indexable, as if it were a literal.
>
> J) Documentation
>
> There are some wordings to improve in the documentation. But I am not the
> best person to give advice about english language ;-).
>
> However, aside the already mentionned lack of changes in the ALTER DEFAULT
> PRIVILEGES chapter, I also noticed :
> - line 50 of the patch, the sentence "(hidden attribute; must be
> explicitly selected)" looks false as the oid column of pg_variable is
> displayed, as for other tables of the catalog;
> - at several places, the word "behave" should be replaced by "behaviour"
> - line 433, a get_schema_variable() function is mentionned; is it a
> function that can really be called by users ?
>
> May be it would be interesting to also add a chapter in the Section V of
> the documentation, in order to more globally present the schema variables
> concept, aside the new or the modified statements.
>
> K) Coding
>
> I am not able to appreciate the way the feature has been coded. So I let
> this for other reviewers ;-)
>
>
> To conclude, again, thanks a lot for this feature !
> And if I may add this. I dream of an additional feature: adding a SHARED
> clause to the CREATE VARIABLE statement in order to be able to create
> memory spaces that could be shared by all connections on the database and
> accessible in SQL and PL, under the protection of ACL. But that's another
> story ;-)
>

sure, it is another story :-).

Thank you for review - I'll try to fix bugs this week.

Pavel

> Best regards. Philippe.
>
> The new status of this patch is: Waiting on Author
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2019-12-25 21:45:49
Message-ID: CAFj8pRAtEUYDnNcRp4TrhbjXKm-An_xgnQ8vqV=YMQbXvrm91Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 22. 12. 2019 v 13:04 odesílatel Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
napsal:

> The following review has been posted through the commitfest application:
> make installcheck-world: tested, passed
> Implements feature: tested, failed
> Spec compliant: not tested
> Documentation: tested, failed
>
> Hi Pavel,
>
> First of all, I would like to congratulate you for this great work. This
> patch is really cool. The lack of package variables is sometimes a blocking
> issue for Oracle to Postgres migrations, because the usual emulation with
> GUC is sometimes not enough, in particular when there are security concerns
> or when the database is used in a public cloud.
>
> As I look forward to having this patch commited, I decided to spend some
> time to participate to the review, although I am not a C specialist and I
> have not a good knowledge of the Postgres internals. Here is my report.
>
> A) Installation
>
> The patch applies correctly and the compilation is fine. The "make check"
> doesn't report any issue.
>
> B) Basic usage
>
> I tried some simple schema variables use cases. No problem.
>
> C) The interface
>
> The SQL changes look good to me.
>
> However, in the CREATE VARIABLE command, I would replace the "TRANSACTION"
> word by "TRANSACTIONAL".
>
> I have also tried to replace this word by a ON ROLLBACK clause at the end
> of the statement, like for ON COMMIT, but I have not found a satisfying
> wording to propose.
>

I propose compromise solution - I introduced new not reserved keyword
"TRANSACTIONAL". User can use TRANSACTION or TRANSACTIONAL. It is similar
relation like "TEMP" or "TEMPORAL"

>
> D) Behaviour
>
> I am ok with variables not being transactional by default. That's the most
> simple, the most efficient, it emulates the package variables of other
> RDBMS and it will probably fit the most common use cases.
>
> Note that I am not strongly opposed to having by default transactional
> variables. But I don't know whether this change would be a great work. We
> would have at least to find another keyword in the CREATE VARIABLE
> statement. Something like "NON-TRANSACTIONAL VARIABLE" ?
>
> It is possible to create a NOT NULL variable without DEFAULT. When trying
> to read the variable before a LET statement, one gets an error massage
> saying that the NULL value is not allowed (and the documentation is clear
> about this case). Just for the records, I wondered whether it wouldn't be
> better to forbid a NOT NULL variable creation that wouldn't have a DEFAULT
> value. But finally, I think this behaviour provides a good way to force the
> variable initialisation before its use. So let's keep it as is.
>
> E) ACL and Rights
>
> I played a little bit with the GRANT and REVOKE statements.
>
> I have got an error (Issue 1). The following statement chain:
> create variable public.sv1 int;
> grant read on variable sv1 to other_user;
> drop owned by other_user;
> reports : ERROR: unexpected object class 4287
>

should be fixed

> I then tried to use DEFAULT PRIVILEGES. Despite this is not documented, I
> successfuly performed:
> alter default privileges in schema public grant read on variables to
> simple_user;
> alter default privileges in schema public grant write on variables to
> simple_user;
>

should be fixed

> When variables are then created, the grants are properly given.
> And the psql \ddp command perfectly returns:
> Default access privileges
> Owner | Schema | Type | Access privileges
> ----------+--------+------+-------------------------
> postgres | public | | simple_user=SW/postgres
> (1 row)
>
> So the ALTER DEFAULT PRIVILEGES documentation chapter has to reflect this
> new syntax (Issue 2).
>
> BTW, in the ACL, the READ privilege is represented by a S letter. A
> comment in the source reports that the R letter was used in the past for
> rule privilege. Looking at the postgres sources, I see that this privilege
> on rules has been suppressed in 8.2, so 13 years ago. As this R letter
> would be a so much better choice, I wonder whether it couldn't be reused
> now for this new purpose. Is it important to keep this letter frozen ?
>

I use ACL_READ constant in my patch. The value of ACL_READ is defined
elsewhere. So the changing from S to R should be done by separate patch and
by separate discussion.

> F) Extension
>
> I then created an extension, whose installation script creates a schema
> variable and functions that use it. The schema variable is correctly linked
> to the extension, so that dropping the extension drops the variable.
>
> But there is an issue when dumping the database (Issue 3). The script
> generated by pg_dump includes the CREATE EXTENSION statement as expected
> but also a redundant CREATE VARIABLE statement for the variable that
> belongs to the extension. As a result, one of course gets an error at
> restore time.
>

should be fixed now

> G) Row Level Security
>
> I did a test activating RLS on a table and creating a POLICY that
> references a schema variable in its USING and WITH CHECK clauses.
> Everything worked fine.
>
> H) psql
>
> A \dV meta-command displays all the created variables.
> I would change a little bit the provided view. More precisely I would:
> - rename "Constraint" into "Is nullable" and report it as a boolean
> - rename "Special behave" into "Is transactional" and report it as a
> boolean
> - change the order of columns so to have:
> Schema | Name | Type | Is nullable | Default | Owner | Is transactional |
> Transaction end action
> "Is nullable" being aside "Default"
>

I implemented your proposal

> I) Performance
>
> I just quickly looked at the performance, and didn't notice any issue.
>
> About variables read performance, I have noticed that:
> select sum(1) from generate_series(1,10000000);
> and
> select sum(sv1) from generate_series(1,10000000);
> have similar response times.
>
> About planning, a condition with a variable used as a constant is
> indexable, as if it were a literal.
>
> J) Documentation
>
> There are some wordings to improve in the documentation. But I am not the
> best person to give advice about english language ;-).
>
> However, aside the already mentionned lack of changes in the ALTER DEFAULT
> PRIVILEGES chapter, I also noticed :
> - line 50 of the patch, the sentence "(hidden attribute; must be
> explicitly selected)" looks false as the oid column of pg_variable is
> displayed, as for other tables of the catalog;
> - at several places, the word "behave" should be replaced by "behaviour"
> - line 433, a get_schema_variable() function is mentionned; is it a
> function that can really be called by users ?
>

should be fixed

> May be it would be interesting to also add a chapter in the Section V of
> the documentation, in order to more globally present the schema variables
> concept, aside the new or the modified statements.
>

We can finalize documentation little bit later, when will be clear what
related functionality is implemented.

updated patch attached

> K) Coding
>
> I am not able to appreciate the way the feature has been coded. So I let
> this for other reviewers ;-)
>
>
> To conclude, again, thanks a lot for this feature !
> And if I may add this. I dream of an additional feature: adding a SHARED
> clause to the CREATE VARIABLE statement in order to be able to create
> memory spaces that could be shared by all connections on the database and
> accessible in SQL and PL, under the protection of ACL. But that's another
> story ;-)
>
> Best regards. Philippe.
>

Thank you very much for review

>
> The new status of this patch is: Waiting on Author
>

Attachment Content-Type Size
schema-variables-20191225.patch.gz application/gzip 66.0 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2019-12-26 18:13:41
Message-ID: CAFj8pRAcb+PLKJJOGn7POtcTuH8DaKqZNid-7UvB9_BtgshHEQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20191226.patch.gz application/gzip 66.0 KB

From: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal: schema variables
Date: 2019-12-30 16:26:10
Message-ID: 157772317031.1198.14690129684698137065.pgcf@coridan.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: not tested
Documentation: tested, failed

Hi Pavel,

I have tested the latest version of your patch.
Both issues I reported are now fixed. And you largely applied my proposals. That's great !

I have also spent some time to review more closely the documentation. I will send you a direct mail with an attached file for some minor comments on this topic.

Except these documentation remarks to come, I haven't any other issue or suggestion to report.
Note that I have not closely looked at the C code itself. But may be some other reviewers have already done that job.
If yes, my feeling is that the patch could soon be set as "Ready for commiter".

Best regards. Philippe.

The new status of this patch is: Waiting on Author


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2019-12-30 20:05:40
Message-ID: CAFj8pRA+SYbegM6f5OTamwhMdsVXB22mbmkscaErrhYge8ji3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 30. 12. 2019 v 17:27 odesílatel Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
napsal:

> The following review has been posted through the commitfest application:
> make installcheck-world: tested, passed
> Implements feature: tested, passed
> Spec compliant: not tested
> Documentation: tested, failed
>
> Hi Pavel,
>
> I have tested the latest version of your patch.
> Both issues I reported are now fixed. And you largely applied my
> proposals. That's great !
>
> I have also spent some time to review more closely the documentation. I
> will send you a direct mail with an attached file for some minor comments
> on this topic.
>
> Except these documentation remarks to come, I haven't any other issue or
> suggestion to report.
> Note that I have not closely looked at the C code itself. But may be some
> other reviewers have already done that job.
> If yes, my feeling is that the patch could soon be set as "Ready for
> commiter".
>
> Best regards. Philippe.
>
> The new status of this patch is: Waiting on Author
>

Thank you very much for your comments, and notes. Updated patch attached.

Regards

Pavel

Attachment Content-Type Size
schema-variables-20191230.patch.gz application/gzip 66.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-01-17 21:10:35
Message-ID: CAFj8pRCAGXK9Wd8FGboFkFyUTWwh0qJUKW0muVAMkAUq6feCdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 30. 12. 2019 v 21:05 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> po 30. 12. 2019 v 17:27 odesílatel Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>
> napsal:
>
>> The following review has been posted through the commitfest application:
>> make installcheck-world: tested, passed
>> Implements feature: tested, passed
>> Spec compliant: not tested
>> Documentation: tested, failed
>>
>> Hi Pavel,
>>
>> I have tested the latest version of your patch.
>> Both issues I reported are now fixed. And you largely applied my
>> proposals. That's great !
>>
>> I have also spent some time to review more closely the documentation. I
>> will send you a direct mail with an attached file for some minor comments
>> on this topic.
>>
>> Except these documentation remarks to come, I haven't any other issue or
>> suggestion to report.
>> Note that I have not closely looked at the C code itself. But may be some
>> other reviewers have already done that job.
>> If yes, my feeling is that the patch could soon be set as "Ready for
>> commiter".
>>
>> Best regards. Philippe.
>>
>> The new status of this patch is: Waiting on Author
>>
>
> Thank you very much for your comments, and notes. Updated patch attached.
>

rebase

> Regards
>
> Pavel
>
>

Attachment Content-Type Size
schema-variables-20200117.patch.gz application/gzip 66.3 KB

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-01-21 23:41:41
Message-ID: 20200121234141.se4v2hygsiy3lffx@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi,

I did a quick review of this patch today, so let me share a couple of
comments.

Firstly, the patch is pretty large - it has ~270kB. Not the largest
patch ever, but large. I think breaking the patch into smaller pieces
would significantly improve the chnce of it getting committed.

Is it possible to break the patch into smaller pieces that could be
applied incrementally? For example, we could move the "transactional"
behavior into a separate patch, but it's not clear to me how much code
would that actually move to that second patch. Any other parts that
could be moved to a separate patch?

I see one of the main contention points was a rather long discussion
about transactional vs. non-transactional behavior. I agree with Pavel's
position that the non-transactional behavior should be the default,
simply because it's better aligned with what the other databases are
doing (and supporting migrations seems like one of the main use cases
for this feature).

I do understand it may not be suitable for some other use cases,
mentioned by Fabien, but IMHO it's fine to require explicit
specification of transactional behavior. Well, we can't have both as
default, and I don't think there's an obvious reason why it should be
the other way around.

Now, a bunch of comments about the code (some of that nitpicking):

1) This hunk in doc/src/sgml/catalogs.sgml still talks about "table
creation" instead of schema creation:

<row>
<entry><structfield>vartypmod</structfield></entry>
<entry><type>int4</type></entry>
<entry></entry>
<entry>
<structfield>vartypmod</structfield> records type-specific data
supplied at table creation time (for example, the maximum
length of a <type>varchar</type> column). It is passed to
type-specific input functions and length coercion functions.
The value will generally be -1 for types that do not need <structfield>vartypmod</structfield>.
</entry>
</row>

2) This hunk in doc/src/sgml/ref/alter_default_privileges.sgml uses
"role_name" instead of "variable_name"

GRANT { READ | WRITE | ALL [ PRIVILEGES ] }
ON VARIABLES
TO { [ GROUP ] <replaceable class="parameter">role_name</replaceable> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

3) I find the syntax in create_variable.sgml a bit too over-complicated:

<synopsis>
CREATE [ { TEMPORARY | TEMP } ] [ { TRANSACTIONAL | TRANSACTION } ] VARIABLE [ IF NOT EXISTS ] <replaceable class="parameter">name</replaceable> [ AS ] <replaceable class="parameter">data_type</replaceable> ] [ COLLATE <replaceable class="parameter">collation</replaceable> ]
[ NOT NULL ] [ DEFAULT <replaceable class="parameter">default_expr</replaceable> ] [ { ON COMMIT DROP | ON { TRANSACTIONAL | TRANSACTION } END RESET } ]
</synopsis>

Do we really need both TRANSACTION and TRANSACTIONAL? Why not just one
that we already have in the grammar (i.e. TRANSACTION)?

4) I think we should rename schemavariable.h to schema_variable.h.

5) objectaddress.c has extra line after 'break;' in one switch.

6) The comment is wrong:

/*
* Find the ObjectAddress for a type or domain
*/
static ObjectAddress
get_object_address_variable(List *object, bool missing_ok)

7) I think the code/comments are really inconsistent in talking about
"variables" and "schema variables". For example in objectaddress.c we do
these two things:

case OCLASS_VARIABLE:
appendStringInfoString(&buffer, "schema variable");
break;

vs.

case DEFACLOBJ_VARIABLE:
appendStringInfoString(&buffer,
" on variables");
break;

That's going to be confusing for people.

8) I'm rather confused by CMD_PLAN_UTILITY, which seems to be defined
merely to support LET. I'm not sure why that's necessary (Why wouldn't
CMD_UTILITY be sufficient?).

Having to add conditions checking for CMD_PLAN_UTILITY to various places
in planner.c is rather annoying, and I wonder how likely it's this will
unnecessarily break external code in extensions etc.

9) This comment in planner.c seems obsolete (not updated to reflect
addition of the CMD_PLAN_UTILITY check):

/*
* If this is an INSERT/UPDATE/DELETE, and we're not being called from
* inheritance_planner, add the ModifyTable node.
*/
if (parse->commandType != CMD_SELECT && parse->commandType != CMD_PLAN_UTILITY && !inheritance_update)

10) I kinda wonder what happens when a function is used in a WHERE
condition, but it depends on a variable and alsu mutates it on each
call ...

11) I think Query->hasSchemaVariable (in analyze.c) should be renamed to
hasSchemaVariables (which reflects the other fields referring to things
like window functions etc.)

12) I find it rather suspicious that we make decisions in utility.c
solely based on commandType (whether it's CMD_UTILITY or not). IMO
it's pretty strange/ugly that T_LetStmt can be both CMD_UTILITY and
CMD_PLAN_UTILITY:

case T_LetStmt:
{
if (pstmt->commandType == CMD_UTILITY)
doLetStmtReset(pstmt);
else
{
Assert(pstmt->commandType == CMD_PLAN_UTILITY);
doLetStmtEval(pstmt, params, queryEnv, queryString);
}

if (completionTag)
strcpy(completionTag, "LET");
}
break;

13) Not sure why we moved DO_TABLE in addBoundaryDependencies
(pg_dump.c), seems unnecessary:

case DO_CONVERSION:
- case DO_TABLE:
+ case DO_VARIABLE:
case DO_ATTRDEF:
+ case DO_TABLE:
case DO_PROCLANG:

14) namespace.c defines VariableIsVisible twice:

extern bool VariableIsVisible(Oid relid);
...
extern bool VariableIsVisible(Oid varid);

15) I'd say lookup_variable and identify_variable should use camelcase
just like the other functions in the same file.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-01-24 05:08:45
Message-ID: CAFj8pRA1NuqD3-JP5ESBA8dUze=6h2YEQoqnBDWgawFo+Z3ONQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 22. 1. 2020 v 0:41 odesílatel Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
napsal:

> Hi,
>
> I did a quick review of this patch today, so let me share a couple of
> comments.
>
> Firstly, the patch is pretty large - it has ~270kB. Not the largest
> patch ever, but large. I think breaking the patch into smaller pieces
> would significantly improve the chnce of it getting committed.
>
> Is it possible to break the patch into smaller pieces that could be
> applied incrementally? For example, we could move the "transactional"
> behavior into a separate patch, but it's not clear to me how much code
> would that actually move to that second patch. Any other parts that
> could be moved to a separate patch?
>

I am sending two patches - 0001 - schema variables, 0002 - transactional
variables

>
> I see one of the main contention points was a rather long discussion
> about transactional vs. non-transactional behavior. I agree with Pavel's
> position that the non-transactional behavior should be the default,
> simply because it's better aligned with what the other databases are
> doing (and supporting migrations seems like one of the main use cases
> for this feature).
>
> I do understand it may not be suitable for some other use cases,
> mentioned by Fabien, but IMHO it's fine to require explicit
> specification of transactional behavior. Well, we can't have both as
> default, and I don't think there's an obvious reason why it should be
> the other way around.
>
> Now, a bunch of comments about the code (some of that nitpicking):
>
>
> 1) This hunk in doc/src/sgml/catalogs.sgml still talks about "table
> creation" instead of schema creation:
>
> <row>
> <entry><structfield>vartypmod</structfield></entry>
> <entry><type>int4</type></entry>
> <entry></entry>
> <entry>
> <structfield>vartypmod</structfield> records type-specific data
> supplied at table creation time (for example, the maximum
> length of a <type>varchar</type> column). It is passed to
> type-specific input functions and length coercion functions.
> The value will generally be -1 for types that do not need
> <structfield>vartypmod</structfield>.
> </entry>
> </row>
>

fixed

>
> 2) This hunk in doc/src/sgml/ref/alter_default_privileges.sgml uses
> "role_name" instead of "variable_name"
>
> GRANT { READ | WRITE | ALL [ PRIVILEGES ] }
> ON VARIABLES
> TO { [ GROUP ] <replaceable class="parameter">role_name</replaceable>
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]
>

I think so this is correct

>
> 3) I find the syntax in create_variable.sgml a bit too over-complicated:
>
> <synopsis>
> CREATE [ { TEMPORARY | TEMP } ] [ { TRANSACTIONAL | TRANSACTION } ]
> VARIABLE [ IF NOT EXISTS ] <replaceable
> class="parameter">name</replaceable> [ AS ] <replaceable
> class="parameter">data_type</replaceable> ] [ COLLATE <replaceable
> class="parameter">collation</replaceable> ]
> [ NOT NULL ] [ DEFAULT <replaceable
> class="parameter">default_expr</replaceable> ] [ { ON COMMIT DROP | ON {
> TRANSACTIONAL | TRANSACTION } END RESET } ]
> </synopsis>
>
> Do we really need both TRANSACTION and TRANSACTIONAL? Why not just one
> that we already have in the grammar (i.e. TRANSACTION)?
>

It was a Philippe's wish - the implementation is simple, and it is similar
like TEMP, TEMPORARY. I have not any opinion about it.

>
> 4) I think we should rename schemavariable.h to schema_variable.h.
>

done

>
> 5) objectaddress.c has extra line after 'break;' in one switch.
>

fixed

>
> 6) The comment is wrong:
>
> /*
> * Find the ObjectAddress for a type or domain
> */
> static ObjectAddress
> get_object_address_variable(List *object, bool missing_ok)
>

fixed

>
> 7) I think the code/comments are really inconsistent in talking about
> "variables" and "schema variables". For example in objectaddress.c we do
> these two things:
>
> case OCLASS_VARIABLE:
> appendStringInfoString(&buffer, "schema variable");
> break;
>
> vs.
>
> case DEFACLOBJ_VARIABLE:
> appendStringInfoString(&buffer,
> " on variables");
> break;
>
> That's going to be confusing for people.
>
>
fixed

>
> 8) I'm rather confused by CMD_PLAN_UTILITY, which seems to be defined
> merely to support LET. I'm not sure why that's necessary (Why wouldn't
> CMD_UTILITY be sufficient?).
>

Currently out utility statements cannot to hold a execution plan, and
cannot be prepared.

so this enhancing is motivated mainly by performance reasons. I would to
allow any SELECT query there, not just expressions only (see a limits of
CALL statement)

> Having to add conditions checking for CMD_PLAN_UTILITY to various places
> in planner.c is rather annoying, and I wonder how likely it's this will
> unnecessarily break external code in extensions etc.
>
>
> 9) This comment in planner.c seems obsolete (not updated to reflect
> addition of the CMD_PLAN_UTILITY check):
>
> /*
> * If this is an INSERT/UPDATE/DELETE, and we're not being called from
> * inheritance_planner, add the ModifyTable node.
> */
> if (parse->commandType != CMD_SELECT && parse->commandType !=
> CMD_PLAN_UTILITY && !inheritance_update)
>

"If this is an INSERT/UPDATE/DELETE," is related to parse->commandType !=
CMD_SELECT && parse->commandType != CMD_PLAN_UTILITY

>
>
> 10) I kinda wonder what happens when a function is used in a WHERE
> condition, but it depends on a variable and alsu mutates it on each
> call ...
>
>
> 11) I think Query->hasSchemaVariable (in analyze.c) should be renamed to
> hasSchemaVariables (which reflects the other fields referring to things
> like window functions etc.)
>
>
done

> 12) I find it rather suspicious that we make decisions in utility.c
> solely based on commandType (whether it's CMD_UTILITY or not). IMO
> it's pretty strange/ugly that T_LetStmt can be both CMD_UTILITY and
> CMD_PLAN_UTILITY:
>
> case T_LetStmt:
> {
> if (pstmt->commandType == CMD_UTILITY)
> doLetStmtReset(pstmt);
> else
> {
> Assert(pstmt->commandType == CMD_PLAN_UTILITY);
> doLetStmtEval(pstmt, params, queryEnv, queryString);
> }
>
> if (completionTag)
> strcpy(completionTag, "LET");
> }
> break;
>
>
> 13) Not sure why we moved DO_TABLE in addBoundaryDependencies
> (pg_dump.c), seems unnecessary:
>
> case DO_CONVERSION:
> - case DO_TABLE:
> + case DO_VARIABLE:
> case DO_ATTRDEF:
> + case DO_TABLE:
> case DO_PROCLANG:
>

fixed

>
> 14) namespace.c defines VariableIsVisible twice:
>
> extern bool VariableIsVisible(Oid relid);
> ...
> extern bool VariableIsVisible(Oid varid);
>
>
fixed

> 15) I'd say lookup_variable and identify_variable should use camelcase
> just like the other functions in the same file.
>

fixed

Regards

Pavel

>
> regards
>
> --
> Tomas Vondra http://www.2ndQuadrant.com
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

Attachment Content-Type Size
0002-transaction-variables.patch.gz application/gzip 7.1 KB
0001-schema-variables.patch.gz application/gzip 64.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-01-26 17:26:16
Message-ID: CAFj8pRDxHCt9_fDQ8cu07jB4KzyU1qmzgH9uA1XsPdqvZN-w6A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

>
>
> 12) I find it rather suspicious that we make decisions in utility.c
> solely based on commandType (whether it's CMD_UTILITY or not). IMO
> it's pretty strange/ugly that T_LetStmt can be both CMD_UTILITY and
> CMD_PLAN_UTILITY:
>
> case T_LetStmt:
> {
> if (pstmt->commandType == CMD_UTILITY)
> doLetStmtReset(pstmt);
> else
> {
> Assert(pstmt->commandType == CMD_PLAN_UTILITY);
> doLetStmtEval(pstmt, params, queryEnv, queryString);
> }
>
> if (completionTag)
> strcpy(completionTag, "LET");
> }
> break;
>
>
>
It looks strange, but it has sense, because the LET stmt supports reset to
default value.

I can write

1. LET var = DEFAULT;
2. LET var = (query);

In first case I have not any query, that I can assign, and in this case the
LET statement is really only UTILITY.

I did comment there

Regards

Pavel

>
>
> regards
>
> --
> Tomas Vondra http://www.2ndQuadrant.com
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

Attachment Content-Type Size
0001-schema-variables-20200126.patch.gz application/gzip 64.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-02-07 16:09:47
Message-ID: CAFj8pRCK5MaMJATx5BmoRv9TdLgZ4kWpor5yEP1e=V6ohoQv2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase

Regards

Pavel

Attachment Content-Type Size
0002-transactional-variables-20200207.patch.gz application/gzip 7.2 KB
0001-schema-variables-20200207.patch.gz application/gzip 64.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-02-10 18:47:35
Message-ID: CAFj8pRAUgPscQcT5CV8QwuNkx1HHSkxb-ba-CMsCe7MODvjMbw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 7. 2. 2020 v 17:09 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> rebase
>
> Regards
>
> Pavel
>

Hi

another rebase, fix \dV statement (for 0001 patch)

Regards

Pavel

Attachment Content-Type Size
0002-transactional-variables-20200210.patch.gz application/gzip 7.5 KB
0001-schema-variables-20200210.patch.gz application/gzip 64.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: Philippe BEAUDOIN <phb07(at)apra(dot)asso(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-02-15 08:05:01
Message-ID: CAFj8pRBQSbOvK94QJCZGY7xqiuT7R7tuGKgci+CXGYONs5PGOw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 10. 2. 2020 v 19:47 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> pá 7. 2. 2020 v 17:09 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> rebase
>>
>> Regards
>>
>> Pavel
>>
>
> Hi
>
> another rebase, fix \dV statement (for 0001 patch)
>

rebase

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
0001-schema-variables-20200215.patch.gz application/gzip 64.2 KB

From: remi duval <remi(dot)duval(at)cheops(dot)fr>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal: schema variables
Date: 2020-02-26 14:53:55
Message-ID: 158272883575.1651.2316685587547965508.pgcf@coridan.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

The following review has been posted through the commitfest application:
make installcheck-world: not tested
Implements feature: tested, passed
Spec compliant: tested, failed
Documentation: tested, failed

Hello Pavel

First thanks for working on this patch cause it might be really helpful for those of us trying to migrate PL code between RDBMs.

I tried your patch for migrating an Oracle package body to PL/pgSQL after also testing a solution using set_config and current_setting (which works but I'm not really satisfied by this workaround solution).

So I compiled latest postgres sources from github on Linux (redhat 7.7) using only your patch number 1 (I did not try the second part of the patch).

For my use-case it's working great, performances are excellent (compared to other solution for porting "package variables").
I did not test all the features involved by the patch (especially ALTER variable).

I have some feedback however :

1) Failure when using pg_dump 13 on a 12.1 database

When exporting a 12.1 database using pg_dump from the latest development sources I have an error regarding variables export

[pg12(at)TST-LINUX-PG-03 ~]$ /opt/postgres12/pg12/bin/pg_dump -h localhost -p 5432 -U postgres -f dump_pg12.sql database1
pg_dump: error: query failed: ERROR: relation "pg_variable" does not exist
LINE 1: ...og.pg_get_expr(v.vardefexpr,0) as vardefexpr FROM pg_variabl...
^
pg_dump: error: query was: SELECT v.tableoid, v.oid, v.varname, v.vareoxaction, v.varnamespace,
(SELECT rolname FROM pg_catalog.pg_roles WHERE oid = varowner) AS rolname
, (SELECT pg_catalog.array_agg(acl ORDER BY row_n) FROM (SELECT acl, row_n
FROM pg_catalog.unnest(coalesce(v.varacl,pg_catalog.acldefault('V',v.varowner)))
WITH ORDINALITY AS perm(acl,row_n)
WHERE NOT EXISTS ( SELECT 1 FROM pg_catalog.unnest(coalesce(pip.initprivs,pg_catalog.acldefault('V',v.varowner))) AS init(init_acl)
WHERE acl = init_acl)) as foo) as varacl, ...:

I think that it should have worked anyway cause the documentation states :
https://www.postgresql.org/docs/current/upgrading.html
"It is recommended that you use the pg_dump and pg_dumpall programs from the newer version of PostgreSQL, to take advantage of enhancements that might have been made in these programs." (that's what I did here)

I think there should be a way to avoid dumping the variable if they don't exist, should'nt it ?

2) Displaying the variables + completion
I created 2 variables using :
CREATE VARIABLE my_pkg.g_dat_deb varchar(11);
CREATE VARIABLE my_pkg.g_dat_fin varchar(11);
When I try to display them, I can only see them when prefixing by the schema :
bdd13=> \dV
"Did not find any schema variables."
bdd13=> \dV my_pkg.*
List of variables
Schema | Name | Type | Is nullable | Default | Owner | Transactional end action
------------+----------------+-----------------------+-------------+---------+-------+--------------------------
my_pkg| g_dat_deb | character varying(11) | t | | myowner |
my_pkg| g_dat_fin | character varying(11) | t | | myowner |
(3 rows)

bdd13=> \dV my_pkg
Did not find any schema variable named "my_pck".
NB : Using this template, functions are returned, maybe variables should also be listed ? (here by querying on "my_pkg%")
cts_get13=> \dV my_p [TAB]
=> completion using [TAB] key is not working

Is this normal that I cannot see all the variables when not specifying any schema ?
Also the completion works for functions, but not for variable.
That's just some bonus but it might be good to have it.

I think the way variables are listed using \dV should match with \df for querying functions

3) Any way to define CONSTANTs ?
We already talked a bit about this subject and also Gilles Darold introduces it in this mailing-list topic but I'd like to insist on it.
I think it would be nice to have a way to say that a variable should not be changed once defined.
Maybe it's hard to implement and can be implemented later, but I just want to know if this concern is open.

Otherwise the documentation looks good to me.

Regards

Rémi


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: remi duval <remi(dot)duval(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-02-26 20:40:02
Message-ID: CAFj8pRDj7ss7YNRdF1nD6=DaeAk7YJ=Nz6449-g0DrPEZmxEug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 26. 2. 2020 v 15:54 odesílatel remi duval <remi(dot)duval(at)cheops(dot)fr> napsal:

> The following review has been posted through the commitfest application:
> make installcheck-world: not tested
> Implements feature: tested, passed
> Spec compliant: tested, failed
> Documentation: tested, failed
>
> Hello Pavel
>
> First thanks for working on this patch cause it might be really helpful
> for those of us trying to migrate PL code between RDBMs.
>
> I tried your patch for migrating an Oracle package body to PL/pgSQL after
> also testing a solution using set_config and current_setting (which works
> but I'm not really satisfied by this workaround solution).
>
> So I compiled latest postgres sources from github on Linux (redhat 7.7)
> using only your patch number 1 (I did not try the second part of the patch).
>
> For my use-case it's working great, performances are excellent (compared
> to other solution for porting "package variables").
> I did not test all the features involved by the patch (especially ALTER
> variable).
>

ALTER VARIABLE is not implemented yet

> I have some feedback however :
>
> 1) Failure when using pg_dump 13 on a 12.1 database
>
> When exporting a 12.1 database using pg_dump from the latest development
> sources I have an error regarding variables export
>
> [pg12(at)TST-LINUX-PG-03 ~]$ /opt/postgres12/pg12/bin/pg_dump -h localhost
> -p 5432 -U postgres -f dump_pg12.sql database1
> pg_dump: error: query failed: ERROR: relation "pg_variable" does not exist
> LINE 1: ...og.pg_get_expr(v.vardefexpr,0) as vardefexpr FROM pg_variabl...
> ^
> pg_dump: error: query was: SELECT v.tableoid, v.oid, v.varname,
> v.vareoxaction, v.varnamespace,
> (SELECT rolname FROM pg_catalog.pg_roles WHERE oid = varowner) AS rolname
> , (SELECT pg_catalog.array_agg(acl ORDER BY row_n) FROM (SELECT acl, row_n
> FROM
> pg_catalog.unnest(coalesce(v.varacl,pg_catalog.acldefault('V',v.varowner)))
> WITH ORDINALITY AS perm(acl,row_n)
> WHERE NOT EXISTS ( SELECT 1 FROM
> pg_catalog.unnest(coalesce(pip.initprivs,pg_catalog.acldefault('V',v.varowner)))
> AS init(init_acl)
> WHERE acl = init_acl)) as foo) as varacl, ...:
>
> I think that it should have worked anyway cause the documentation states :
> https://www.postgresql.org/docs/current/upgrading.html
> "It is recommended that you use the pg_dump and pg_dumpall programs from
> the newer version of PostgreSQL, to take advantage of enhancements that
> might have been made in these programs." (that's what I did here)
>
> I think there should be a way to avoid dumping the variable if they don't
> exist, should'nt it ?
>

There was a protection against dump 11, but now it should be Postgres 12.
Fixed.

>
> 2) Displaying the variables + completion
> I created 2 variables using :
> CREATE VARIABLE my_pkg.g_dat_deb varchar(11);
> CREATE VARIABLE my_pkg.g_dat_fin varchar(11);
> When I try to display them, I can only see them when prefixing by the
> schema :
> bdd13=> \dV
> "Did not find any schema variables."
> bdd13=> \dV my_pkg.*
> List of variables
> Schema | Name | Type | Is nullable |
> Default | Owner | Transactional end action
>
> ------------+----------------+-----------------------+-------------+---------+-------+--------------------------
> my_pkg| g_dat_deb | character varying(11) | t | |
> myowner |
> my_pkg| g_dat_fin | character varying(11) | t | |
> myowner |
> (3 rows)
>

it is ok - it depends on SEARCH_PATH value

> bdd13=> \dV my_pkg
> Did not find any schema variable named "my_pck".
> NB : Using this template, functions are returned, maybe variables should
> also be listed ? (here by querying on "my_pkg%")
> cts_get13=> \dV my_p [TAB]
> => completion using [TAB] key is not working
>
> Is this normal that I cannot see all the variables when not specifying any
> schema ?
> Also the completion works for functions, but not for variable.
> That's just some bonus but it might be good to have it.
>
> I think the way variables are listed using \dV should match with \df for
> querying functions
>

fixed

> 3) Any way to define CONSTANTs ?
> We already talked a bit about this subject and also Gilles Darold
> introduces it in this mailing-list topic but I'd like to insist on it.
> I think it would be nice to have a way to say that a variable should not
> be changed once defined.
> Maybe it's hard to implement and can be implemented later, but I just want
> to know if this concern is open.
>

This topic is open. I tried to play with it. The problem is syntax. When I
try to reproduce syntax from PLpgSQL, then I need to introduce new reserved
keyword. So my initial idea was wrong.
We need to open discussion about implementable syntax. For this moment you
can use a workaround - any schema variable without WRITE right is constant.
Implementation is easy. Design of syntax is harder.

please see attached patch

Regards

Pavel

>
> Otherwise the documentation looks good to me.
>
> Regards
>
> Rémi

Attachment Content-Type Size
schema-variables-20200226.patch.gz application/gzip 64.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: remi duval <remi(dot)duval(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-02-27 14:37:48
Message-ID: CAFj8pRC9H8s3=Twpk4e+As6Sz7NrceynEKsupg5JLNpVBe4sqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

> 3) Any way to define CONSTANTs ?
> We already talked a bit about this subject and also Gilles Darold
> introduces it in this mailing-list topic but I'd like to insist on it.
> I think it would be nice to have a way to say that a variable should not
> be changed once defined.
> Maybe it's hard to implement and can be implemented later, but I just want
> to know if this concern is open.
>

I played little bit with it and I didn't find any nice solution, but maybe
I found the solution. I had ideas about some variants, but almost all time
I had a problem with parser's shifts because all potential keywords are not
reserved.

last variant, but maybe best is using keyword WITH

So the syntax can looks like

CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT
expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]

What do you think about this syntax? It doesn't need any new keyword, and
it easy to enhance it.

CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);

?

Regards

Pavel


From: DUVAL REMI <REMI(dot)DUVAL(at)CHEOPS(dot)FR>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: RE: proposal: schema variables
Date: 2020-02-27 14:59:12
Message-ID: aa8e0d2dc1f342fe97692028713b111c@CHG-E2K13-DC2.INTRANET.CHEOPS.FR
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hello Pavel.

That looks pretty good to me !

I’m adding Philippe Beaudoin who was also interested in this topic.

Recap : We were looking for a way to separate variable from constants in the “Schema Variables” proposition from Pavel.
Pavel was saying that there are some limitations regarding the keywords we can use, as the community don’t want to introduce too much new keywords in Postgres SQL (PL/pgSQL is a different list of keywords).
“CONSTANT” is not a keyword in SQL for Now (though it is one in PL/pgSQL).
Pavel’s syntax allow to use it as a keyword in the “WITH OPTIONS” clause that is already supported.
… I think it’s a good idea.

The list of keywords is defined in : postgresql\src\include\parser\kwlist.h

Pavel, I saw that in DB2, those variables are called “Global Variables”, is it something we can consider changing, or do you prefer to keep using the “Schema Variable” name ?

De : Pavel Stehule [mailto:pavel(dot)stehule(at)gmail(dot)com]
Envoyé : jeudi 27 février 2020 15:38
À : DUVAL REMI <REMI(dot)DUVAL(at)CHEOPS(dot)FR>
Cc : PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Objet : Re: proposal: schema variables

Hi

3) Any way to define CONSTANTs ?
We already talked a bit about this subject and also Gilles Darold introduces it in this mailing-list topic but I'd like to insist on it.
I think it would be nice to have a way to say that a variable should not be changed once defined.
Maybe it's hard to implement and can be implemented later, but I just want to know if this concern is open.

I played little bit with it and I didn't find any nice solution, but maybe I found the solution. I had ideas about some variants, but almost all time I had a problem with parser's shifts because all potential keywords are not reserved.

last variant, but maybe best is using keyword WITH

So the syntax can looks like

CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]

What do you think about this syntax? It doesn't need any new keyword, and it easy to enhance it.

CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);

?

Regards

Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-02-27 15:09:44
Message-ID: CAFj8pRARL4SpJQxsp4JS2t=WoZvbj7QOCgjM_mLbsv=+Qh2vxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 27. 2. 2020 v 15:59 odesílatel DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr> napsal:

> Hello Pavel.
>
>
>
> That looks pretty good to me !
>
>
>
> I’m adding Philippe Beaudoin who was also interested in this topic.
>
>
>
> Recap : We were looking for a way to separate variable from constants in
> the “Schema Variables” proposition from Pavel.
>
> Pavel was saying that there are some limitations regarding the keywords we
> can use, as the community don’t want to introduce too much new keywords in
> Postgres SQL (PL/pgSQL is a different list of keywords).
>
> “CONSTANT” is not a keyword in SQL for Now (though it is one in PL/pgSQL).
>
> Pavel’s syntax allow to use it as a keyword in the “WITH OPTIONS” clause
> that is already supported.
>
> … I think it’s a good idea.
>
>
>
> The list of keywords is defined in : postgresql\src\include\parser\kwlist.h
>
>
>
> Pavel, I saw that in DB2, those variables are called “Global Variables”,
> is it something we can consider changing, or do you prefer to keep using
> the “Schema Variable” name ?
>

It is most hard question. Global variables has sense, but when we will use
it in plpgsql, then this name can be little bit confusing. Personally I
prefer "schema variable" although my opinion is not too strong. This name
more signalize so this is more generic, more database related than some
special kind of plpgsql variables. Now, I think so maybe is better to use
schema variables, because there is different syntax then global temp
tables. Variables are global by design. So in this moment I prefer the name
"schema variables". It can be used as global variables in plpgsql, but it
is one case.

Pavel

>
>
>
> *De :* Pavel Stehule [mailto:pavel(dot)stehule(at)gmail(dot)com]
> *Envoyé :* jeudi 27 février 2020 15:38
> *À :* DUVAL REMI <REMI(dot)DUVAL(at)CHEOPS(dot)FR>
> *Cc :* PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
> *Objet :* Re: proposal: schema variables
>
>
>
>
>
> Hi
>
>
>
>
> 3) Any way to define CONSTANTs ?
> We already talked a bit about this subject and also Gilles Darold
> introduces it in this mailing-list topic but I'd like to insist on it.
> I think it would be nice to have a way to say that a variable should not
> be changed once defined.
> Maybe it's hard to implement and can be implemented later, but I just want
> to know if this concern is open.
>
>
>
> I played little bit with it and I didn't find any nice solution, but maybe
> I found the solution. I had ideas about some variants, but almost all time
> I had a problem with parser's shifts because all potential keywords are not
> reserved.
>
>
>
> last variant, but maybe best is using keyword WITH
>
>
>
> So the syntax can looks like
>
>
>
> CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT
> expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]
>
>
>
> What do you think about this syntax? It doesn't need any new keyword, and
> it easy to enhance it.
>
>
>
> CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);
>
>
>
> ?
>
>
>
> Regards
>
>
>
> Pavel
>
>
>
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: remi duval <remi(dot)duval(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-02-28 15:30:28
Message-ID: CAFj8pRDZ-SxOwfupyD=YhGAMKjNetWhGVkdq9RUs-44wjpmxPQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 27. 2. 2020 v 15:37 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
> Hi
>
>
>> 3) Any way to define CONSTANTs ?
>> We already talked a bit about this subject and also Gilles Darold
>> introduces it in this mailing-list topic but I'd like to insist on it.
>> I think it would be nice to have a way to say that a variable should not
>> be changed once defined.
>> Maybe it's hard to implement and can be implemented later, but I just
>> want to know if this concern is open.
>>
>
> I played little bit with it and I didn't find any nice solution, but maybe
> I found the solution. I had ideas about some variants, but almost all time
> I had a problem with parser's shifts because all potential keywords are not
> reserved.
>
> last variant, but maybe best is using keyword WITH
>
> So the syntax can looks like
>
> CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT
> expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]
>
> What do you think about this syntax? It doesn't need any new keyword, and
> it easy to enhance it.
>
> CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);
>

After some more thinking and because in other patch I support syntax CREATE
TRANSACTION VARIABLE ... I change my opinion and implemented support for
syntax CREATE IMMUTABLE VARIABLE for define constants.

See attached patch

Regards

Pavel

>
> ?
>
> Regards
>
> Pavel
>
>
>

Attachment Content-Type Size
schema-variables-20200228.patch.gz application/gzip 64.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: remi duval <remi(dot)duval(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-02-29 09:09:47
Message-ID: CAFj8pRALAZOu6bXTaz6CHox9S=OqHT-suX+LRgA4z0nzhXv4Vw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 28. 2. 2020 v 16:30 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 27. 2. 2020 v 15:37 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>>
>> Hi
>>
>>
>>> 3) Any way to define CONSTANTs ?
>>> We already talked a bit about this subject and also Gilles Darold
>>> introduces it in this mailing-list topic but I'd like to insist on it.
>>> I think it would be nice to have a way to say that a variable should not
>>> be changed once defined.
>>> Maybe it's hard to implement and can be implemented later, but I just
>>> want to know if this concern is open.
>>>
>>
>> I played little bit with it and I didn't find any nice solution, but
>> maybe I found the solution. I had ideas about some variants, but almost all
>> time I had a problem with parser's shifts because all potential keywords
>> are not reserved.
>>
>> last variant, but maybe best is using keyword WITH
>>
>> So the syntax can looks like
>>
>> CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT
>> expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]
>>
>> What do you think about this syntax? It doesn't need any new keyword, and
>> it easy to enhance it.
>>
>> CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);
>>
>
> After some more thinking and because in other patch I support syntax
> CREATE TRANSACTION VARIABLE ... I change my opinion and implemented support
> for
> syntax CREATE IMMUTABLE VARIABLE for define constants.
>

second try to fix pg_dump

Regards

Pavel

>
> See attached patch
>
> Regards
>
> Pavel
>
>
>>
>> ?
>>
>> Regards
>>
>> Pavel
>>
>>
>>

Attachment Content-Type Size
schema-variables-20200229.patch.gz application/gzip 64.6 KB

From: Asif Rehman <asifr(dot)rehman(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: remi duval <remi(dot)duval(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-03-05 14:10:49
Message-ID: CADM=Jej3onf9VK_3BfsuCpRLnXrYKp+cCY2PtahpCXRY4jG1iw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sat, Feb 29, 2020 at 2:10 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

>
>
> pá 28. 2. 2020 v 16:30 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>>
>>
>> čt 27. 2. 2020 v 15:37 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> napsal:
>>
>>>
>>> Hi
>>>
>>>
>>>> 3) Any way to define CONSTANTs ?
>>>> We already talked a bit about this subject and also Gilles Darold
>>>> introduces it in this mailing-list topic but I'd like to insist on it.
>>>> I think it would be nice to have a way to say that a variable should
>>>> not be changed once defined.
>>>> Maybe it's hard to implement and can be implemented later, but I just
>>>> want to know if this concern is open.
>>>>
>>>
>>> I played little bit with it and I didn't find any nice solution, but
>>> maybe I found the solution. I had ideas about some variants, but almost all
>>> time I had a problem with parser's shifts because all potential keywords
>>> are not reserved.
>>>
>>> last variant, but maybe best is using keyword WITH
>>>
>>> So the syntax can looks like
>>>
>>> CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT
>>> expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]
>>>
>>> What do you think about this syntax? It doesn't need any new keyword,
>>> and it easy to enhance it.
>>>
>>> CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);
>>>
>>
>> After some more thinking and because in other patch I support syntax
>> CREATE TRANSACTION VARIABLE ... I change my opinion and implemented support
>> for
>> syntax CREATE IMMUTABLE VARIABLE for define constants.
>>
>
> second try to fix pg_dump
>
> Regards
>
> Pavel
>
>
>>
>> See attached patch
>>
>> Regards
>>
>> Pavel
>>
>>
>>>
>>> ?
>>>
>>> Regards
>>>
>>> Pavel
>>>
>>>
>>>
Hi Pavel,

I have been reviewing the latest patch (schema-variables-20200229.patch.gz)
and here are few comments:

1- There is a compilation error, when compiled with --with-llvm enabled on
CentOS 7.

llvmjit_expr.c: In function ‘llvm_compile_expr’:
llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
type [enabled by default]
build_EvalXFunc(b, mod, "ExecEvalParamVariable",
^
llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
[enabled by default]
llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
type [enabled by default]
llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
[enabled by default]
llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
type [enabled by default]
llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
[enabled by default]
llvmjit_expr.c:1090:5: warning: passing argument 5 of ‘build_EvalXFuncInt’
from incompatible pointer type [enabled by default]
llvmjit_expr.c:60:21: note: expected ‘struct ExprEvalStep *’ but argument
is of type ‘LLVMValueRef’
static LLVMValueRef build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef mod,
^
llvmjit_expr.c:1092:29: error: ‘i’ undeclared (first use in this function)
LLVMBuildBr(b, opblocks[i + 1]);
^
llvmjit_expr.c:1092:29: note: each undeclared identifier is reported only
once for each function it appears in
make[2]: *** [llvmjit_expr.o] Error 1

After looking into it, it turns out that:
- parameter order was incorrect in build_EvalXFunc()
- LLVMBuildBr() is using the undeclared variable 'i' whereas it should be
using 'opno'.

2- Similarly, If the default expression is referencing a function or object,
dependency should be marked, so if the function is not dropped silently.
otherwise, a cache lookup error will come.

postgres=# create or replace function foofunc() returns timestamp as $$
begin return now(); end; $$ language plpgsql;
CREATE FUNCTION
postgres=# create schema test;
CREATE SCHEMA
postgres=# create variable test.v1 as timestamp default foofunc();
CREATE VARIABLE
postgres=# drop function foofunc();
DROP FUNCTION
postgres=# select test.v1;
ERROR: cache lookup failed for function 16437

3- Variable DEFAULT expression is apparently being evaluated at the time of
first access. whereas I think that It should be at the time of variable
creation. consider the following example:

postgres=# create variable test.v2 as timestamp default now();
CREATE VARIABLE
postgres=# select now();
now
-------------------------------
2020-03-05 12:13:29.775373+00
(1 row)
postgres=# select test.v2;
v2
----------------------------
2020-03-05 12:13:37.192317 -- I was expecting this to be earlier than the
above timestamp.
(1 row)

postgres=# select test.v2;
v2
----------------------------
2020-03-05 12:13:37.192317
(1 row)
postgres=# let test.v2 = default;
LET
postgres=# select test.v2;
v2
----------------------------
2020-03-05 12:14:07.538615
(1 row)

To continue my testing of the patch I made few fixes for the above-mentioned
comments. The patch for those changes is attached if it could be of any use.

--
Asif Rehman
Highgo Software (Canada/China/Pakistan)
URL : www.highgo.ca

Attachment Content-Type Size
sv-fixes.patch application/octet-stream 1.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Asif Rehman <asifr(dot)rehman(at)gmail(dot)com>
Cc: remi duval <remi(dot)duval(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-03-05 17:54:29
Message-ID: CAFj8pRCzjcYXTOgOoM41RwVr38mPf172_A184pPLeybA_QvqpQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 5. 3. 2020 v 15:11 odesílatel Asif Rehman <asifr(dot)rehman(at)gmail(dot)com>
napsal:

>
>
> On Sat, Feb 29, 2020 at 2:10 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>>
>>
>> pá 28. 2. 2020 v 16:30 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> napsal:
>>
>>>
>>>
>>> čt 27. 2. 2020 v 15:37 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>>> napsal:
>>>
>>>>
>>>> Hi
>>>>
>>>>
>>>>> 3) Any way to define CONSTANTs ?
>>>>> We already talked a bit about this subject and also Gilles Darold
>>>>> introduces it in this mailing-list topic but I'd like to insist on it.
>>>>> I think it would be nice to have a way to say that a variable should
>>>>> not be changed once defined.
>>>>> Maybe it's hard to implement and can be implemented later, but I just
>>>>> want to know if this concern is open.
>>>>>
>>>>
>>>> I played little bit with it and I didn't find any nice solution, but
>>>> maybe I found the solution. I had ideas about some variants, but almost all
>>>> time I had a problem with parser's shifts because all potential keywords
>>>> are not reserved.
>>>>
>>>> last variant, but maybe best is using keyword WITH
>>>>
>>>> So the syntax can looks like
>>>>
>>>> CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT
>>>> expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]
>>>>
>>>> What do you think about this syntax? It doesn't need any new keyword,
>>>> and it easy to enhance it.
>>>>
>>>> CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);
>>>>
>>>
>>> After some more thinking and because in other patch I support syntax
>>> CREATE TRANSACTION VARIABLE ... I change my opinion and implemented support
>>> for
>>> syntax CREATE IMMUTABLE VARIABLE for define constants.
>>>
>>
>> second try to fix pg_dump
>>
>> Regards
>>
>> Pavel
>>
>>
>>>
>>> See attached patch
>>>
>>> Regards
>>>
>>> Pavel
>>>
>>>
>>>>
>>>> ?
>>>>
>>>> Regards
>>>>
>>>> Pavel
>>>>
>>>>
>>>>
> Hi Pavel,
>
> I have been reviewing the latest patch (schema-variables-20200229.patch.gz)
> and here are few comments:
>
> 1- There is a compilation error, when compiled with --with-llvm enabled on
> CentOS 7.
>
> llvmjit_expr.c: In function ‘llvm_compile_expr’:
> llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
> type [enabled by default]
> build_EvalXFunc(b, mod, "ExecEvalParamVariable",
> ^
> llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
> [enabled by default]
> llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
> type [enabled by default]
> llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
> [enabled by default]
> llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
> type [enabled by default]
> llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
> [enabled by default]
> llvmjit_expr.c:1090:5: warning: passing argument 5 of ‘build_EvalXFuncInt’
> from incompatible pointer type [enabled by default]
> llvmjit_expr.c:60:21: note: expected ‘struct ExprEvalStep *’ but argument
> is of type ‘LLVMValueRef’
> static LLVMValueRef build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef
> mod,
> ^
> llvmjit_expr.c:1092:29: error: ‘i’ undeclared (first use in this function)
> LLVMBuildBr(b, opblocks[i + 1]);
> ^
> llvmjit_expr.c:1092:29: note: each undeclared identifier is reported only
> once for each function it appears in
> make[2]: *** [llvmjit_expr.o] Error 1
>
>
>
> After looking into it, it turns out that:
> - parameter order was incorrect in build_EvalXFunc()
> - LLVMBuildBr() is using the undeclared variable 'i' whereas it should be
> using 'opno'.
>
>
> 2- Similarly, If the default expression is referencing a function or
> object,
> dependency should be marked, so if the function is not dropped silently.
> otherwise, a cache lookup error will come.
>
> postgres=# create or replace function foofunc() returns timestamp as $$
> begin return now(); end; $$ language plpgsql;
> CREATE FUNCTION
> postgres=# create schema test;
> CREATE SCHEMA
> postgres=# create variable test.v1 as timestamp default foofunc();
> CREATE VARIABLE
> postgres=# drop function foofunc();
> DROP FUNCTION
> postgres=# select test.v1;
> ERROR: cache lookup failed for function 16437
>
>
Thank you for this analyze and patches. I merged them to attached patch

>
> 3- Variable DEFAULT expression is apparently being evaluated at the time of
> first access. whereas I think that It should be at the time of variable
> creation. consider the following example:
>
> postgres=# create variable test.v2 as timestamp default now();
> CREATE VARIABLE
> postgres=# select now();
> now
> -------------------------------
> 2020-03-05 12:13:29.775373+00
> (1 row)
> postgres=# select test.v2;
> v2
> ----------------------------
> 2020-03-05 12:13:37.192317 -- I was expecting this to be earlier than
> the above timestamp.
> (1 row)
>
> postgres=# select test.v2;
> v2
> ----------------------------
> 2020-03-05 12:13:37.192317
> (1 row)
> postgres=# let test.v2 = default;
> LET
> postgres=# select test.v2;
> v2
> ----------------------------
> 2020-03-05 12:14:07.538615
> (1 row)
>
>
This is expected and wanted - same behave has plpgsql variables.

CREATE OR REPLACE FUNCTION public.foo()
RETURNS void
LANGUAGE plpgsql
AS $function$
declare x timestamp default current_timestamp;
begin
raise notice '%', x;
end;
$function$

postgres=# select foo();
NOTICE: 2020-03-05 18:49:12.465054
┌─────┐
│ foo │
╞═════╡
│ │
└─────┘
(1 row)

postgres=# select foo();
NOTICE: 2020-03-05 18:49:13.255197
┌─────┐
│ foo │
╞═════╡
│ │
└─────┘
(1 row)

You can use

CREATE VARIABLE cuser AS text DEFAULT session_user;

Has not any sense to use a value from creating time

And a analogy with CREATE TABLE

CREATE TABLE fooo(a timestamp DEFAULT current_timestamp) -- there is not a
create time timestamp

I fixed buggy behave of IMMUTABLE variables

Regards

Pavel

>
> To continue my testing of the patch I made few fixes for the
> above-mentioned
> comments. The patch for those changes is attached if it could be of any
> use.
>
> --
> Asif Rehman
> Highgo Software (Canada/China/Pakistan)
> URL : www.highgo.ca
>
>

Attachment Content-Type Size
schema-variables-20200305.patch.gz application/gzip 65.0 KB

From: DUVAL REMI <REMI(dot)DUVAL(at)CHEOPS(dot)FR>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: RE: proposal: schema variables
Date: 2020-03-06 15:44:14
Message-ID: 158cad51e4004c70ab621af77edae2ee@CHG-E2K13-DC2.INTRANET.CHEOPS.FR
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hello Pavel

I tested your patch again and I think things are better now, close to perfect for me.

1) Patch review

- We can define CONSTANTs with CREATE IMMUTABLE VARIABLE … I’m really pleased with this

- The previous bug I mentioned to you by private mail (see detail below) has been fixed and a non-regression test case has been added for it.

- I’m now able to export a 12.1 database using pg_dump from the latest git HEAD (internal version 130000).

NB: the condition is “if internal_version < 130000 => don’t try to export any schema variable”.

Also I was able to test a use case for a complex Oracle package I migrated to PostgreSQL (it has a total of 194 variables and constants in it !).
The Oracle package has been migrated to a PostgreSQL schema with one routine per Oracle subprogram.
I’m able to run my business test case using schema variables on those routines and it’s giving me the expected result.

NB: Previous bug was
database1=> CREATE VARIABLE T0_var AS char(14);
CREATE VARIABLE
database1=> CREATE IMMUTABLE VARIABLE Taille_var AS numeric DEFAULT 14;
CREATE VARIABLE
database1=> LET T0_var = LPAD('999', trunc(Taille_var::NUMERIC)::INTEGER, '0');
ERROR: schema variable "taille_var" is declared IMMUTABLE
database1=> LET T0_var = LPAD('999', trunc(Taille_var::NUMERIC)::INTEGER, '0');
ERROR: variable "taille_var" has not valid content

ð It’s now fixed !

2) Regarding documentation

It’s pretty good except some small details :

- sql-createvariable.html => IMMUTABLE parameter : The value of the variable cannot be changed. => I think an article is needed here (the)

- sql-createvariable.html => ON COMMIT DROP : The ON COMMIT DROP clause specifies the bahaviour of temporary => behaviour
Also there are “tabs” between words (here between “of” and “temporary”), making the paragraph look strange.

- sql-createvariable.html => Maybe we should mention that the IMMUTABLE parameter (CREATE IMMUTABLE VARIABLE …) is the way to define global CONSTANTs, because people will look for a way to create global constants in the documentation and it would be good if they can find the CONSTANT word in it.
Also maybe it’s worth mentioning that “schema variables” relates to “global variables” (for the same purpose of people searching in the documentation).

- sql-altervariable.html => sentence “These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the variable.“ => not sure I understand this one. Isn’t it “does not do anything you could do” instead of “you couln’t do” .. but maybe it’s me

Otherwise, this is a really nice feature and I’m looking forward to have it in PostgreSQL.

Thanks a lot

Duval Rémi

De : Pavel Stehule [mailto:pavel(dot)stehule(at)gmail(dot)com]
Envoyé : jeudi 5 mars 2020 18:54
À : Asif Rehman <asifr(dot)rehman(at)gmail(dot)com>
Cc : DUVAL REMI <REMI(dot)DUVAL(at)CHEOPS(dot)FR>; PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Objet : Re: proposal: schema variables

čt 5. 3. 2020 v 15:11 odesílatel Asif Rehman <asifr(dot)rehman(at)gmail(dot)com<mailto:asifr(dot)rehman(at)gmail(dot)com>> napsal:

On Sat, Feb 29, 2020 at 2:10 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com<mailto:pavel(dot)stehule(at)gmail(dot)com>> wrote:

pá 28. 2. 2020 v 16:30 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com<mailto:pavel(dot)stehule(at)gmail(dot)com>> napsal:

čt 27. 2. 2020 v 15:37 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com<mailto:pavel(dot)stehule(at)gmail(dot)com>> napsal:

Hi

3) Any way to define CONSTANTs ?
We already talked a bit about this subject and also Gilles Darold introduces it in this mailing-list topic but I'd like to insist on it.
I think it would be nice to have a way to say that a variable should not be changed once defined.
Maybe it's hard to implement and can be implemented later, but I just want to know if this concern is open.

I played little bit with it and I didn't find any nice solution, but maybe I found the solution. I had ideas about some variants, but almost all time I had a problem with parser's shifts because all potential keywords are not reserved.

last variant, but maybe best is using keyword WITH

So the syntax can looks like

CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]

What do you think about this syntax? It doesn't need any new keyword, and it easy to enhance it.

CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);

After some more thinking and because in other patch I support syntax CREATE TRANSACTION VARIABLE ... I change my opinion and implemented support for
syntax CREATE IMMUTABLE VARIABLE for define constants.

second try to fix pg_dump

Regards

Pavel

See attached patch

Regards

Pavel

?

Regards

Pavel

Hi Pavel,

I have been reviewing the latest patch (schema-variables-20200229.patch.gz)
and here are few comments:

1- There is a compilation error, when compiled with --with-llvm enabled on
CentOS 7.

llvmjit_expr.c: In function ‘llvm_compile_expr’:
llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer type [enabled by default]
build_EvalXFunc(b, mod, "ExecEvalParamVariable",
^
llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’) [enabled by default]
llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer type [enabled by default]
llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’) [enabled by default]
llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer type [enabled by default]
llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’) [enabled by default]
llvmjit_expr.c:1090:5: warning: passing argument 5 of ‘build_EvalXFuncInt’ from incompatible pointer type [enabled by default]
llvmjit_expr.c:60:21: note: expected ‘struct ExprEvalStep *’ but argument is of type ‘LLVMValueRef’
static LLVMValueRef build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef mod,
^
llvmjit_expr.c:1092:29: error: ‘i’ undeclared (first use in this function)
LLVMBuildBr(b, opblocks[i + 1]);
^
llvmjit_expr.c:1092:29: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [llvmjit_expr.o] Error 1

After looking into it, it turns out that:
- parameter order was incorrect in build_EvalXFunc()
- LLVMBuildBr() is using the undeclared variable 'i' whereas it should be
using 'opno'.

2- Similarly, If the default expression is referencing a function or object,
dependency should be marked, so if the function is not dropped silently.
otherwise, a cache lookup error will come.

postgres=# create or replace function foofunc() returns timestamp as $$ begin return now(); end; $$ language plpgsql;
CREATE FUNCTION
postgres=# create schema test;
CREATE SCHEMA
postgres=# create variable test.v1 as timestamp default foofunc();
CREATE VARIABLE
postgres=# drop function foofunc();
DROP FUNCTION
postgres=# select test.v1;
ERROR: cache lookup failed for function 16437

Thank you for this analyze and patches. I merged them to attached patch

3- Variable DEFAULT expression is apparently being evaluated at the time of
first access. whereas I think that It should be at the time of variable
creation. consider the following example:

postgres=# create variable test.v2 as timestamp default now();
CREATE VARIABLE
postgres=# select now();
now
-------------------------------
2020-03-05 12:13:29.775373+00
(1 row)
postgres=# select test.v2;
v2
----------------------------
2020-03-05 12:13:37.192317 -- I was expecting this to be earlier than the above timestamp.
(1 row)

postgres=# select test.v2;
v2
----------------------------
2020-03-05 12:13:37.192317
(1 row)
postgres=# let test.v2 = default;
LET
postgres=# select test.v2;
v2
----------------------------
2020-03-05 12:14:07.538615
(1 row)

This is expected and wanted - same behave has plpgsql variables.

CREATE OR REPLACE FUNCTION public.foo()
RETURNS void
LANGUAGE plpgsql
AS $function$
declare x timestamp default current_timestamp;
begin
raise notice '%', x;
end;
$function$

postgres=# select foo();
NOTICE: 2020-03-05 18:49:12.465054
┌─────┐
│ foo │
╞═════╡
│ │
└─────┘
(1 row)

postgres=# select foo();
NOTICE: 2020-03-05 18:49:13.255197
┌─────┐
│ foo │
╞═════╡
│ │
└─────┘
(1 row)

You can use

CREATE VARIABLE cuser AS text DEFAULT session_user;

Has not any sense to use a value from creating time

And a analogy with CREATE TABLE

CREATE TABLE fooo(a timestamp DEFAULT current_timestamp) -- there is not a create time timestamp

I fixed buggy behave of IMMUTABLE variables

Regards

Pavel

To continue my testing of the patch I made few fixes for the above-mentioned
comments. The patch for those changes is attached if it could be of any use.

--
Asif Rehman
Highgo Software (Canada/China/Pakistan)
URL : www.highgo.ca<http://www.highgo.ca>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-03-06 18:54:35
Message-ID: CAFj8pRDaGtWaTY5PD4Hp+yuzxhuseqq=N3HMVv0hAza2srKEvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 6. 3. 2020 v 16:44 odesílatel DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr> napsal:

> Hello Pavel
>
>
>
> I tested your patch again and I think things are better now, close to
> perfect for me.
>
>
>
> *1) **Patch review*
>
>
>
> - We can define CONSTANTs with CREATE IMMUTABLE VARIABLE … I’m
> really pleased with this
>
> - The previous bug I mentioned to you by private mail (see
> detail below) has been fixed and a non-regression test case has been added
> for it.
>
> - I’m now able to export a 12.1 database using pg_dump from the
> latest git HEAD (internal version 130000).
>
> NB: the condition is “if internal_version < 130000 => don’t try to export
> any schema variable”.
>
>
>
> Also I was able to test a use case for a complex Oracle package I migrated
> to PostgreSQL (it has a total of 194 variables and constants in it !).
>
> The Oracle package has been migrated to a PostgreSQL schema with one
> routine per Oracle subprogram.
>
> I’m able to run my business test case using schema variables on those
> routines and it’s giving me the expected result.
>
>
>
> NB: Previous bug was
>
> database1=> CREATE VARIABLE T0_var AS char(14);
> CREATE VARIABLE
> database1=> CREATE IMMUTABLE VARIABLE Taille_var AS numeric DEFAULT 14;
> CREATE VARIABLE
> database1=> LET T0_var = LPAD('999', trunc(Taille_var::NUMERIC)::INTEGER,
> '0');
> *ERROR: schema variable "taille_var" is declared IMMUTABLE*
> database1=> LET T0_var = LPAD('999', trunc(Taille_var::NUMERIC)::INTEGER,
> '0');
> *ERROR: variable "taille_var" has not valid content*
>
> ð It’s now fixed !
>
>
>
> *2) **Regarding documentation *
>
>
>
> It’s pretty good except some small details :
>
> - sql-createvariable.html => IMMUTABLE parameter : The value of
> *the* variable cannot be changed. => I think an article is needed here
> (the)
>

fixed

- sql-createvariable.html => ON COMMIT DROP : The ON COMMIT DROP
> clause specifies the bahaviour of temporary => behaviour
> Also there are “tabs” between words (here between “of” and “temporary”),
> making the paragraph look strange.
>

fixed

> - sql-createvariable.html => Maybe we should mention that the
> IMMUTABLE parameter (CREATE IMMUTABLE VARIABLE …) is the way to define
> global CONSTANTs, because people will look for a way to create global
> constants in the documentation and it would be good if they can find the
> CONSTANT word in it.
> Also maybe it’s worth mentioning that “schema variables” relates to
> “global variables” (for the same purpose of people searching in the
> documentation).
>
probably it should be somewhere
https://www.postgresql.org/docs/current/plpgsql-porting.html

I wrote note there

> - sql-altervariable.html => sentence “These restrictions enforce
> that altering the owner doesn't do anything you couldn't do by dropping and
> recreating the variable.“ => not sure I understand this one. Isn’t it
> “does not do anything you could do” instead of “you couln’t do” .. but
> maybe it’s me
>
This sentence is used more times (from alter_view0

To alter the owner, you must also be a direct or indirect member of the new
owning role, and that role must have <literal>CREATE</literal> privilege
on
the view's schema. (These restrictions enforce that altering the owner
doesn't do anything you couldn't do by dropping and recreating the view.
However, a superuser can alter ownership of any view anyway.)

>
>
> Otherwise, this is a really nice feature and I’m looking forward to have
> it in PostgreSQL.
>

Thank you very much

updated patch attached

>
> Thanks a lot
>
>
>
> Duval Rémi
>
>
>
> *De :* Pavel Stehule [mailto:pavel(dot)stehule(at)gmail(dot)com]
> *Envoyé :* jeudi 5 mars 2020 18:54
> *À :* Asif Rehman <asifr(dot)rehman(at)gmail(dot)com>
> *Cc :* DUVAL REMI <REMI(dot)DUVAL(at)CHEOPS(dot)FR>; PostgreSQL Hackers <
> pgsql-hackers(at)lists(dot)postgresql(dot)org>
> *Objet :* Re: proposal: schema variables
>
>
>
>
>
>
>
> čt 5. 3. 2020 v 15:11 odesílatel Asif Rehman <asifr(dot)rehman(at)gmail(dot)com>
> napsal:
>
>
>
>
>
> On Sat, Feb 29, 2020 at 2:10 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
>
>
>
>
> pá 28. 2. 2020 v 16:30 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>
>
>
>
> čt 27. 2. 2020 v 15:37 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>
>
> Hi
>
>
>
>
> 3) Any way to define CONSTANTs ?
> We already talked a bit about this subject and also Gilles Darold
> introduces it in this mailing-list topic but I'd like to insist on it.
> I think it would be nice to have a way to say that a variable should not
> be changed once defined.
> Maybe it's hard to implement and can be implemented later, but I just want
> to know if this concern is open.
>
>
>
> I played little bit with it and I didn't find any nice solution, but maybe
> I found the solution. I had ideas about some variants, but almost all time
> I had a problem with parser's shifts because all potential keywords are not
> reserved.
>
>
>
> last variant, but maybe best is using keyword WITH
>
>
>
> So the syntax can looks like
>
>
>
> CREATE [ TEMP ] VARIABLE varname [ AS ] type [ NOT NULL ] [ DEFAULT
> expression ] [ WITH [ OPTIONS ] '(' ... ')' ] ]
>
>
>
> What do you think about this syntax? It doesn't need any new keyword, and
> it easy to enhance it.
>
>
>
> CREATE VARIABLE foo AS int DEFAULT 10 WITH OPTIONS ( CONSTANT);
>
>
>
> After some more thinking and because in other patch I support syntax
> CREATE TRANSACTION VARIABLE ... I change my opinion and implemented support
> for
>
> syntax CREATE IMMUTABLE VARIABLE for define constants.
>
>
>
> second try to fix pg_dump
>
>
>
> Regards
>
>
>
> Pavel
>
>
>
>
>
> See attached patch
>
>
>
> Regards
>
>
>
> Pavel
>
>
>
>
>
> ?
>
>
>
> Regards
>
>
>
> Pavel
>
>
>
>
>
>
>
> Hi Pavel,
>
>
>
> I have been reviewing the latest patch (schema-variables-20200229.patch.gz)
>
> and here are few comments:
>
>
>
> 1- There is a compilation error, when compiled with --with-llvm enabled on
>
> CentOS 7.
>
>
>
> llvmjit_expr.c: In function ‘llvm_compile_expr’:
>
> llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
> type [enabled by default]
>
> build_EvalXFunc(b, mod, "ExecEvalParamVariable",
>
> ^
>
> llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
> [enabled by default]
>
> llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
> type [enabled by default]
>
> llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
> [enabled by default]
>
> llvmjit_expr.c:1090:5: warning: initialization from incompatible pointer
> type [enabled by default]
>
> llvmjit_expr.c:1090:5: warning: (near initialization for ‘(anonymous)[0]’)
> [enabled by default]
>
> llvmjit_expr.c:1090:5: warning: passing argument 5 of ‘build_EvalXFuncInt’
> from incompatible pointer type [enabled by default]
>
> llvmjit_expr.c:60:21: note: expected ‘struct ExprEvalStep *’ but argument
> is of type ‘LLVMValueRef’
>
> static LLVMValueRef build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef
> mod,
>
> ^
>
> llvmjit_expr.c:1092:29: error: ‘i’ undeclared (first use in this function)
>
> LLVMBuildBr(b, opblocks[i + 1]);
>
> ^
>
> llvmjit_expr.c:1092:29: note: each undeclared identifier is reported only
> once for each function it appears in
>
> make[2]: *** [llvmjit_expr.o] Error 1
>
>
>
>
>
> After looking into it, it turns out that:
>
> - parameter order was incorrect in build_EvalXFunc()
>
> - LLVMBuildBr() is using the undeclared variable 'i' whereas it should be
>
> using 'opno'.
>
>
>
>
>
> 2- Similarly, If the default expression is referencing a function or
> object,
>
> dependency should be marked, so if the function is not dropped silently.
>
> otherwise, a cache lookup error will come.
>
>
>
> postgres=# create or replace function foofunc() returns timestamp as $$
> begin return now(); end; $$ language plpgsql;
>
> CREATE FUNCTION
>
> postgres=# create schema test;
>
> CREATE SCHEMA
>
> postgres=# create variable test.v1 as timestamp default foofunc();
>
> CREATE VARIABLE
>
> postgres=# drop function foofunc();
>
> DROP FUNCTION
>
> postgres=# select test.v1;
>
> ERROR: cache lookup failed for function 16437
>
>
>
> Thank you for this analyze and patches. I merged them to attached patch
>
>
>
>
>
>
>
>
>
> 3- Variable DEFAULT expression is apparently being evaluated at the time of
>
> first access. whereas I think that It should be at the time of variable
>
> creation. consider the following example:
>
>
>
> postgres=# create variable test.v2 as timestamp default now();
>
> CREATE VARIABLE
>
> postgres=# select now();
>
> now
>
> -------------------------------
>
> 2020-03-05 12:13:29.775373+00
>
> (1 row)
>
> postgres=# select test.v2;
>
> v2
>
> ----------------------------
>
> 2020-03-05 12:13:37.192317 -- I was expecting this to be earlier than the
> above timestamp.
>
> (1 row)
>
>
>
> postgres=# select test.v2;
>
> v2
>
> ----------------------------
>
> 2020-03-05 12:13:37.192317
>
> (1 row)
>
> postgres=# let test.v2 = default;
>
> LET
>
> postgres=# select test.v2;
>
> v2
>
> ----------------------------
>
> 2020-03-05 12:14:07.538615
>
> (1 row)
>
>
>
> This is expected and wanted - same behave has plpgsql variables.
>
>
>
> CREATE OR REPLACE FUNCTION public.foo()
> RETURNS void
> LANGUAGE plpgsql
> AS $function$
> declare x timestamp default current_timestamp;
> begin
> raise notice '%', x;
> end;
> $function$
>
>
>
> postgres=# select foo();
> NOTICE: 2020-03-05 18:49:12.465054
> ┌─────┐
> │ foo │
> ╞═════╡
> │ │
> └─────┘
> (1 row)
>
> postgres=# select foo();
> NOTICE: 2020-03-05 18:49:13.255197
> ┌─────┐
> │ foo │
> ╞═════╡
> │ │
> └─────┘
> (1 row)
>
>
>
> You can use
>
>
>
> CREATE VARIABLE cuser AS text DEFAULT session_user;
>
>
>
> Has not any sense to use a value from creating time
>
>
>
> And a analogy with CREATE TABLE
>
>
>
> CREATE TABLE fooo(a timestamp DEFAULT current_timestamp) -- there is not a
> create time timestamp
>
>
>
>
>
> I fixed buggy behave of IMMUTABLE variables
>
>
>
> Regards
>
>
>
> Pavel
>
>
>
>
>
>
>
> To continue my testing of the patch I made few fixes for the
> above-mentioned
>
> comments. The patch for those changes is attached if it could be of any
> use.
>
>
>
> --
>
> Asif Rehman
>
> Highgo Software (Canada/China/Pakistan)
> URL : www.highgo.ca
>
>

Attachment Content-Type Size
doc.patch text/x-patch 2.4 KB
schema-variables-20200306.patch.gz application/gzip 65.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-03-07 21:15:15
Message-ID: CAFj8pRD8T5os8Yym+mKjHKQzntS8fQkS+GoK8sKQmvHgF_z=hg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I fixed the some ugly parts of this patch - now the LET x = DEFAULT, LET x
= NULL is processed by more usual way.
Statement LET is doesn't switch between STMT_UTILITY and STMT_PLAN_UTILITY
like before. It is only STMT_PLAN_UTILITY statement.

Regards

Pavel

Attachment Content-Type Size
schema-variables-20200307.patch.gz application/gzip 65.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-03-08 18:12:07
Message-ID: CAFj8pRDepLHgceFPqNYTtkx0DgbdxsRP=G3+yL8mCW0K8=81Tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 7. 3. 2020 v 22:15 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> I fixed the some ugly parts of this patch - now the LET x = DEFAULT, LET x
> = NULL is processed by more usual way.
> Statement LET is doesn't switch between STMT_UTILITY and STMT_PLAN_UTILITY
> like before. It is only STMT_PLAN_UTILITY statement.
>

I did some cleaning - I mainly replaced CMD_PLAN_UTILITY by CMD_LET because
there is not another similar statement in queue.

Regards

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20200308.patch.gz application/gzip 65.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-03-13 18:44:33
Message-ID: CAFj8pRDnxjje-FAc9bRFtt3Di=ZhGi6DOVAEZnHDesfR8zmN-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 8. 3. 2020 v 19:12 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> so 7. 3. 2020 v 22:15 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> I fixed the some ugly parts of this patch - now the LET x = DEFAULT, LET
>> x = NULL is processed by more usual way.
>> Statement LET is doesn't switch between STMT_UTILITY and
>> STMT_PLAN_UTILITY like before. It is only STMT_PLAN_UTILITY statement.
>>
>
> I did some cleaning - I mainly replaced CMD_PLAN_UTILITY by CMD_LET
> because there is not another similar statement in queue.
>

another cleaning - I repleaced CMD_LET by CMD_SELECT_UTILITY. This name is
more illustrative, and little bit cleaned code.

CMD_SELECT_UTILITY is mix of CMD_SELECT and CMD_UTILITY. It allows PREPARE
and parametrizations like CMD_SELECT. But execution is like CMD_UTILITY by
own utility routine with explicit dest receiver setting. This design
doesn't need to introduce new executor and planner nodes (like ModifyTable
and ModifyTablePath).

Regards

Pavel

> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>

Attachment Content-Type Size
schema-variables-20200313.patch.gz application/gzip 65.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-03-18 05:58:30
Message-ID: CAFj8pRAdag+uS9EO0k0EpWMeOHY_WOJuh7aFnmSwpJi-V-L0fQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh patch - rebase and fix issue reported by Remi - broken usage CREATE
VARIABLE inside PLpgSQL

Regards

Pavel

Attachment Content-Type Size
schema-variables-20200318.patch.gz application/gzip 66.3 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-03-20 07:18:45
Message-ID: CAFj8pRC_sMuOjUn=ikNavENVRqFZahBrAiAqiMfjMf1kUj7+aw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 19. 3. 2020 v 10:43 odesílatel DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr> napsal:

> Hello
>
>
>
> I played around with the ALTER VARIABLE statement to make sure it’s OK and
> it seems fine to me.
>
>
>
> Another last thing before commiting.
>
>
>
> I agree with Thomas Vondra, that this part might/should be simplified :
>
>
>
> [ { ON COMMIT DROP | ON { TRANSACTIONAL | TRANSACTION } END RESET } ]
>
>
>
> I would only allow “ON TRANSACTION END RESET”.
>
> I think we don’t need both here.
>
> Philippe Beaudoin was indeed talking about the TRANSACTIONAL keyword, but
> that would have make sense (and I think that’s what he meant) , if you
> could do something like “CREATE [NON] TRANSACTIONAL VARIABLE …”.
>
> But here I don’t think that the ON TRANSACTIONAL END RESET has any sense
> in English, and it only complicates the syntax.
>
>
>
> Maybe Thomas Vondra (if it’s him) would be more inclined to commit the
> patch if it has this more simple syntax has he requested.
>
>
>
> What do you think ?
>

I removed TRANSACTIONAL from this clause, see attachement change.diff

Updated patch attached.

I hope it would be the last touch, making it fully ready for a commiter.
>

Thank you very much for review and testing

Pavel

>

Attachment Content-Type Size
change.diff text/x-patch 2.0 KB
schema-variables-20200320.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-03-20 08:28:22
Message-ID: CAFj8pRA9kLgW24cX+O7XUajepQLR+MjvRDC=02O8cBcB9=0wKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 20. 3. 2020 v 8:18 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 19. 3. 2020 v 10:43 odesílatel DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>
> napsal:
>
>> Hello
>>
>>
>>
>> I played around with the ALTER VARIABLE statement to make sure it’s OK
>> and it seems fine to me.
>>
>>
>>
>> Another last thing before commiting.
>>
>>
>>
>> I agree with Thomas Vondra, that this part might/should be simplified :
>>
>>
>>
>> [ { ON COMMIT DROP | ON { TRANSACTIONAL | TRANSACTION } END RESET } ]
>>
>>
>>
>> I would only allow “ON TRANSACTION END RESET”.
>>
>> I think we don’t need both here.
>>
>> Philippe Beaudoin was indeed talking about the TRANSACTIONAL keyword, but
>> that would have make sense (and I think that’s what he meant) , if you
>> could do something like “CREATE [NON] TRANSACTIONAL VARIABLE …”.
>>
>> But here I don’t think that the ON TRANSACTIONAL END RESET has any sense
>> in English, and it only complicates the syntax.
>>
>>
>>
>> Maybe Thomas Vondra (if it’s him) would be more inclined to commit the
>> patch if it has this more simple syntax has he requested.
>>
>>
>>
>> What do you think ?
>>
>
> I removed TRANSACTIONAL from this clause, see attachement change.diff
>
> Updated patch attached.
>
> I hope it would be the last touch, making it fully ready for a commiter.
>>
>
> Thank you very much for review and testing
>

documentation fix

> Pavel
>
>>

Attachment Content-Type Size
schema-variables-20200320-2.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-03-22 07:40:33
Message-ID: CAFj8pRBS-9mMkTMns=95bWJ3xr8rOM0eX_=YixrqD-97UEVFOA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20200322.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-04-10 17:30:47
Message-ID: CAFj8pRBoGBKopkiTa4ki3dMgy-cSTRZ-BQPKOq7=Tk0SSNsowA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase

Regards

Pavel

ne 22. 3. 2020 v 8:40 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> rebase
>
> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20200310.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-05-21 10:10:15
Message-ID: CAFj8pRBCiWn12H9FHymYs17fk68nRd9Xpn+SYf18TLdb2YSUrQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

just rebase without any other changes

Regards

Pavel


From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-05-21 11:34:44
Message-ID: CAA4eK1JV-Ox0oRFdXnPqXSzM84wTR5QFkRzCpNVF_+0FNjS5Mg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, May 21, 2020 at 3:41 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> Hi
>
> just rebase without any other changes
>

You seem to forget attaching the rebased patch.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-05-21 12:49:57
Message-ID: CAFj8pRByCCcgDkeXyafAnH6LgxtAyCVwg6yfJAhyTY6GLscfZg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 21. 5. 2020 v 13:34 odesílatel Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
napsal:

> On Thu, May 21, 2020 at 3:41 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> >
> > Hi
> >
> > just rebase without any other changes
> >
>
> You seem to forget attaching the rebased patch.
>

I am sorry

attached.

Pavel

> --
> With Regards,
> Amit Kapila.
> EnterpriseDB: http://www.enterprisedb.com
>

Attachment Content-Type Size
schema-variables-20200521.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "phb07(at)apra(dot)asso(dot)fr" <phb07(at)apra(dot)asso(dot)fr>
Subject: Re: proposal: schema variables
Date: 2020-07-05 13:33:34
Message-ID: CAFj8pRBvUonC_ug3F=w1Q55Dp=DggojvAeL7Vmh14Q-WhFHxzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 21. 5. 2020 v 14:49 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 21. 5. 2020 v 13:34 odesílatel Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
> napsal:
>
>> On Thu, May 21, 2020 at 3:41 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> wrote:
>> >
>> > Hi
>> >
>> > just rebase without any other changes
>> >
>>
>> You seem to forget attaching the rebased patch.
>>
>
> I am sorry
>
> attached.
>

fresh rebase

Regards

Pavel

> Pavel
>
>
>> --
>> With Regards,
>> Amit Kapila.
>> EnterpriseDB: http://www.enterprisedb.com
>>
>

Attachment Content-Type Size
schema-variables-20200705.patch.gz application/gzip 66.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-07-06 08:17:07
Message-ID: CAFj8pRDj72P-f=SUygtOXnTOBQ0RzmL_fN=wLfaCzcbPVpGgzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 5. 7. 2020 v 15:33 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 21. 5. 2020 v 14:49 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>>
>>
>> čt 21. 5. 2020 v 13:34 odesílatel Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
>> napsal:
>>
>>> On Thu, May 21, 2020 at 3:41 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>>> wrote:
>>> >
>>> > Hi
>>> >
>>> > just rebase without any other changes
>>> >
>>>
>>> You seem to forget attaching the rebased patch.
>>>
>>
>> I am sorry
>>
>> attached.
>>
>
> fresh rebase
>

fix test build

Regards

Pavel

> Regards
>
> Pavel
>
>
>> Pavel
>>
>>
>>> --
>>> With Regards,
>>> Amit Kapila.
>>> EnterpriseDB: http://www.enterprisedb.com
>>>
>>

Attachment Content-Type Size
schema-variables-20200706.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-07-11 04:44:24
Message-ID: CAFj8pRDD2GQaJ_iDT4vSVe658+oHRXU2S2af7Y1-it9jaP8VFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 6. 7. 2020 v 10:17 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> ne 5. 7. 2020 v 15:33 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>>
>>
>> čt 21. 5. 2020 v 14:49 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>> napsal:
>>
>>>
>>>
>>> čt 21. 5. 2020 v 13:34 odesílatel Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
>>> napsal:
>>>
>>>> On Thu, May 21, 2020 at 3:41 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
>>>> wrote:
>>>> >
>>>> > Hi
>>>> >
>>>> > just rebase without any other changes
>>>> >
>>>>
>>>> You seem to forget attaching the rebased patch.
>>>>
>>>
>>> I am sorry
>>>
>>> attached.
>>>
>>
>> fresh rebase
>>
>
> fix test build
>

rebase

Pavel

> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>>
>>> Pavel
>>>
>>>
>>>> --
>>>> With Regards,
>>>> Amit Kapila.
>>>> EnterpriseDB: http://www.enterprisedb.com
>>>>
>>>

Attachment Content-Type Size
schema-variables-20200711.patch.gz application/gzip 66.0 KB

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-09-24 03:56:37
Message-ID: 20200924035637.GF28585@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sat, Jul 11, 2020 at 06:44:24AM +0200, Pavel Stehule wrote:
> rebase

Per the CF bot, this needs an extra rebase as it does not apply
anymore. This has not attracted much the attention of committers as
well.
--
Michael


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-09-24 03:58:55
Message-ID: CAFj8pRAFktynx5wkanv5SRuzXkZgXu77XpVACiSE=v7i1xHFbw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 24. 9. 2020 v 5:56 odesílatel Michael Paquier <michael(at)paquier(dot)xyz>
napsal:

> On Sat, Jul 11, 2020 at 06:44:24AM +0200, Pavel Stehule wrote:
> > rebase
>
> Per the CF bot, this needs an extra rebase as it does not apply
> anymore. This has not attracted much the attention of committers as
> well.
>

I'll fix it today

--
> Michael
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-09-24 18:49:50
Message-ID: CAFj8pRA=bn_g5T2AZduy5gNOQoOnUJ+pMHmnRMHi6mR0n=TAsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 24. 9. 2020 v 5:58 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 24. 9. 2020 v 5:56 odesílatel Michael Paquier <michael(at)paquier(dot)xyz>
> napsal:
>
>> On Sat, Jul 11, 2020 at 06:44:24AM +0200, Pavel Stehule wrote:
>> > rebase
>>
>> Per the CF bot, this needs an extra rebase as it does not apply
>> anymore. This has not attracted much the attention of committers as
>> well.
>>
>
> I'll fix it today
>

fixed patch attached

Regards

Pavel

> --
>> Michael
>>
>

Attachment Content-Type Size
schema-variables-20200924.patch.gz application/gzip 66.1 KB

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-10-01 03:38:24
Message-ID: 20201001033824.GC8130@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Sep 24, 2020 at 08:49:50PM +0200, Pavel Stehule wrote:
> fixed patch attached

It looks like there are again conflicts within setrefs.c.
--
Michael


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-10-01 05:08:38
Message-ID: CAFj8pRC9de05HSb4tEHDUwJ98+4Wh30W-rJrNOPnTz6ARcv0Fw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 1. 10. 2020 v 5:38 odesílatel Michael Paquier <michael(at)paquier(dot)xyz>
napsal:

> On Thu, Sep 24, 2020 at 08:49:50PM +0200, Pavel Stehule wrote:
> > fixed patch attached
>
> It looks like there are again conflicts within setrefs.c.
>

fresh patch

Regards

Pavel

--
> Michael
>

Attachment Content-Type Size
schema-variables-20201001.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-11-10 18:45:26
Message-ID: CAFj8pRBC5Wz1xHKKBmKsM0xYN0+PdSZ5oXPsk5SZt+VprdUW3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 1. 10. 2020 v 7:08 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 1. 10. 2020 v 5:38 odesílatel Michael Paquier <michael(at)paquier(dot)xyz>
> napsal:
>
>> On Thu, Sep 24, 2020 at 08:49:50PM +0200, Pavel Stehule wrote:
>> > fixed patch attached
>>
>> It looks like there are again conflicts within setrefs.c.
>>
>
> fresh patch
>

rebase

> Regards
>
> Pavel
>
> --
>> Michael
>>
>

Attachment Content-Type Size
schema-variables-20201110.patch.gz application/gzip 66.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-12-19 06:57:35
Message-ID: CAFj8pRAh4pzMoZrKCLt9h+Lr2L=vhgs2PjAF45uLbp_7sijM5w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

only rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20201219.patch.gz application/gzip 66.0 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-12-26 04:52:44
Message-ID: CAFj8pRA-kxQ1oErcuDeUKYsrgwB5XGLhquatwxOe3dCVy1gcyQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 19. 12. 2020 v 7:57 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> only rebase
>

rebase and comments fixes

Regards

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20201222.patch.gz application/gzip 66.2 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-12-26 06:18:21
Message-ID: 51a9a68e8a998d04df17417d45c1dbd4@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2020-12-26 05:52, Pavel Stehule wrote:
> so 19. 12. 2020 v 7:57 odesílatel Pavel Stehule
> <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
> [schema-variables-20201222.patch.gz (~]
>
>> Hi
>>
>> only rebase
>>
>
> rebase and comments fixes
>

Hi Pavel,

This file is the exact same as the file you sent Tuesday. Is it a
mistake?


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2020-12-26 06:23:58
Message-ID: CAFj8pRBbt2xhY9PyabOY0ZN+Aig6ee3oCon-DM9qi0Uw_3qfbw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 26. 12. 2020 v 7:18 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> On 2020-12-26 05:52, Pavel Stehule wrote:
> > so 19. 12. 2020 v 7:57 odesílatel Pavel Stehule
> > <pavel(dot)stehule(at)gmail(dot)com>
> > napsal:
> > [schema-variables-20201222.patch.gz (~]
> >
> >> Hi
> >>
> >> only rebase
> >>
> >
> > rebase and comments fixes
> >
>
> Hi Pavel,
>
> This file is the exact same as the file you sent Tuesday. Is it a
> mistake?
>

It is the same. Unfortunately, it was sent in an isolated thread, and
commitfest applications didn't find the latest version. I tried to attach
new thread to the commitfest application, but without success.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-01 08:45:13
Message-ID: CAFj8pRDSa52J7kPmCYXgq1BBbu3YBXwpdSOVpjgU=hnE2k04Cw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20210101.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-08 06:20:50
Message-ID: CAFj8pRD+QiWOoPrFk2NnPs3t5Eaf4X=aGRV-9ww11cnPP+fV4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

just rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20200108.patch.gz application/gzip 65.7 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-08 17:54:55
Message-ID: bdeb7611c6dbf22226c302bcc01d178b@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2021-01-08 07:20, Pavel Stehule wrote:
> Hi
>
> just rebase
>
> [schema-variables-20200108.patch]

Hey Pavel,

My gcc 8.3.0 compile says:
(on debian 10/Buster)

utility.c: In function ‘CreateCommandTag’:
utility.c:2332:8: warning: this statement may fall through
[-Wimplicit-fallthrough=]
tag = CMDTAG_SELECT;
~~~~^~~~~~~~~~~~~~~
utility.c:2334:3: note: here
case T_LetStmt:
^~~~

compile, check, check-world, runs without further problem.

I also changed a few typos/improvements in the documentation, see
attached.

One thing I wasn't sure of: I have assumed that
ON TRANSACTIONAL END RESET

should be
ON TRANSACTION END RESET

and changed it accordingly, please double-check.

Erik Rijkers

Attachment Content-Type Size
create_variable.sgml.20210108.diff text/x-diff 4.6 KB
discard.sgml.20210108.diff text/x-diff 299 bytes
drop_variable.sgml.20210108.diff text/x-diff 674 bytes
let.sgml.20210108.diff text/x-diff 1.1 KB
plpgsql.sgml.20210108.diff text/x-diff 845 bytes

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-10 16:54:48
Message-ID: CAFj8pRCGTjqHvH9oeiSf4T6Bydhk9pm033DxxibgF+B7SHC6MQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 8. 1. 2021 v 18:54 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> On 2021-01-08 07:20, Pavel Stehule wrote:
> > Hi
> >
> > just rebase
> >
> > [schema-variables-20200108.patch]
>
> Hey Pavel,
>
> My gcc 8.3.0 compile says:
> (on debian 10/Buster)
>
> utility.c: In function ‘CreateCommandTag’:
> utility.c:2332:8: warning: this statement may fall through
> [-Wimplicit-fallthrough=]
> tag = CMDTAG_SELECT;
> ~~~~^~~~~~~~~~~~~~~
> utility.c:2334:3: note: here
> case T_LetStmt:
> ^~~~
>

yes, there was an error from the last rebase. Fixed

>
> compile, check, check-world, runs without further problem.
>
> I also changed a few typos/improvements in the documentation, see
> attached.
>
> One thing I wasn't sure of: I have assumed that
> ON TRANSACTIONAL END RESET
>
> should be
> ON TRANSACTION END RESET
>
> and changed it accordingly, please double-check.
>

It looks well, I merged these changes to patch. Thank you very much for
these corectures

Updated patch attached

Regards

Pavel

>
> Erik Rijkers
>

Attachment Content-Type Size
schema-variables-20210110.patch.gz application/gzip 65.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-14 06:35:29
Message-ID: CAFj8pRAzNDhFgbZnT0T0mJ7ygA1Qje1Hc0TiKwXM8++kGooPYg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20210114.patch.gz application/gzip 65.6 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-14 09:24:27
Message-ID: 89817942c99da01cd5e7850fe418436b@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2021-01-14 07:35, Pavel Stehule wrote:
> [schema-variables-20210114.patch.gz]

Build is fine. My (small) list of tests run OK.

I did notice a few more documentation peculiarities:

'The PostgreSQL has schema variables' should be
'PostgreSQL has schema variables'

A link to the LET command should be added to the 'See Also' of the
CREATE VARIABLE, ALTER VARIABLE, and DROP VARIABLE pages. (After all,
the LET command is the most interesting)
Similarly, an ALTER VARIABLE link should be added to the 'See Also'
section of LET.

Somehow, the sgml in the doc files causes too large spacing in the html,
example:
I copy from the LET html:
'if that is defined. If no explicit'
(6 spaces between 'defined.' and 'If')
Can you have a look? Sorry - I can't find the cause. It occurs on a
few more places in the newly added sgml/html. The unwanted spaces are
visible also in the pdf.
(firefox 78.6.1, debian)

Thanks,

Erik Rijkers


From: Josef Šimánek <josef(dot)simanek(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-14 10:31:33
Message-ID: CAFp7QwqnqAHM1HtmBjJCjrnvWnP78Kk-20G4pk7Xo=PbxnBB0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

I did some testing locally. All runs smoothly, compiled without warning.

Later on (once merged) it would be nice to write down a documentation
page for the whole feature as a set next to documented individual
commands.
It took me a few moments to understand how this works.

I was looking how to create variable with non default value in one
command, but if I understand it correctly, that's not the purpose.
Variable lives in a schema with default value, but you can set it per
session via LET.

Thus "CREATE VARIABLE" statement should not be usually part of
"classic" queries, but it should be threatened more like TABLE or
other DDL statements.

On the other side LET is there to use the variable in "classic" queries.

Does that make sense? Feel free to ping me if any help with
documentation would be needed. I can try to prepare an initial
variables guide once I'll ensure I do understand this feature well.

PS: Now it is clear to me why it is called "schema variables", not
"session variables".

čt 14. 1. 2021 v 7:36 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> napsal:
>
> Hi
>
> rebase
>
> Regards
>
> Pavel
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-18 09:50:25
Message-ID: CAFj8pRBarjJYfkN-0-i=JRZJ4PTOYC+K7XgAhfdDqWGqRiPkyw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 14. 1. 2021 v 10:24 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> On 2021-01-14 07:35, Pavel Stehule wrote:
> > [schema-variables-20210114.patch.gz]
>
>
> Build is fine. My (small) list of tests run OK.
>
> I did notice a few more documentation peculiarities:
>
>
> 'The PostgreSQL has schema variables' should be
> 'PostgreSQL has schema variables'
>
>
fixed

> A link to the LET command should be added to the 'See Also' of the
> CREATE VARIABLE, ALTER VARIABLE, and DROP VARIABLE pages. (After all,
> the LET command is the most interesting)
> Similarly, an ALTER VARIABLE link should be added to the 'See Also'
> section of LET.
>

fixed

>
> Somehow, the sgml in the doc files causes too large spacing in the html,
> example:
> I copy from the LET html:
> 'if that is defined. If no explicit'
> (6 spaces between 'defined.' and 'If')
> Can you have a look? Sorry - I can't find the cause. It occurs on a
> few more places in the newly added sgml/html. The unwanted spaces are
> visible also in the pdf.
>

Should be fixed in the last version. Probably there were some problems with
invisible white chars.

Thank you for check

Pavel

> (firefox 78.6.1, debian)
>
>
> Thanks,
>
> Erik Rijkers
>
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josef Šimánek <josef(dot)simanek(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-18 09:57:51
Message-ID: CAFj8pRCQev+-zHvVTnYYdhsujUsFY=Dxd_RycAC5WQeWE+gTFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

čt 14. 1. 2021 v 11:31 odesílatel Josef Šimánek <josef(dot)simanek(at)gmail(dot)com>
napsal:

> I did some testing locally. All runs smoothly, compiled without warning.
>
> Later on (once merged) it would be nice to write down a documentation
> page for the whole feature as a set next to documented individual
> commands.
> It took me a few moments to understand how this works.
>
> I was looking how to create variable with non default value in one
> command, but if I understand it correctly, that's not the purpose.
> Variable lives in a schema with default value, but you can set it per
> session via LET.
>
> Thus "CREATE VARIABLE" statement should not be usually part of
> "classic" queries, but it should be threatened more like TABLE or
> other DDL statements.
>
> On the other side LET is there to use the variable in "classic" queries.
>
> Does that make sense? Feel free to ping me if any help with
> documentation would be needed. I can try to prepare an initial
> variables guide once I'll ensure I do understand this feature well.
>

I invite any help with doc. Maybe there can be page in section advanced
features

https://www.postgresql.org/docs/current/tutorial-advanced.html

Regards

Pavel

>
> PS: Now it is clear to me why it is called "schema variables", not
> "session variables".
>
> čt 14. 1. 2021 v 7:36 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
> >
> > Hi
> >
> > rebase
> >
> > Regards
> >
> > Pavel
> >
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-18 09:59:27
Message-ID: CAFj8pRDqdWdCULxd5asbKs5C4e9kT2TuKBkR5L-e1=hP5wF2uw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 18. 1. 2021 v 10:50 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> čt 14. 1. 2021 v 10:24 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:
>
>> On 2021-01-14 07:35, Pavel Stehule wrote:
>> > [schema-variables-20210114.patch.gz]
>>
>>
>> Build is fine. My (small) list of tests run OK.
>>
>> I did notice a few more documentation peculiarities:
>>
>>
>> 'The PostgreSQL has schema variables' should be
>> 'PostgreSQL has schema variables'
>>
>>
> fixed
>
>
>> A link to the LET command should be added to the 'See Also' of the
>> CREATE VARIABLE, ALTER VARIABLE, and DROP VARIABLE pages. (After all,
>> the LET command is the most interesting)
>> Similarly, an ALTER VARIABLE link should be added to the 'See Also'
>> section of LET.
>>
>
> fixed
>
>
>>
>> Somehow, the sgml in the doc files causes too large spacing in the html,
>> example:
>> I copy from the LET html:
>> 'if that is defined. If no explicit'
>> (6 spaces between 'defined.' and 'If')
>> Can you have a look? Sorry - I can't find the cause. It occurs on a
>> few more places in the newly added sgml/html. The unwanted spaces are
>> visible also in the pdf.
>>
>
> Should be fixed in the last version. Probably there were some problems
> with invisible white chars.
>
> Thank you for check
>
> Pavel
>
>
>
>> (firefox 78.6.1, debian)
>>
>
and here is the patch

Regards

Pavel

>>
>> Thanks,
>>
>> Erik Rijkers
>>
>>
>>

Attachment Content-Type Size
schema-variables-20200118.patch.gz application/gzip 65.6 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-18 14:24:15
Message-ID: 56ca532c37eb0b540961f74a7bd5db39@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2021-01-18 10:59, Pavel Stehule wrote:
>>
> and here is the patch
> [schema-variables-20200118.patch.gz ]

One small thing:

The drop variable synopsis is:

DROP VARIABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

In that text following it, 'RESTRICT' is not documented. When used it
does not give an error but I don't see how it 'works'.

Erik


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-18 18:17:06
Message-ID: CAFj8pRCPW56pFr0F0BcasdXjFeo3SFixNSpWKaBk0ibvznum-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 18. 1. 2021 v 15:24 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> On 2021-01-18 10:59, Pavel Stehule wrote:
> >>
> > and here is the patch
> > [schema-variables-20200118.patch.gz ]
>
>
> One small thing:
>
> The drop variable synopsis is:
>
> DROP VARIABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
>
> In that text following it, 'RESTRICT' is not documented. When used it
> does not give an error but I don't see how it 'works'.
>

should be fixed now. Thank you for check

Regards

Pavel

>
> Erik
>
>
>
>

Attachment Content-Type Size
schema-variables-20200118-2.patch.gz application/gzip 65.7 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-01-23 09:50:29
Message-ID: CAFj8pRD1Feit93CgwmYm1Q=X+M+AZqffCEZPFQ7qEMNHZRN4fA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

only rebase

Regards

Pavel

Attachment Content-Type Size
schema-variables-20200123.patch.gz application/gzip 65.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-02-02 08:43:57
Message-ID: CAFj8pRCc=B9-FRQg5eWDSkGwS2vpkq88hR6042cmPPizHuEGSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase and set PK for pg_variable table

Regards

Pavel

Attachment Content-Type Size
schema-variables-20210202.patch.gz application/gzip 65.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-02-16 17:46:13
Message-ID: CAFj8pRBk8x7afUXKLBOU-Ctg6A7QJvTAGGVEi0b6Jc8YTe8nUg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

út 2. 2. 2021 v 9:43 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> rebase and set PK for pg_variable table
>

rebase

Pavel

> Regards
>
> Pavel
>

Attachment Content-Type Size
schema-variables-20200216.patch.gz application/gzip 65.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-03-01 07:50:28
Message-ID: CAFj8pRCSwHQ4BJUbjF2YEausK1Z6+ejMyedpqAnWJbG+FEJDLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

út 16. 2. 2021 v 18:46 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> út 2. 2. 2021 v 9:43 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>> Hi
>>
>> rebase and set PK for pg_variable table
>>
>
> rebase
>

rebase

> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>

Attachment Content-Type Size
schema-variables-20200301.patch.gz application/gzip 65.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-03-13 06:01:13
Message-ID: CAFj8pRAbY+N+UqjqgESL5x-bsGmV+aVyyUkxUSgaGDZToZjDqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase

Pavel

Attachment Content-Type Size
schema-variables-20210313.patch.gz application/gzip 65.8 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables - doc
Date: 2021-03-17 12:05:11
Message-ID: 836057387.197819.1615982711621@webmailclassic.xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance


> On 2021.03.13. 07:01 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hi
> fresh rebase
> [schema-variables-20210313.patch.gz]

Hi Pavel,

I notice that the phrase 'schema variable' is not in the index at the end ('bookindex.html'). Not good.

It is also not in the index at the front of the manual - also not good.

Maybe these two (front and back index) can be added?

If a user searches the pdf, the first occurrence he finds is at:

43.13.2.4. Global variables and constants
(in itself that occurrence/mention is all right, but is should not be the first find, I think)

(I think there was in earlier versions of the patch an entry in the 'contents', i.e., at the front of the manual). I think it would be good to have it in the front-index, pointing to either LET or CREATE VARIABLE, or maybe even to a small introductory paragraph somewhere else (again, I seem to remember that there was one in an earlier patch version).

Of the new commands that this patch brings, 'LET' is the most immediately illuminating for a user (even when a CREATE VARIABLE has to be done first. There is an entry 'LET' in the index (good), but it would be better if that with LET-entry too the phrase 'schema variable' occurred. (I don't know if that's possible)

Then, in the CREATE VARIABLE paragraphs it says
'Changing a schema variable is non-transactional by default.'

I think that, unless there exists a mode where schema vars can be made transactional, 'by default' should be deleted (and there is no such 'transactional mode' for schema variables, is there?). The 'Description' also has such a 'By default' which is better removed for the same reason.

In the CREATE VARIABLE page the example is:

CREATE VARIABLE var1 AS integer;
SELECT var1;

I suggest to make that

CREATE VARIABLE var1 AS date;
LET var1 = (select current_date);
SELECT var1;

So that the example immediately shows an application of functionality.

Thanks,

Erik Rijkers

>
> Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables - doc
Date: 2021-03-22 09:47:07
Message-ID: CAFj8pRAZRt8MdOuvmUELbrNQRbYyHGktyZH3+7iM_ZW-Npwj6g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

st 17. 3. 2021 v 13:05 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

>
> > On 2021.03.13. 07:01 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> > Hi
> > fresh rebase
> > [schema-variables-20210313.patch.gz]
>
>
> Hi Pavel,
>
> I notice that the phrase 'schema variable' is not in the index at the end
> ('bookindex.html'). Not good.
>
> It is also not in the index at the front of the manual - also not good.
>
> Maybe these two (front and back index) can be added?
>

I inserted new indexterm "schema variable", and now this part of
bookindex.html looks like:

schema variablealtering, ALTER VARIABLEchanging, LETdefining, CREATE
VARIABLEdescription, Descriptionremoving, DROP VARIABLE

>
> If a user searches the pdf, the first occurrence he finds is at:
>
> 43.13.2.4. Global variables and constants
> (in itself that occurrence/mention is all right, but is should not be
> the first find, I think)
>
> (I think there was in earlier versions of the patch an entry in the
> 'contents', i.e., at the front of the manual). I think it would be good to
> have it in the front-index, pointing to either LET or CREATE VARIABLE, or
> maybe even to a small introductory paragraph somewhere else (again, I seem
> to remember that there was one in an earlier patch version).
>

I wrote new section to "advanced features" about schema variables

>
>
> Of the new commands that this patch brings, 'LET' is the most immediately
> illuminating for a user (even when a CREATE VARIABLE has to be done first.
> There is an entry 'LET' in the index (good), but it would be better if that
> with LET-entry too the phrase 'schema variable' occurred. (I don't know if
> that's possible)
>
>
> Then, in the CREATE VARIABLE paragraphs it says
> 'Changing a schema variable is non-transactional by default.'
>
> I think that, unless there exists a mode where schema vars can be made
> transactional, 'by default' should be deleted (and there is no such
> 'transactional mode' for schema variables, is there?). The 'Description'
> also has such a 'By default' which is better removed for the same reason.
>

fixed

>
> In the CREATE VARIABLE page the example is:
>
> CREATE VARIABLE var1 AS integer;
> SELECT var1;
>
> I suggest to make that
>
> CREATE VARIABLE var1 AS date;
> LET var1 = (select current_date);
> SELECT var1;
>
> So that the example immediately shows an application of functionality.
>

done

Thank you for the documentation review.

Updated patch attached

Regards

Pavel

>
> Thanks,
>
> Erik Rijkers
>
>
>
>
>
>
>
>
>
>
>
>
>
> >
> > Pavel
>

Attachment Content-Type Size
schema-variables-20210322.patch.gz application/gzip 66.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables - doc
Date: 2021-03-25 08:05:43
Message-ID: CAFj8pRBGyK4gY=RSinMGLO-hkbdnopayBnfODaaKjruY6RaAcA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 22. 3. 2021 v 10:47 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> st 17. 3. 2021 v 13:05 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:
>
>>
>> > On 2021.03.13. 07:01 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> > Hi
>> > fresh rebase
>> > [schema-variables-20210313.patch.gz]
>>
>>
>> Hi Pavel,
>>
>> I notice that the phrase 'schema variable' is not in the index at the end
>> ('bookindex.html'). Not good.
>>
>> It is also not in the index at the front of the manual - also not good.
>>
>> Maybe these two (front and back index) can be added?
>>
>
> I inserted new indexterm "schema variable", and now this part of
> bookindex.html looks like:
>
> schema variablealtering, ALTER VARIABLEchanging, LETdefining, CREATE
> VARIABLEdescription, Descriptionremoving, DROP VARIABLE
>
>
>
>>
>> If a user searches the pdf, the first occurrence he finds is at:
>>
>> 43.13.2.4. Global variables and constants
>> (in itself that occurrence/mention is all right, but is should not be
>> the first find, I think)
>>
>> (I think there was in earlier versions of the patch an entry in the
>> 'contents', i.e., at the front of the manual). I think it would be good to
>> have it in the front-index, pointing to either LET or CREATE VARIABLE, or
>> maybe even to a small introductory paragraph somewhere else (again, I seem
>> to remember that there was one in an earlier patch version).
>>
>
>
> I wrote new section to "advanced features" about schema variables
>
>
>>
>>
>> Of the new commands that this patch brings, 'LET' is the most immediately
>> illuminating for a user (even when a CREATE VARIABLE has to be done first.
>> There is an entry 'LET' in the index (good), but it would be better if that
>> with LET-entry too the phrase 'schema variable' occurred. (I don't know if
>> that's possible)
>>
>>
>> Then, in the CREATE VARIABLE paragraphs it says
>> 'Changing a schema variable is non-transactional by default.'
>>
>> I think that, unless there exists a mode where schema vars can be made
>> transactional, 'by default' should be deleted (and there is no such
>> 'transactional mode' for schema variables, is there?). The 'Description'
>> also has such a 'By default' which is better removed for the same reason.
>>
>
> fixed
>
>
>>
>> In the CREATE VARIABLE page the example is:
>>
>> CREATE VARIABLE var1 AS integer;
>> SELECT var1;
>>
>> I suggest to make that
>>
>> CREATE VARIABLE var1 AS date;
>> LET var1 = (select current_date);
>> SELECT var1;
>>
>> So that the example immediately shows an application of functionality.
>>
>
> done
>
> Thank you for the documentation review.
>
> Updated patch attached
>
> Regards
>
> Pavel
>
>
fresh update with merged Eric's changes in documentation

Regards

Pavel

>
>>
>> Thanks,
>>
>> Erik Rijkers
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> >
>> > Pavel
>>
>

Attachment Content-Type Size
schema-variables-20210325.patch.gz application/gzip 66.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-04-04 08:30:01
Message-ID: CAFj8pRBzKcqzj=23BHfv1QaXHt=2_SN=uhdR3rb_dAVQoit7ug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

so 13. 3. 2021 v 7:01 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> fresh rebase
>

only rebase

Regards

Pavel

>
> Pavel
>

Attachment Content-Type Size
schema-variables-20210404.patch.gz application/gzip 66.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2021-04-10 06:58:41
Message-ID: CAFj8pRCi-n6SzkAB+OHG=TZvL13xxta_qgffBLDOY0HEBqDhvg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I am sending a strongly updated patch for schema variables.

I rewrote an execution of a LET statement. In the previous implementation I
hacked STMT_SELECT. Now, I introduced a new statement STMT_LET, and I
implemented a new executor node SetVariable. Now I think this
implementation is much cleaner. Implementation with own executor node
reduces necessary work on PL side - and allows the LET statement to be
prepared - what is important from a security view.

I'll try to write a second implementation based on a cleaner implementation
like utility command too. I expect so this version will be more simple, but
utility commands cannot be prepared, and probably, there should be special
support for any PL. I hope a cleaner implementation can help to move this
patch.

We can choose one variant in the next step and this variant can be
finalized.

Notes, comments?

Regards

Pavel

Attachment Content-Type Size
schema-variables-rev2-20210410.patch.gz application/gzip 69.7 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-19 11:41:00
Message-ID: 8181bd3abc647bdae5a4f78e71e62478a98c75f4.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sat, 2021-04-10 at 08:58 +0200, Pavel Stehule wrote:
> I am sending a strongly updated patch for schema variables.
>
> I rewrote an execution of a LET statement. In the previous implementation I hacked
> STMT_SELECT. Now, I introduced a new statement STMT_LET, and I implemented a new
> executor node SetVariable. Now I think this implementation is much cleaner.
> Implementation with own executor node reduces necessary work on PL side - and allows
> the LET statement to be prepared - what is important from a security view.
>
> I'll try to write a second implementation based on a cleaner implementation like
> utility command too. I expect so this version will be more simple, but utility
> commands cannot be prepared, and probably, there should be special support for
> any PL. I hope a cleaner implementation can help to move this patch.
>
> We can choose one variant in the next step and this variant can be finalized.
>
> Notes, comments?

Thank you!

I tried to give the patch a spin, but it doesn't apply any more,
and there are too many conflicts for me to fix manually.

So I had a look at the documentation:

> --- a/doc/src/sgml/advanced.sgml
> +++ b/doc/src/sgml/advanced.sgml

> + <para>
> + The value of a schema variable is local to the current session. Retrieving
> + a variable's value returns either a NULL or a default value, unless its value
> + is set to something else in the current session with a LET command. The content
> + of a variable is not transactional. This is the same as in regular variables
> + in PL languages.
> + </para>
> +
> + <para>
> + Schema variables are retrieved by the <command>SELECT</command> SQL command.
> + Their value is set with the <command>LET</command> SQL command.
> + While schema variables share properties with tables, their value cannot be updated
> + with an <command>UPDATE</command> command.

"PL languages" -> "procedural languages". Perhaps a link to the "procedural Languages"
chapter would be a good idea.
I don't think we should say "regular" variables: are there irregular variables?

My feeling is that "SQL statement <command>XY</command>" is better than
"<command>XY</command> SQL command".

I think the last sentence should go. The properties they share with tables are
that they live in a schema and can be used with SELECT.
Also, it is not necessary to mention that they cannot be UPDATEd. They cannot
be TRUNCATEd or CALLed either, so why mention UPDATE specifically?

> --- a/doc/src/sgml/catalogs.sgml
> +++ b/doc/src/sgml/catalogs.sgml

> + <row>
> + <entry><structfield>varisnotnull</structfield></entry>
> + <entry><type>boolean</type></entry>
> + <entry></entry>
> + <entry>
> + True if the schema variable doesn't allow null value. The default value is false.
> + </entry>
> + </row>

I think the attribute should be called "varnotnull", similar to "attnotnull".
This attribute determines whether the variable is NOT NULL or not, not about
its current setting.

There is a plural missing: "doesn't allow null valueS".

> + <row>
> + <entry><structfield>vareoxaction</structfield></entry>
> + <entry><type>char</type></entry>
> + <entry></entry>
> + <entry>
> + <literal>n</literal> = no action, <literal>d</literal> = drop the variable,
> + <literal>r</literal> = reset the variable to its default value.
> + </entry>
> + </row>

Perhaps the name "varxactendaction" would be better.

A descriptive sentence is missing.

> --- /dev/null
> +++ b/doc/src/sgml/ref/create_variable.sgml

> + <para>
> + The value of a schema variable is local to the current session. Retrieving
> + a variable's value returns either a NULL or a default value, unless its value
> + is set to something else in the current session with a LET command. The content
> + of a variable is not transactional. This is the same as in regular variables in PL languages.
> + </para>

"regular variables in PL languages" -> "variables in procedural languages"

> + <para>
> + Schema variables are retrieved by the <command>SELECT</command> SQL command.
> + Their value is set with the <command>LET</command> SQL command.
> + While schema variables share properties with tables, their value cannot be updated
> + with an <command>UPDATE</command> command.
> + </para>

That's just a literal copy from the tutorial section. I have the same comments
as there.

> + <varlistentry>
> + <term><literal>NOT NULL</literal></term>
> + <listitem>
> + <para>
> + The <literal>NOT NULL</literal> clause forbids to set the variable to
> + a null value. A variable created as NOT NULL and without an explicitly
> + declared default value cannot be read until it is initialized by a LET
> + command. This obliges the user to explicitly initialize the variable
> + content before reading it.
> + </para>
> + </listitem>
> + </varlistentry>

What is the reason for that behavior? I'd have expected that a NOT NULL
variable needs a default value.

> --- /dev/null
> +++ b/doc/src/sgml/ref/let.sgml

> + <varlistentry>
> + <term><literal>sql_expression</literal></term>
> + <listitem>
> + <para>
> + An SQL expression. The result is cast into the schema variable's type.
> + </para>
> + </listitem>
> + </varlistentry>

Always, even if there is no assignment or implicit cast?

I see no such wording fir INSERT or UPDATE, so if only assignment casts are used,
the second sentence should be removed.

> --- a/doc/src/sgml/ref/pg_restore.sgml
> +++ b/doc/src/sgml/ref/pg_restore.sgml

> + <varlistentry>
> + <term><option>-A <replaceable class="parameter">schema_variable</replaceable></option></term>
> + <term><option>--variable=<replaceable class="parameter">schema_variable</replaceable></option></term>
> + <listitem>
> + <para>
> + Restore a named schema variable only. Multiple schema variables may be specified with
> + multiple <option>-A</option> switches.
> + </para>
> + </listitem>
> + </varlistentry>

Do we need that? We have no such option for functions and other non-relations.

And if we really want such an option for "pg_restore", why not for "pg_dump"?

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-20 19:48:43
Message-ID: CAFj8pRBZf7QjC06UO2u95iuDez5RNTZo6YwQKWzyNBknT-R1Ug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 19. 7. 2024 v 13:41 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Sat, 2021-04-10 at 08:58 +0200, Pavel Stehule wrote:
> > I am sending a strongly updated patch for schema variables.
> >
> > I rewrote an execution of a LET statement. In the previous
> implementation I hacked
> > STMT_SELECT. Now, I introduced a new statement STMT_LET, and I
> implemented a new
> > executor node SetVariable. Now I think this implementation is much
> cleaner.
> > Implementation with own executor node reduces necessary work on PL side
> - and allows
> > the LET statement to be prepared - what is important from a security
> view.
> >
> > I'll try to write a second implementation based on a cleaner
> implementation like
> > utility command too. I expect so this version will be more simple, but
> utility
> > commands cannot be prepared, and probably, there should be special
> support for
> > any PL. I hope a cleaner implementation can help to move this patch.
> >
> > We can choose one variant in the next step and this variant can be
> finalized.
> >
> > Notes, comments?
>
> Thank you!
>
> I tried to give the patch a spin, but it doesn't apply any more,
> and there are too many conflicts for me to fix manually.
>
>
>
just fresh rebase

I'll reply to your comments tomorrow.

Regards

Pavel

Attachment Content-Type Size
v20240720-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240720-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.5 KB
v20240720-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240720-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 146.7 KB
v20240720-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240720-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240720-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.6 KB
v20240720-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 134.4 KB
v20240720-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240720-0010-implementation-of-temporary-session-variables.patch text/x-patch 38.6 KB
v20240720-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.3 KB
v20240720-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.6 KB
v20240720-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 12.0 KB
v20240720-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.4 KB
v20240720-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240720-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240720-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240720-0019-transactional-variables.patch text/x-patch 39.0 KB
v20240720-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-22 06:37:22
Message-ID: CAFj8pRBaD0_bMrCREWnVLfcTMdc0v7ns7Rt=sEvd1EoFmLfarQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 19. 7. 2024 v 13:41 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Sat, 2021-04-10 at 08:58 +0200, Pavel Stehule wrote:
> > I am sending a strongly updated patch for schema variables.
> >
> > I rewrote an execution of a LET statement. In the previous
> implementation I hacked
> > STMT_SELECT. Now, I introduced a new statement STMT_LET, and I
> implemented a new
> > executor node SetVariable. Now I think this implementation is much
> cleaner.
> > Implementation with own executor node reduces necessary work on PL side
> - and allows
> > the LET statement to be prepared - what is important from a security
> view.
> >
> > I'll try to write a second implementation based on a cleaner
> implementation like
> > utility command too. I expect so this version will be more simple, but
> utility
> > commands cannot be prepared, and probably, there should be special
> support for
> > any PL. I hope a cleaner implementation can help to move this patch.
> >
> > We can choose one variant in the next step and this variant can be
> finalized.
> >
> > Notes, comments?
>
> Thank you!
>
> I tried to give the patch a spin, but it doesn't apply any more,
> and there are too many conflicts for me to fix manually.
>
> So I had a look at the documentation:
>
> > --- a/doc/src/sgml/advanced.sgml
> > +++ b/doc/src/sgml/advanced.sgml
>
> > + <para>
> > + The value of a schema variable is local to the current session.
> Retrieving
> > + a variable's value returns either a NULL or a default value, unless
> its value
> > + is set to something else in the current session with a LET command.
> The content
> > + of a variable is not transactional. This is the same as in regular
> variables
> > + in PL languages.
> > + </para>
> > +
> > + <para>
> > + Schema variables are retrieved by the <command>SELECT</command> SQL
> command.
> > + Their value is set with the <command>LET</command> SQL command.
> > + While schema variables share properties with tables, their value
> cannot be updated
> > + with an <command>UPDATE</command> command.
>
> "PL languages" -> "procedural languages". Perhaps a link to the
> "procedural Languages"
> chapter would be a good idea.
> I don't think we should say "regular" variables: are there irregular
> variables?
>
> My feeling is that "SQL statement <command>XY</command>" is better than
> "<command>XY</command> SQL command".
>

probably, you are reading an old version of this patch. I cannot find these
sentences.

>
> I think the last sentence should go. The properties they share with
> tables are
> that they live in a schema and can be used with SELECT.
> Also, it is not necessary to mention that they cannot be UPDATEd. They
> cannot
> be TRUNCATEd or CALLed either, so why mention UPDATE specifically?
>
> > --- a/doc/src/sgml/catalogs.sgml
> > +++ b/doc/src/sgml/catalogs.sgml
>
> > + <row>
> > + <entry><structfield>varisnotnull</structfield></entry>
> > + <entry><type>boolean</type></entry>
> > + <entry></entry>
> > + <entry>
> > + True if the schema variable doesn't allow null value. The
> default value is false.
> > + </entry>
> > + </row>
>
> I think the attribute should be called "varnotnull", similar to
> "attnotnull".
> This attribute determines whether the variable is NOT NULL or not, not
> about
> its current setting.
>
> There is a plural missing: "doesn't allow null valueS".
>

changed

>
> > + <row>
> > + <entry><structfield>vareoxaction</structfield></entry>
> > + <entry><type>char</type></entry>
> > + <entry></entry>
> > + <entry>
> > + <literal>n</literal> = no action, <literal>d</literal> = drop
> the variable,
> > + <literal>r</literal> = reset the variable to its default value.
> > + </entry>
> > + </row>
>
> Perhaps the name "varxactendaction" would be better.
>
> A descriptive sentence is missing.
>

I renamed field, recent version looks like

<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>varxactendaction</structfield> <type>char</type>
</para>
<para>
Action performed at end of transaction:
<literal>n</literal> = no action, <literal>d</literal> = drop the
variable,
<literal>r</literal> = reset the variable to its default value.
</para></entry>
</row>

>
> > --- /dev/null
> > +++ b/doc/src/sgml/ref/create_variable.sgml
>
> > + <para>
> > + The value of a schema variable is local to the current session.
> Retrieving
> > + a variable's value returns either a NULL or a default value, unless
> its value
> > + is set to something else in the current session with a LET command.
> The content
> > + of a variable is not transactional. This is the same as in regular
> variables in PL languages.
> > + </para>
>
> "regular variables in PL languages" -> "variables in procedural languages"
>

fixed

>
> > + <para>
> > + Schema variables are retrieved by the <command>SELECT</command> SQL
> command.
> > + Their value is set with the <command>LET</command> SQL command.
> > + While schema variables share properties with tables, their value
> cannot be updated
> > + with an <command>UPDATE</command> command.
> > + </para>
>
> That's just a literal copy from the tutorial section. I have the same
> comments
> as there.
>

fixed

>
> > + <varlistentry>
> > + <term><literal>NOT NULL</literal></term>
> > + <listitem>
> > + <para>
> > + The <literal>NOT NULL</literal> clause forbids to set the
> variable to
> > + a null value. A variable created as NOT NULL and without an
> explicitly
> > + declared default value cannot be read until it is initialized by
> a LET
> > + command. This obliges the user to explicitly initialize the
> variable
> > + content before reading it.
> > + </para>
> > + </listitem>
> > + </varlistentry>
>
> What is the reason for that behavior? I'd have expected that a NOT NULL
> variable needs a default value.
>

changed - now, the default is required when variable is NOT NULL

>
> > --- /dev/null
> > +++ b/doc/src/sgml/ref/let.sgml
>
> > + <varlistentry>
> > + <term><literal>sql_expression</literal></term>
> > + <listitem>
> > + <para>
> > + An SQL expression. The result is cast into the schema variable's
> type.
> > + </para>
> > + </listitem>
> > + </varlistentry>
>
> Always, even if there is no assignment or implicit cast?
>

It uses implicit cast in COERCION_ASSIGNMENT context. coerce_to_target_type
is used always

This part of doc currently looks

<listitem>
<para>
An SQL expression (can be subquery in parenthesis). The result must
be of castable to the same data type as the session variable (in
implicit or assignment context).
</para>
</listitem>

> I see no such wording fir INSERT or UPDATE, so if only assignment casts
> are used,
> the second sentence should be removed.
>
> > --- a/doc/src/sgml/ref/pg_restore.sgml
> > +++ b/doc/src/sgml/ref/pg_restore.sgml
>
> > + <varlistentry>
> > + <term><option>-A <replaceable
> class="parameter">schema_variable</replaceable></option></term>
> > + <term><option>--variable=<replaceable
> class="parameter">schema_variable</replaceable></option></term>
> > + <listitem>
> > + <para>
> > + Restore a named schema variable only. Multiple schema
> variables may be specified with
> > + multiple <option>-A</option> switches.
> > + </para>
> > + </listitem>
> > + </varlistentry>
>
> Do we need that? We have no such option for functions and other
> non-relations.
>

It is designed to be consistent with others. pg_restore supports functions
-P, triggers -T

>
> And if we really want such an option for "pg_restore", why not for
> "pg_dump"?
>

I have no strong opinion about it, I think so it is consistent with other
non-relations, but it is not important.

I moved this feature to a separate patch. It can be committed optionaly or
later.

pg_restore has options -P, -T, and pg_dump does not have these options.
These options (functionality) can be implemented in pg_dump too, but
unfortunately -T is used for different purposes (exclude table).

Regards

Pavel

>
> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240722-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 131.7 KB
v20240722-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240722-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.5 KB
v20240722-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240722-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 146.7 KB
v20240722-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.6 KB
v20240722-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240722-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240722-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240722-0010-implementation-of-temporary-session-variables.patch text/x-patch 38.7 KB
v20240722-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.5 KB
v20240722-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.4 KB
v20240722-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240722-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 12.0 KB
v20240722-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240722-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240722-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240722-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240722-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240722-0019-transactional-variables.patch text/x-patch 39.0 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-22 08:23:39
Message-ID: 890e1f8bf8eb45af17c892016674c752cb3ab8dc.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Thanks for the updated patch and the fixes!

On Mon, 2024-07-22 at 08:37 +0200, Pavel Stehule wrote:
> > > --- a/doc/src/sgml/ref/pg_restore.sgml
> > > +++ b/doc/src/sgml/ref/pg_restore.sgml
> >
> > > +     <varlistentry>
> > > +      <term><option>-A <replaceable class="parameter">schema_variable</replaceable></option></term>
> > > +      <term><option>--variable=<replaceable class="parameter">schema_variable</replaceable></option></term>
> > > +      <listitem>
> > > +       <para>
> > > +        Restore a named schema variable only.  Multiple schema variables may be specified with
> > > +        multiple <option>-A</option> switches.
> > > +       </para>
> > > +      </listitem>
> > > +     </varlistentry>
> >
> > Do we need that?  We have no such option for functions and other non-relations.
>
> It is designed to be consistent with others. pg_restore supports functions -P, triggers -T
> >
> > And if we really want such an option for "pg_restore", why not for "pg_dump"?
> >
>
> I have no strong opinion about it, I think so it is consistent with other non-relations, but it is not important.
>
> I moved this feature to a separate patch. It can be committed optionaly or later.
>
> pg_restore has options -P, -T, and pg_dump does not have these options. These options (functionality) can
> be implemented in pg_dump too, but unfortunately -T is used for different purposes (exclude table).

Ah! I didn't realize that -P and -T are the same. So no objections, although I'm
not sure if anyone will ever want to restore a single variable from a backup.

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-22 08:55:30
Message-ID: CAFj8pRBRm9htfi72202FiD6zafpgvX3MF41U7Lm2fZbktfOL2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 22. 7. 2024 v 10:23 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> Thanks for the updated patch and the fixes!
>
> On Mon, 2024-07-22 at 08:37 +0200, Pavel Stehule wrote:
> > > > --- a/doc/src/sgml/ref/pg_restore.sgml
> > > > +++ b/doc/src/sgml/ref/pg_restore.sgml
> > >
> > > > + <varlistentry>
> > > > + <term><option>-A <replaceable
> class="parameter">schema_variable</replaceable></option></term>
> > > > + <term><option>--variable=<replaceable
> class="parameter">schema_variable</replaceable></option></term>
> > > > + <listitem>
> > > > + <para>
> > > > + Restore a named schema variable only. Multiple schema
> variables may be specified with
> > > > + multiple <option>-A</option> switches.
> > > > + </para>
> > > > + </listitem>
> > > > + </varlistentry>
> > >
> > > Do we need that? We have no such option for functions and other
> non-relations.
> >
> > It is designed to be consistent with others. pg_restore supports
> functions -P, triggers -T
> > >
> > > And if we really want such an option for "pg_restore", why not for
> "pg_dump"?
> > >
> >
> > I have no strong opinion about it, I think so it is consistent with
> other non-relations, but it is not important.
> >
> > I moved this feature to a separate patch. It can be committed optionaly
> or later.
> >
> > pg_restore has options -P, -T, and pg_dump does not have these options.
> These options (functionality) can
> > be implemented in pg_dump too, but unfortunately -T is used for
> different purposes (exclude table).
>
> Ah! I didn't realize that -P and -T are the same. So no objections,
> although I'm
> not sure if anyone will ever want to restore a single variable from a
> backup.
>

I wrote it mainly for completeness and symmetry. I can imagine only one use
case - possibility to offline trace the changes of schema, but who knows.
The cost is just an occupation of 'A' char. Maybe it doesn't need a short
option, and a long option can be good enough.

Pavel

> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-23 14:34:44
Message-ID: 9e67d49deb18270eddb95e602c83f02b98459843.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Thanks for the fixes and the new patch set!
I think that this would be a very valuable feature!

This is a very incomplete review after playing with the patch set for a while.

Some bugs and oddities I have found:

"psql" support:

\? gives

\dV [PATTERN] list variables

I think that should say "schema variables" to distinguish them from
psql variables.

Running \dV when connected to an older server gives

ERROR: relation "pg_catalog.pg_variable" does not exist
LINE 16: FROM pg_catalog.pg_variable v
^

I think it would be better not to run the query and show a response like

session variables don't exist in server version 16

The LET statement:

CREATE VARIABLE testvar AS int4multirange[];
LET testvar = '{\{[2\,7]\,[11\,13]\}}';
ERROR: variable "laurenz.testvar" is of type int4multirange[], but expression is of type text
LINE 1: LET testvar = '{\{[2\,7]\,[11\,13]\}}';
^
HINT: You will need to rewrite or cast the expression.

Sure, I can add an explicit type cast, but I think that the type should
be determined by the type of the variable. The right-hand side should be
treated as "unknown", and the type input function should be used.

Parameter session_variables_ambiguity_warning:

--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -1544,6 +1544,16 @@ struct config_bool ConfigureNamesBool[] =
false,
NULL, NULL, NULL
},
+ {
+ {"session_variables_ambiguity_warning", PGC_USERSET, DEVELOPER_OPTIONS,
+ gettext_noop("Raise warning when reference to a session variable is ambiguous."),
+ NULL,
+ GUC_NOT_IN_SAMPLE
+ },
+ &session_variables_ambiguity_warning,
+ false,
+ NULL, NULL, NULL
+ },

I think the short_desc should be "Raise a warning" (with the indefinite article).

DEVELOPER_OPTIONS is the wrong category. We normally use that for parameters
that are only relevant for PostgreSQL hackers. I think it should be
CLIENT_CONN_OTHER.

CREATE VARIABLE command:

CREATE VARIABLE str AS text NOT NULL;
ERROR: session variable must have a default value, since it's declared NOT NULL

Perhaps this error message would be better:

session variables declared as NOT NULL must have a default value

This is buggy:

CREATE VARIABLE str AS text NOT NULL DEFAULT NULL;

Ugh.

SELECT str;
ERROR: null value is not allowed for NOT NULL session variable "laurenz.str"
DETAIL: The result of DEFAULT expression is NULL.

Perhaps that is a leftover from the previous coding, but I think there need be
no check upon SELECT. It should be enough to check during CREATE VARIABLE and
LET.

pg_dump support:

The attempt to dump a database with an older version leads to

pg_dump: error: query failed: ERROR: relation "pg_catalog.pg_variable" does not exist
LINE 14: FROM pg_catalog.pg_variable v
^

Dumping variables must be conditional on the server version.

IMMUTABLE variables:

+ <varlistentry id="sql-createvariable-immutable">
+ <term><literal>IMMUTABLE</literal></term>
+ <listitem>
+ <para>
+ The assigned value of the session variable can not be changed.
+ Only if the session variable doesn't have a default value, a single
+ initialization is allowed using the <command>LET</command> command. Once
+ done, no further change is allowed until end of transaction
+ if the session variable was created with clause <literal>ON TRANSACTION
+ END RESET</literal>, or until reset of all session variables by
+ <command>DISCARD VARIABLES</command>, or until reset of all session
+ objects by command <command>DISCARD ALL</command>.
+ </para>
+ </listitem>
+ </varlistentry>

I can see the usefulness of IMMUTABLE variables, but I am surprised that
they are reset by DISCARD. What is the use case you have in mind?
The use case I can envision is an application that sets a value right after
authentication, for use with row-level security. But then it would be harmful
if the user could reset the variable with DISCARD.

Documentation:

--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml

+ <para>
+ The session variables can be shadowed by column references in a query. When
+ a query contains identifiers or qualified identifiers that could be used as
+ both a session variable identifiers and as column identifier, then the
+ column identifier is preferred every time. Warnings can be emitted when
+ this situation happens by enabling configuration parameter <xref
+ linkend="guc-session-variables-ambiguity-warning"/>. User can explicitly
+ qualify the source object by syntax <literal>table.column</literal> or
+ <literal>variable.column</literal>.
+ </para>

I think you mean <literal>schema.variable</literal>, not <literal>variable.column</literal>.

Yours,
Laurenz Albe


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-23 21:41:28
Message-ID: 4165c66e9057c34423a0f91d1558165738ba31e2.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Tue, 2024-07-23 at 16:34 +0200, Laurenz Albe wrote:
> CREATE VARIABLE command:
>
> This is buggy:
>
> CREATE VARIABLE str AS text NOT NULL DEFAULT NULL;
>
> Ugh.
>
> SELECT str;
> ERROR: null value is not allowed for NOT NULL session variable "laurenz.str"
> DETAIL: The result of DEFAULT expression is NULL.
>
> Perhaps that is a leftover from the previous coding, but I think there need be
> no check upon SELECT. It should be enough to check during CREATE VARIABLE and
> LET.

I'm having second thoughts about that.

I was thinking of a variable like of a table column, but there is a fundamental
difference: there is a clear moment when a tuple is added (INSERT or UPDATE),
which is the point where a column can be checked for NULL values.

A variable can be SELECTed without having been LET before, in which case it
has the default value. But there is no way to test the default value before
the variable is SELECTed. So while DEFAULT NULL for a non-nullable variable
seems weird, it is no worse than DEFAULT somefunc() for a function that returns
NULL.

So perhaps the behavior I complained about above is actually the right one.
In the view of that, it doesn't seem necessary to enforce a DEFAULT value for
a NOT NULL variable: NOT NULL might just as well mean "you have to LET it before
you can SELECT it".

> IMMUTABLE variables:
>
> + <varlistentry id="sql-createvariable-immutable">
> + <term><literal>IMMUTABLE</literal></term>
> + <listitem>
> + <para>
> + The assigned value of the session variable can not be changed.
> + Only if the session variable doesn't have a default value, a single
> + initialization is allowed using the <command>LET</command> command. Once
> + done, no further change is allowed until end of transaction
> + if the session variable was created with clause <literal>ON TRANSACTION
> + END RESET</literal>, or until reset of all session variables by
> + <command>DISCARD VARIABLES</command>, or until reset of all session
> + objects by command <command>DISCARD ALL</command>.
> + </para>
> + </listitem>
> + </varlistentry>
>
> I can see the usefulness of IMMUTABLE variables, but I am surprised that
> they are reset by DISCARD. What is the use case you have in mind?
> The use case I can envision is an application that sets a value right after
> authentication, for use with row-level security. But then it would be harmful
> if the user could reset the variable with DISCARD.

I'm beginning to be uncertain about that as well. You might want to use a
connection pool, and you LET the variable when you take it out of the pool.
When the session is returned to the pool, variables get DISCARDed.

Sure, a user can call DISCARD, but only if he or she is in an interactive session.

So perhaps it is good as it is.

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-24 15:19:55
Message-ID: CAFj8pRDXo-RRcy2VFDm_vzv3Eaaz6Ex=X19up=x8W4COyBNmaQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

út 23. 7. 2024 v 16:34 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> Thanks for the fixes and the new patch set!
> I think that this would be a very valuable feature!
>
>
Thank you :-)

> This is a very incomplete review after playing with the patch set for a
> while.
>
> Some bugs and oddities I have found:
>
> "psql" support:
>
> \? gives
>
> \dV [PATTERN] list variables
>
> I think that should say "schema variables" to distinguish them from
> psql variables.
>

enhanced to "list session variables"

>
> Running \dV when connected to an older server gives
>
> ERROR: relation "pg_catalog.pg_variable" does not exist
> LINE 16: FROM pg_catalog.pg_variable v
> ^
>
> I think it would be better not to run the query and show a response like
>
> session variables don't exist in server version 16
>

there is standardized error message - and I used now

<-->if (pset.sversion < 180000)
<-->{
<--><-->char<--><-->sverbuf[32];

<--><-->pg_log_error("The server (version %s) does not support session
variables.",
<--><--><--><--><--> formatPGVersionNumber(pset.sversion, false,
<--><--><--><--><--><--><--><--><--><--> sverbuf, sizeof(sverbuf)));
<--><-->return true;
<-->}

>
> The LET statement:
>
> CREATE VARIABLE testvar AS int4multirange[];
> LET testvar = '{\{[2\,7]\,[11\,13]\}}';
> ERROR: variable "laurenz.testvar" is of type int4multirange[], but
> expression is of type text
> LINE 1: LET testvar = '{\{[2\,7]\,[11\,13]\}}';
> ^
> HINT: You will need to rewrite or cast the expression.
>
> Sure, I can add an explicit type cast, but I think that the type should
> be determined by the type of the variable. The right-hand side should be
> treated as "unknown", and the type input function should be used.
>

fixed - it needed set pstate->p_resolve_unknowns = false;

I used your example in regress test

> Parameter session_variables_ambiguity_warning:
>
> --- a/src/backend/utils/misc/guc_tables.c
> +++ b/src/backend/utils/misc/guc_tables.c
> @@ -1544,6 +1544,16 @@ struct config_bool ConfigureNamesBool[] =
> false,
> NULL, NULL, NULL
> },
> + {
> + {"session_variables_ambiguity_warning", PGC_USERSET,
> DEVELOPER_OPTIONS,
> + gettext_noop("Raise warning when reference to a session
> variable is ambiguous."),
> + NULL,
> + GUC_NOT_IN_SAMPLE
> + },
> + &session_variables_ambiguity_warning,
> + false,
> + NULL, NULL, NULL
> + },
>
> I think the short_desc should be "Raise a warning" (with the indefinite
> article).
>
> DEVELOPER_OPTIONS is the wrong category. We normally use that for
> parameters
> that are only relevant for PostgreSQL hackers. I think it should be
> CLIENT_CONN_OTHER.
>

changed

> CREATE VARIABLE command:
>
> CREATE VARIABLE str AS text NOT NULL;
> ERROR: session variable must have a default value, since it's
> declared NOT NULL
>
> Perhaps this error message would be better:
>
> session variables declared as NOT NULL must have a default value
>

changed

>
> This is buggy:
>
> CREATE VARIABLE str AS text NOT NULL DEFAULT NULL;
>
> Ugh.
>
> SELECT str;
> ERROR: null value is not allowed for NOT NULL session variable
> "laurenz.str"
> DETAIL: The result of DEFAULT expression is NULL.
>
> Perhaps that is a leftover from the previous coding, but I think there
> need be
> no check upon SELECT. It should be enough to check during CREATE
> VARIABLE and
> LET.
>

I think it is correct. When you use SELECT str, then DEFAULT expression is
executed, and then the result is assigned to a variable, and there is NOT
NULL guard, which raises an exception. The variable is not initialized when
you run DDL, but it is initialized when you first read or write from/to the
variable. The DEFAULT expression is not evaluated in DDL time. In this
case, I can detect the problem in DDL time because the result is
transformed to NULL node, but generally there can be SQL non immutable
function, and then I need to wait until the DEFAULT expression will be
evaluated - and it is time of first reading. Unfortunately, there is not an
available check if some expression is NULL, that I can use in DDL time, but
I have it in plpgsql_check.

You can have a function

CREATE OR REPLACE FUNCTION foo()
RETURNS int AS $$
BEGIN
RETURN NULL;
END:
$$ LANGUAGE plpgsql;

the function is not marked as IMMUTABLE

I can

CREATE VARIABLE v AS int NOT NULL DEFAULT foo();

In DDL time I know nothing about result of foo()

When I run SELECT v; then foo is executed, and because it is in
contradiction with the NOT NULL clause, it fails. And I think it is correct.

It is consistent with PL/pgSQL. I can write

(2024-07-24 11:57:33) postgres=# CREATE OR REPLACE FUNCTION fx()
postgres-# RETURNS void AS $$
postgres$# DECLARE v int NOT NULL DEFAULT NULL;
postgres$# BEGIN
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
(2024-07-24 12:06:54) postgres=# SELECT fx();
ERROR: null value cannot be assigned to variable "v" declared NOT NULL
CONTEXT: PL/pgSQL function fx() line 2 during statement block local
variable initialization

DDL is ok, and SELECT fails.

I think so DDL should not to evaluate DEFAULT expressions - the result from
this are issues described in discussion about usage 'now'::timestamp

>
> pg_dump support:
>
> The attempt to dump a database with an older version leads to
>
> pg_dump: error: query failed: ERROR: relation
> "pg_catalog.pg_variable" does not exist
> LINE 14: FROM pg_catalog.pg_variable v
> ^

Dumping variables must be conditional on the server version.
>

>
fixed, there was guard but for pg 17

>
> IMMUTABLE variables:
>
> + <varlistentry id="sql-createvariable-immutable">
> + <term><literal>IMMUTABLE</literal></term>
> + <listitem>
> + <para>
> + The assigned value of the session variable can not be changed.
> + Only if the session variable doesn't have a default value, a
> single
> + initialization is allowed using the <command>LET</command>
> command. Once
> + done, no further change is allowed until end of transaction
> + if the session variable was created with clause <literal>ON
> TRANSACTION
> + END RESET</literal>, or until reset of all session variables by
> + <command>DISCARD VARIABLES</command>, or until reset of all
> session
> + objects by command <command>DISCARD ALL</command>.
> + </para>
> + </listitem>
> + </varlistentry>
>
> I can see the usefulness of IMMUTABLE variables, but I am surprised that
> they are reset by DISCARD. What is the use case you have in mind?
> The use case I can envision is an application that sets a value right
> after
> authentication, for use with row-level security. But then it would be
> harmful
> if the user could reset the variable with DISCARD.
>

Primary I think about IMMUTABLE variables like about some form of cache.
This cache is protected against unwanted repeated write - and can help with
detection of this situation.
It is not a security tool primarily - there are access rights for this
purpose. The scope of this cache can be different - sometimes session,
sometimes transaction. When you use a pooler like pgbouncer, then the
lifetime is ended by command DISCARD ALL. Moreover, after DISCARD ALL, the
session should be in default state, so then any session variable should be
not initialized. And there is an implementation reason too. When I handle
command DISCARD VARIABLES, I just reset related memory contexts. It is
quick and safe.

I can imagine more strict behaviour - like impossibility to discard context
or necessity to have default immutable expressions. But then this clause is
not useful for connection pooling with transaction mode :-/. So current
design is a compromise - if somebody wants strict behaviour, then can set
default immutable expressions (by self). And then there will not be a
problem with DISCARD VARIABLES.

But because it supports a possibility ON TRANSACTION END RESET, then
theoretically it can be used in transaction mode too without possibility to
be reset by DISCARD ALL.

At the end there is just one question - the DISCARD VARIABLES should
support some exceptions, or the immutability of variables should have some
exceptions? I can imagine the surprise so after DISCARD ALL, the immutable
variable lost a value, but the same surprise can be in the moment after
DISCARD ALL when the LET immutablevar statement fails. Then we have to
choose a priority - DISCARD x IMMUTABLE.

I prefer to have a stronger DISCARD VARIABLES command without exceptions
(for semantic, for simple implementation), but I am open to discussion. If
we want to support the IMMUTABLE clause, then we have to reply to the
mentioned question. What do you think about it?

>
> Documentation:
> RestoreArchive
> --- a/doc/src/sgml/ddl.sgml
> +++ b/doc/src/sgml/ddl.sgml
>
> + <para>
> + The session variables can be shadowed by column references in a
> query. When
> + a query contains identifiers or qualified identifiers that could
> be used as
> + both a session variable identifiers and as column identifier,
> then the
> + column identifier is preferred every time. Warnings can be
> emitted when
> + this situation happens by enabling configuration parameter <xref
> + linkend="guc-session-variables-ambiguity-warning"/>. User can
> explicitly
> + qualify the source object by syntax
> <literal>table.column</literal> or
> + <literal>variable.column</literal>.
> + </para>
>
> I think you mean <literal>schema.variable</literal>, not
> <literal>variable.column</literal>.
>

fixed

> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240724-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240724-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.0 KB
v20240724-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240724-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.5 KB
v20240724-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.7 KB
v20240724-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.3 KB
v20240724-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240724-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240724-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240724-0010-implementation-of-temporary-session-variables.patch text/x-patch 38.7 KB
v20240724-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.5 KB
v20240724-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.4 KB
v20240724-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240724-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 12.0 KB
v20240724-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240724-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240724-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240724-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240724-0019-transactional-variables.patch text/x-patch 39.0 KB
v20240724-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-24 17:02:11
Message-ID: f9f4d536993e48990bd7eb38e18798c4572b6700.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Wed, 2024-07-24 at 17:19 +0200, Pavel Stehule wrote:
> >   This is buggy:
> >
> >     CREATE VARIABLE str AS text NOT NULL DEFAULT NULL;
> >
> >   Ugh.
> >
> >     SELECT str;
> >     ERROR:  null value is not allowed for NOT NULL session variable "laurenz.str"
> >     DETAIL:  The result of DEFAULT expression is NULL.
> >
> >   Perhaps that is a leftover from the previous coding, but I think there need be
> >   no check upon SELECT.  It should be enough to check during CREATE VARIABLE and
> >   LET.
>
> I think it is correct. When you use SELECT str, then DEFAULT expression is
> executed, and then the result is assigned to a variable, and there is NOT NULL
> guard, which raises an exception. The variable is not initialized when you run
> DDL, but it is initialized when you first read or write from/to the variable.
> The DEFAULT expression is not evaluated in DDL time. In this case, I can detect
> the problem in DDL time because the result is transformed to NULL node, but
> generally there can be SQL non immutable function, and then I need to wait until
> the DEFAULT expression will be evaluated - and it is time of first reading.
> Unfortunately, there is not an available check if some expression is NULL,
> that I can use in DDL time, but I have it in plpgsql_check.

That makes sense to me.

In that case, I think we can drop the requirement that NOT NULL variables
need a default clause.

>
> >   I can see the usefulness of IMMUTABLE variables, but I am surprised that
> >   they are reset by DISCARD.  What is the use case you have in mind?
> >   The use case I can envision is an application that sets a value right after
> >   authentication, for use with row-level security.  But then it would be harmful
> >   if the user could reset the variable with DISCARD.
>
> Primary I think about IMMUTABLE variables like about some form of cache.
> This cache is protected against unwanted repeated write - and can help with
> detection of this situation.

We can leave it as it is. The IMMUTABLE feature need not go into the first
release, so that can be discussed some more later.

Thanks for the new patch set; I'll look at it soon.

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-24 18:01:01
Message-ID: CAFj8pRDgraz64HHcCoFGCKDM1Cxv1ukELsqfsxux4JP3PM6RyQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 24. 7. 2024 v 19:02 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Wed, 2024-07-24 at 17:19 +0200, Pavel Stehule wrote:
> > > This is buggy:
> > >
> > > CREATE VARIABLE str AS text NOT NULL DEFAULT NULL;
> > >
> > > Ugh.
> > >
> > > SELECT str;
> > > ERROR: null value is not allowed for NOT NULL session variable
> "laurenz.str"
> > > DETAIL: The result of DEFAULT expression is NULL.
> > >
> > > Perhaps that is a leftover from the previous coding, but I think
> there need be
> > > no check upon SELECT. It should be enough to check during CREATE
> VARIABLE and
> > > LET.
> >
> > I think it is correct. When you use SELECT str, then DEFAULT expression
> is
> > executed, and then the result is assigned to a variable, and there is
> NOT NULL
> > guard, which raises an exception. The variable is not initialized when
> you run
> > DDL, but it is initialized when you first read or write from/to the
> variable.
> > The DEFAULT expression is not evaluated in DDL time. In this case, I can
> detect
> > the problem in DDL time because the result is transformed to NULL node,
> but
> > generally there can be SQL non immutable function, and then I need to
> wait until
> > the DEFAULT expression will be evaluated - and it is time of first
> reading.
> > Unfortunately, there is not an available check if some expression is
> NULL,
> > that I can use in DDL time, but I have it in plpgsql_check.
>
> That makes sense to me.
>
> In that case, I think we can drop the requirement that NOT NULL variables
> need a default clause.
>

removed

>
> >
> > > I can see the usefulness of IMMUTABLE variables, but I am surprised
> that
> > > they are reset by DISCARD. What is the use case you have in mind?
> > > The use case I can envision is an application that sets a value
> right after
> > > authentication, for use with row-level security. But then it would
> be harmful
> > > if the user could reset the variable with DISCARD.
> >
> > Primary I think about IMMUTABLE variables like about some form of cache.
> > This cache is protected against unwanted repeated write - and can help
> with
> > detection of this situation.
>
> We can leave it as it is. The IMMUTABLE feature need not go into the first
> release, so that can be discussed some more later.
>
> Thanks for the new patch set; I'll look at it soon.
>

Thank you very much

Regards

Pavel

>
> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240724-2-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240724-2-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.0 KB
v20240724-2-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.5 KB
v20240724-2-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240724-2-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.7 KB
v20240724-2-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240724-2-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240724-2-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.3 KB
v20240724-2-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240724-2-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.5 KB
v20240724-2-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.4 KB
v20240724-2-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.2 KB
v20240724-2-0010-implementation-of-temporary-session-variables.patch text/x-patch 38.7 KB
v20240724-2-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 12.0 KB
v20240724-2-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240724-2-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240724-2-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240724-2-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240724-2-0019-transactional-variables.patch text/x-patch 39.0 KB
v20240724-2-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-24 19:03:15
Message-ID: CAFj8pRB5utBPQvXUnNkCE9SyfcfJjA72+88znOS9GjmVBGy74A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

út 23. 7. 2024 v 23:41 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Tue, 2024-07-23 at 16:34 +0200, Laurenz Albe wrote:
> > CREATE VARIABLE command:
> >
> > This is buggy:
> >
> > CREATE VARIABLE str AS text NOT NULL DEFAULT NULL;
> >
> > Ugh.
> >
> > SELECT str;
> > ERROR: null value is not allowed for NOT NULL session variable
> "laurenz.str"
> > DETAIL: The result of DEFAULT expression is NULL.
> >
> > Perhaps that is a leftover from the previous coding, but I think there
> need be
> > no check upon SELECT. It should be enough to check during CREATE
> VARIABLE and
> > LET.
>
> I'm having second thoughts about that.
>
> I was thinking of a variable like of a table column, but there is a
> fundamental
> difference: there is a clear moment when a tuple is added (INSERT or
> UPDATE),
> which is the point where a column can be checked for NULL values.
>
> A variable can be SELECTed without having been LET before, in which case it
> has the default value. But there is no way to test the default value
> before
> the variable is SELECTed. So while DEFAULT NULL for a non-nullable
> variable
> seems weird, it is no worse than DEFAULT somefunc() for a function that
> returns
> NULL.
>
> So perhaps the behavior I complained about above is actually the right one.
> In the view of that, it doesn't seem necessary to enforce a DEFAULT value
> for
> a NOT NULL variable: NOT NULL might just as well mean "you have to LET it
> before
> you can SELECT it".
>

exactly

>
> > IMMUTABLE variables:
> >
> > + <varlistentry id="sql-createvariable-immutable">
> > + <term><literal>IMMUTABLE</literal></term>
> > + <listitem>
> > + <para>
> > + The assigned value of the session variable can not be changed.
> > + Only if the session variable doesn't have a default value, a
> single
> > + initialization is allowed using the <command>LET</command>
> command. Once
> > + done, no further change is allowed until end of transaction
> > + if the session variable was created with clause <literal>ON
> TRANSACTION
> > + END RESET</literal>, or until reset of all session variables
> by
> > + <command>DISCARD VARIABLES</command>, or until reset of all
> session
> > + objects by command <command>DISCARD ALL</command>.
> > + </para>
> > + </listitem>
> > + </varlistentry>
> >
> > I can see the usefulness of IMMUTABLE variables, but I am surprised
> that
> > they are reset by DISCARD. What is the use case you have in mind?
> > The use case I can envision is an application that sets a value right
> after
> > authentication, for use with row-level security. But then it would be
> harmful
> > if the user could reset the variable with DISCARD.
>
> I'm beginning to be uncertain about that as well. You might want to use a
> connection pool, and you LET the variable when you take it out of the pool.
> When the session is returned to the pool, variables get DISCARDed.
>
> Sure, a user can call DISCARD, but only if he or she is in an interactive
> session.
>
> So perhaps it is good as it is.
>

I think this design should work. There are a lot of scenarios, where
session variables can be used well, and sure, there will be scenarios where
it doesn't work well, but now, I think it is a good balance between
usability, complexity and code complexity. There are a lot of lines, but
the code is almost very simple.

Regards

Pavel

>
> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-25 13:52:47
Message-ID: 3b662dc5b615d4c20a55e8e2fbe6fc00fe00609d.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Thanks for the updated patch set.

I found a problem in 0019-transactional-variables.patch:

--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -9851,6 +9851,17 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
</para></entry>
</row>

+ <row>
+ <entry><structfield>varistransact</structfield></entry>
+ <entry><type>boolean</type></entry>
+ <entry></entry>
+ <entry>
+ True, when the variable is "transactional". In case of transaction
+ rollback, transactional variables are reset to their content at the
+ transaction start. The default value is false.
+ </entry>
+ </row>

That's messed up; it should be

<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>varistransact</structfield> <type>boolean</type>
</para>
<para>
True, when the variable is <quote>transactional</quote>. In the case
of a transaction rollback, transactional variables are reset to the
value they had when the transaction started. The default value is
<literal>false</literal>.
</para></entry>
</row>

I have started reading through the first patch, and so far I have only found
language problems.

I wonder how I should go about this. At first, I intended to send an edited
version of the first patch, but as later patches depend on earlier patches,
that would mess up the patch set.

I can send my suggested modifications in text, but then you have to copy and
paste them all, which is cumbersome.

What would be best for you?

Thinking further, I wondered about the order of patches.
If some committer eventually takes mercy on this patch set, I expect that
only a part of the functionality will go in as a first step.
Does the order of the patches in the patch set match such a process?

I'd guess that temporary session variables or ON TRANSACTION END RESET
would be things that can be committed later on, but PL/pgSQL support
should be in the first commit.

What is your approach to that?

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-25 16:32:24
Message-ID: CAFj8pRAsjr0pzQpQeRrQ-wR-ew1oTc6qkW=4355KveN1jKQ+1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

čt 25. 7. 2024 v 15:52 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> Thanks for the updated patch set.
>
> I found a problem in 0019-transactional-variables.patch:
>
> --- a/doc/src/sgml/catalogs.sgml
> +++ b/doc/src/sgml/catalogs.sgml
> @@ -9851,6 +9851,17 @@ SCRAM-SHA-256$<replaceable>&lt;iteration
> count&gt;</replaceable>:<replaceable>&l
> </para></entry>
> </row>
>
> + <row>
> + <entry><structfield>varistransact</structfield></entry>
> + <entry><type>boolean</type></entry>
> + <entry></entry>
> + <entry>
> + True, when the variable is "transactional". In case of transaction
> + rollback, transactional variables are reset to their content at the
> + transaction start. The default value is false.
> + </entry>
> + </row>
>
> That's messed up; it should be
>
> <row>
> <entry role="catalog_table_entry"><para role="column_definition">
> <structfield>varistransact</structfield> <type>boolean</type>
> </para>
> <para>
> True, when the variable is <quote>transactional</quote>. In the case
> of a transaction rollback, transactional variables are reset to the
> value they had when the transaction started. The default value is
> <literal>false</literal>.
> </para></entry>
> </row>
>
>
changed

> I have started reading through the first patch, and so far I have only
> found
> language problems.
>
> I wonder how I should go about this. At first, I intended to send an
> edited
> version of the first patch, but as later patches depend on earlier patches,
> that would mess up the patch set.
>
> I can send my suggested modifications in text, but then you have to copy
> and
> paste them all, which is cumbersome.
>
> What would be best for you?
>

send me it in any form - probably the diff of patches are best. I'll do
necessary fixes.

There are not good tool for maintaining chronologically incremental
patchset

>
> Thinking further, I wondered about the order of patches.
> If some committer eventually takes mercy on this patch set, I expect that
> only a part of the functionality will go in as a first step.
> Does the order of the patches in the patch set match such a process?
>

yes

we talk so first seven patches are mandatory - others are optional and
introduce new functionality or increase performance

>
> I'd guess that temporary session variables or ON TRANSACTION END RESET
> would be things that can be committed later on, but PL/pgSQL support
> should be in the first commit.
>

The plpgsql is supported by a second patch, because variables are
accessible by queries. But patch 16 introduces the
PLpgSQL LET command, and then allows us to evaluate an expression as a
simple expression, which is significantly faster.

> What is your approach to that?
>

The first six, seven patches are fundamental. For others we can talk about
priorities. I see performance related patches to be more important, but
they are a little bit more technically difficult or maybe related to a not
too cool area now (like PL/pgSQL - I like it, but almost all people's
stored procedures aren't used). Implementation of new features is almost
done by simple patches. And again for somebody temp variables are not
important (usage temp variables in PLpgSQL is +/- zero), but for others can
be very important (it can be very interesting for writing psql scripts,
because it allows parametrization of DO commands, and it is cheaper than
temp tables for passing result).

So others patches have some order, because there has to be some order, but
it is not final or immutable. I can imagine throwing these patches to
different patchset. On the second hand, the size of these patches is less
than the first two, and I think it is interesting, because from my
perspective, these patches cover this area completely. But again, the order
of these patches is important for some dependencies in files (regress
tests), but it doesn't draw the priority of implemented features. Current
state is the result of my work or work of other peoples that did review of
these patches. I am open to changing this order, if somebody would do it.

Regards

Pavel

> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240725-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.0 KB
v20240725-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240725-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.5 KB
v20240725-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240725-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.7 KB
v20240725-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240725-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.3 KB
v20240725-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240725-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240725-0010-implementation-of-temporary-session-variables.patch text/x-patch 38.7 KB
v20240725-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.5 KB
v20240725-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.4 KB
v20240725-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.2 KB
v20240725-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 12.0 KB
v20240725-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240725-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240725-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240725-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240725-0019-transactional-variables.patch text/x-patch 39.0 KB
v20240725-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-27 14:19:23
Message-ID: c29fb07fb1b55725e175e5625a5261baeab4a977.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

I went through the v20240724-2-0001 patch and mostly changed some documentation
and the comments. Attached is my updated version.

Comments:

> --- a/src/backend/catalog/namespace.c
> +++ b/src/backend/catalog/namespace.c
> [...]
> +bool
> +VariableIsVisible(Oid varid)
> [...]
> + /*
> + * Quick check: if it ain't in the path at all, it ain't visible. Items in
> + * the system namespace are surely in the path and so we needn't even do
> + * list_member_oid() for them.
> + */
> + varnamespace = varform->varnamespace;
> + if (varnamespace != PG_CATALOG_NAMESPACE &&
> + !list_member_oid(activeSearchPath, varnamespace))
> + visible = false;
> + else

I cannot imagine that we'll ever have session variables in "pg_catalog".
Did you put that there as defensive coding?

> --- a/src/backend/catalog/namespace.c
> +++ b/src/backend/catalog/namespace.c
> [...]
> +Datum
> +pg_variable_is_visible(PG_FUNCTION_ARGS)

That function should get documented in functions-info.html#FUNCTIONS-INFO-SCHEMA-TABLE
I have added an entry in the attached patch.

> --- /dev/null
> +++ b/doc/src/sgml/ref/create_variable.sgml
> [...]
> + <note>
> + <para>
> + Inside a query or an expression, the session variable can be shadowed by
> + column or by routine's variable or routine argument. Such collisions of
> + identifiers can be resolved by using qualified identifiers. Session variables
> + can use schema name, columns can use table aliases, routine variables
> + can use block labels, and routine arguments can use the routine name.
> + </para>
> + </note>
> + </refsect1>

I have slightly rewritten the text and moved it to doc/src/sgml/ddl.sgml.
I felt that to be a better place for generic information about session variable's
behavior. Also, the single paragraph in doc/src/sgml/ddl.sgml felt lonely.
I left the note in CREATE VARIABLE, but it is now just a link to ddl.sgml.

> --- a/src/bin/pg_dump/pg_dump.c
> +++ b/src/bin/pg_dump/pg_dump.c
> [...]
> +void
> +getVariables(Archive *fout)
> +{
> [...]
> + for (i = 0; i < ntups; i++)
> + {
> [...]
> + /* Decide whether we want to dump it */
> + selectDumpableObject(&(varinfo[i].dobj), fout);
> +
> + /* Do not try to dump ACL if no ACL exists. */
> + if (!PQgetisnull(res, i, i_varacl))
> + varinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
> +
> + if (strlen(varinfo[i].rolname) == 0)
> + pg_log_warning("owner of variable \"%s\" appears to be invalid",
> + varinfo[i].dobj.name);
> +
> + /* Decide whether we want to dump it */
> + selectDumpableObject(&(varinfo[i].dobj), fout);
> +
> + vtype = findTypeByOid(varinfo[i].vartype);
> + addObjectDependency(&varinfo[i].dobj, vtype->dobj.dumpId);
> + }

One of the two selectDumpableObject() calls seems redundant.
I removed the first one; I hope that's OK.

> --- a/src/bin/psql/tab-complete.c
> +++ b/src/bin/psql/tab-complete.c
> [...]
> @@ -4421,7 +4449,7 @@ psql_completion(const char *text, int start, int end)
>
> /* PREPARE xx AS */
> else if (Matches("PREPARE", MatchAny, "AS"))
> - COMPLETE_WITH("SELECT", "UPDATE", "INSERT INTO", "DELETE FROM");
> + COMPLETE_WITH("SELECT", "UPDATE", "INSERT INTO", "DELETE FROM", "LET");

I guess that belongs in the second patch, but I didn't change it.
Since the feature cannot be committed without LET, it doesn't really matter in
which of the two patches it is.

> --- a/src/test/regress/expected/psql.out
> +++ b/src/test/regress/expected/psql.out
> [...]
> +\dV regression|mydb.public.var
> +cross-database references are not implemented: regression|mydb.public.var

That's a weird test - why the pipe? Is there something I don't get?
There is already another test for cross-database references.

> +\dV "no.such.database"."no.such.schema"."no.such.variable"
> +cross-database references are not implemented: "no.such.database"."no.such.schema"."no.such.variable"

And another one. Do we need so many tests for that?

I hope I didn't create too many conflicts with the rest of the patch set.

I plan to review the other patches too, but I'll go on vacations for three weeks
in a week, and fall promises to be busy. So it might be a while.

Yours,
Laurenz Albe

Attachment Content-Type Size
v20240727-0001-Catalog-CREATE-ALTER-DROP-privileges-pg_du.patch text/x-patch 105.6 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-29 09:56:46
Message-ID: 6996931e8c9edf3b82223e74e92326a7ed06c1d6.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sat, 2024-07-27 at 16:19 +0200, Laurenz Albe wrote:
> I went through the v20240724-2-0001 patch and mostly changed some documentation
> and the comments.  Attached is my updated version.

Sorry; I forgot the new files. Here is an updated replacement for your first patch.

I'll start working on the second patch now.

Yours,
Laurenz Albe

Attachment Content-Type Size
v20240729-0001-Enhancing-catalog-for-support-session-vari.patch text/x-patch 132.7 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-30 19:46:46
Message-ID: 67aa68a7e6dfb44c0cbbdf7f97cadfede4269ce5.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

This is my review of the second patch in the series.

Again, I mostly changed code comments and documentation.

Noteworthy remarks:

- A general reminder: single line comments should start with a lower case
letter and have to period in the end:

/* this is a typical single line comment */

- Variable as parameter:

CREATE VARIABLE var AS date;
LET var = current_date;
PREPARE stmt(date) AS SELECT $1;
EXECUTE stmt(var);
ERROR: paramid of PARAM_VARIABLE param is out of range

Is that working as intended? I don't understand the error message.

Perhaps there is a bug in src/backend/executor/execExpr.c.

- IdentifyVariable

> --- a/src/backend/catalog/namespace.c
> +++ b/src/backend/catalog/namespace.c
> [...]
> +/*
> + * IdentifyVariable - try to find variable identified by list of names.
> [...]

The function comment doesn't make clear to me what the function does.
Perhaps that is so confusing because the function seems to serve several
purposes (during parsing, in ANALYZE, and to identify shadowed variables
in a later patch).

I rewrote the function comment, but didn't touch the code or code comments.

Perhaps part of the reason why this function is so complicated is that
you support things like this:

CREATE SCHEMA sch;
CREATE TYPE cp AS (a integer, b integer);
CREATE VARIABLE sch.v AS cp;
LET sch.v = (1, 2);
SELECT sch.v.b;
b
═══
2
(1 row)

test=# SELECT test.sch.v.b;
b
═══
2
(1 row)

We don't support that for tables:

CREATE TABLE tab (c cp);
INSERT INTO tab VALUES (ROW(42, 43));
SELECT tab.c.b FROM tab;
ERROR: cross-database references are not implemented: tab.c.b

You have to use extra parentheses:

SELECT (tab.c).b FROM tab;
b
════
43
(1 row)

I'd say that this should be the same for session variables.
What do you think?

Code comments:

- There are lots of variables declared at the beginning, but they are only
used in code blocks further down. For clarity, you should declare a
variable in the code block where it is used.

- + /*
+ * In this case, "a" is used as catalog name - check it.
+ */
+ if (strcmp(a, get_database_name(MyDatabaseId)) != 0)
+ {
+ if (!noerror)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cross-database references are not implemented: %s",
+ NameListToString(names))));
+ }
+ else
+ {

There needn't be an "else", since the ereport() will never return.
Less indentation is better.

- src/backend/commands/session_variable.c

There is one comment that confuses me and that I did not edit:

> +Datum
> +GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
> +{
> + SVariable svar;
> +
> + svar = get_session_variable(varid);
> +
> + /*
> + * Although svar is freshly validated in this point, the svar->is_valid can
> + * be false, due possible accepting invalidation message inside domain
> + * check. Now, the validation is done after lock, that can also accept
> + * invalidation message, so validation should be trustful.
> + *
> + * For now, we don't need to repeat validation. Only svar should be valid
> + * pointer.
> + */
> + Assert(svar);
> +
> + *typid = svar->typid;
> +
> + return copy_session_variable_value(svar, isNull);
> +}

- src/backend/executor/execMain.c

> @@ -196,6 +198,51 @@ standard_ExecutorStart(QueryDesc *queryDesc, int eflags)
> Assert(queryDesc->sourceText != NULL);
> estate->es_sourceText = queryDesc->sourceText;
>
> + /*
> + * The executor doesn't work with session variables directly. Values of
> + * related session variables are copied to dedicated array, and this array
> + * is passed to executor.
> + */

Why? Is that a performance measure? The comment should explain that.

- parallel safety

> --- a/src/backend/optimizer/util/clauses.c
> +++ b/src/backend/optimizer/util/clauses.c
> @@ -935,6 +936,13 @@ max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
> if (param->paramkind == PARAM_EXTERN)
> return false;
>
> + /* We doesn't support passing session variables to workers */
> + if (param->paramkind == PARAM_VARIABLE)
> + {
> + if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED, context))
> + return true;
> + }

Even if a later patch alleviates that restriction, this patch should document that
session variables imply "parallel restricted". I have added that to doc/src/sgml/parallel.sgml.

Attached are the first two patches with my edits (the first patch is unchanged;
I just add it again to keep the cfbot happy.

I hope to get to review the other patches at some later time.

Yours,
Laurenz Albe

Attachment Content-Type Size
v20240730-0001-Enhancing-catalog-for-support-session-vari.patch text/x-patch 132.7 KB
v20240730-0002-Storage-for-session-variables-and-SQL-inte.patch text/x-patch 119.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-30 20:56:19
Message-ID: CAFj8pRBRkK_hNz6MmCb7nKathY=hqn04AQPozHUU_od1nm=hcw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

so 27. 7. 2024 v 16:19 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> I went through the v20240724-2-0001 patch and mostly changed some
> documentation
> and the comments. Attached is my updated version.
>
> Comments:
>
> > --- a/src/backend/catalog/namespace.c
> > +++ b/src/backend/catalog/namespace.c
> > [...]
> > +bool
> > +VariableIsVisible(Oid varid)
> > [...]
> > + /*
> > + * Quick check: if it ain't in the path at all, it ain't visible.
> Items in
> > + * the system namespace are surely in the path and so we needn't
> even do
> > + * list_member_oid() for them.
> > + */
> > + varnamespace = varform->varnamespace;
> > + if (varnamespace != PG_CATALOG_NAMESPACE &&
> > + !list_member_oid(activeSearchPath, varnamespace))
> > + visible = false;
> > + else
>
> I cannot imagine that we'll ever have session variables in "pg_catalog".
> Did you put that there as defensive coding?
>

No, I just used a pattern for relations. I removed the test against
PG_CATALOG_NAMESPACE and wrote comment

<-->/*
<--> * Quick check: if it ain't in the path at all, it ain't visible. We
<--> * don't expect usage of session variables in the system namespace.
<--> */

>
> > --- a/src/backend/catalog/namespace.c
> > +++ b/src/backend/catalog/namespace.c
> > [...]
> > +Datum
> > +pg_variable_is_visible(PG_FUNCTION_ARGS)
>
> That function should get documented in
> functions-info.html#FUNCTIONS-INFO-SCHEMA-TABLE
> I have added an entry in the attached patch.
>

merged

>
> > --- /dev/null
> > +++ b/doc/src/sgml/ref/create_variable.sgml
> > [...]
> > + <note>
> > + <para>
> > + Inside a query or an expression, the session variable can be
> shadowed by
> > + column or by routine's variable or routine argument. Such
> collisions of
> > + identifiers can be resolved by using qualified identifiers. Session
> variables
> > + can use schema name, columns can use table aliases, routine
> variables
> > + can use block labels, and routine arguments can use the routine
> name.
> > + </para>
> > + </note>
> > + </refsect1>
>
> I have slightly rewritten the text and moved it to doc/src/sgml/ddl.sgml.
> I felt that to be a better place for generic information about session
> variable's
> behavior. Also, the single paragraph in doc/src/sgml/ddl.sgml felt lonely.
> I left the note in CREATE VARIABLE, but it is now just a link to ddl.sgml.
>

merged

>
> > --- a/src/bin/pg_dump/pg_dump.c
> > +++ b/src/bin/pg_dump/pg_dump.c
> > [...]
> > +void
> > +getVariables(Archive *fout)
> > +{
> > [...]
> > + for (i = 0; i < ntups; i++)
> > + {
> > [...]
> > + /* Decide whether we want to dump it */
> > + selectDumpableObject(&(varinfo[i].dobj), fout);
> > +
> > + /* Do not try to dump ACL if no ACL exists. */
> > + if (!PQgetisnull(res, i, i_varacl))
> > + varinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
> > +
> > + if (strlen(varinfo[i].rolname) == 0)
> > + pg_log_warning("owner of variable \"%s\" appears to be
> invalid",
> > + varinfo[i].dobj.name);
> > +
> > + /* Decide whether we want to dump it */
> > + selectDumpableObject(&(varinfo[i].dobj), fout);
> > +
> > + vtype = findTypeByOid(varinfo[i].vartype);
> > + addObjectDependency(&varinfo[i].dobj, vtype->dobj.dumpId);
> > + }
>
> One of the two selectDumpableObject() calls seems redundant.
> I removed the first one; I hope that's OK.
>

sure

>
> > --- a/src/bin/psql/tab-complete.c
> > +++ b/src/bin/psql/tab-complete.c
> > [...]
> > @@ -4421,7 +4449,7 @@ psql_completion(const char *text, int start, int
> end)
> >
> > /* PREPARE xx AS */
> > else if (Matches("PREPARE", MatchAny, "AS"))
> > - COMPLETE_WITH("SELECT", "UPDATE", "INSERT INTO", "DELETE FROM");
> > + COMPLETE_WITH("SELECT", "UPDATE", "INSERT INTO", "DELETE FROM",
> "LET");
>
> I guess that belongs in the second patch, but I didn't change it.
> Since the feature cannot be committed without LET, it doesn't really
> matter in
> which of the two patches it is.
>
> > --- a/src/test/regress/expected/psql.out
> > +++ b/src/test/regress/expected/psql.out
> > [...]
> > +\dV regression|mydb.public.var
> > +cross-database references are not implemented:
> regression|mydb.public.var
>

> That's a weird test - why the pipe? Is there something I don't get?
>

This test is not related to pipe, but usage of invalid multipart names

These tests look weird, but when you look at the psql.out file, then it is
consistent with others.

There is already another test for cross-database references.
>
> > +\dV "no.such.database"."no.such.schema"."no.such.variable"
> > +cross-database references are not implemented:
> "no.such.database"."no.such.schema"."no.such.variable"
>
> And another one. Do we need so many tests for that?
>

It is crash psql parser test - these tests are designed like \dt or \di

>
>
> I hope I didn't create too many conflicts with the rest of the patch set.
>
> I plan to review the other patches too, but I'll go on vacations for three
> weeks
> in a week, and fall promises to be busy. So it might be a while.
>

I am sending patches with merged your changes (related to first patch)

Regards

Pavel

>
> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240730-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240730-0019-transactional-variables.patch text/x-patch 39.1 KB
v20240730-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240730-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240730-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240730-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240730-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 12.0 KB
v20240730-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.4 KB
v20240730-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240730-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.2 KB
v20240730-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240730-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240730-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240730-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.3 KB
v20240730-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240730-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.5 KB
v20240730-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240730-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240730-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.8 KB
v20240730-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-31 06:41:50
Message-ID: CAFj8pRB4oRVXTqChg0JH0XCKv33assFGr4jmUw3ht+4C6ac2PQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

út 30. 7. 2024 v 21:46 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> This is my review of the second patch in the series.
>
> Again, I mostly changed code comments and documentation.
>
> Noteworthy remarks:
>
> - A general reminder: single line comments should start with a lower case
> letter and have to period in the end:
>
> /* this is a typical single line comment */
>
> - Variable as parameter:
>
> CREATE VARIABLE var AS date;
> LET var = current_date;
> PREPARE stmt(date) AS SELECT $1;
> EXECUTE stmt(var);
> ERROR: paramid of PARAM_VARIABLE param is out of range
>
> Is that working as intended? I don't understand the error message.
>
> Perhaps there is a bug in src/backend/executor/execExpr.c.
>
> - IdentifyVariable
>
> > --- a/src/backend/catalog/namespace.c
> > +++ b/src/backend/catalog/namespace.c
> > [...]
> > +/*
> > + * IdentifyVariable - try to find variable identified by list of
> names.
> > [...]
>
> The function comment doesn't make clear to me what the function does.
> Perhaps that is so confusing because the function seems to serve several
> purposes (during parsing, in ANALYZE, and to identify shadowed variables
> in a later patch).
>
> I rewrote the function comment, but didn't touch the code or code
> comments.
>
> Perhaps part of the reason why this function is so complicated is that
> you support things like this:
>
> CREATE SCHEMA sch;
> CREATE TYPE cp AS (a integer, b integer);
> CREATE VARIABLE sch.v AS cp;
> LET sch.v = (1, 2);
> SELECT sch.v.b;
> b
> ═══
> 2
> (1 row)
>
> test=# SELECT test.sch.v.b;
> b
> ═══
> 2
> (1 row)
>
> We don't support that for tables:
>
> CREATE TABLE tab (c cp);
> INSERT INTO tab VALUES (ROW(42, 43));
> SELECT tab.c.b FROM tab;
> ERROR: cross-database references are not implemented: tab.c.b
>
> You have to use extra parentheses:
>
> SELECT (tab.c).b FROM tab;
> b
> ════
> 43
> (1 row)
>
> I'd say that this should be the same for session variables.
> What do you think?
>
> Code comments:
>
> - There are lots of variables declared at the beginning, but they are
> only
> used in code blocks further down. For clarity, you should declare a
> variable in the code block where it is used.
>
> - + /*
> + * In this case, "a" is used as catalog name -
> check it.
> + */
> + if (strcmp(a, get_database_name(MyDatabaseId)) !=
> 0)
> + {
> + if (!noerror)
> + ereport(ERROR,
> +
> (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> + errmsg("cross-database references
> are not implemented: %s",
> + NameListToString(names))));
> + }
> + else
> + {
>
> There needn't be an "else", since the ereport() will never return.
> Less indentation is better.
>
> - src/backend/commands/session_variable.c
>
> There is one comment that confuses me and that I did not edit:
>
> > +Datum
> > +GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
> > +{
> > + SVariable svar;
> > +
> > + svar = get_session_variable(varid);
> > +
> > + /*
> > + * Although svar is freshly validated in this point, the
> svar->is_valid can
> > + * be false, due possible accepting invalidation message inside
> domain
> > + * check. Now, the validation is done after lock, that can also
> accept
> > + * invalidation message, so validation should be trustful.
> > + *
> > + * For now, we don't need to repeat validation. Only svar should
> be valid
> > + * pointer.
> > + */
> > + Assert(svar);
> > +
> > + *typid = svar->typid;
> > +
> > + return copy_session_variable_value(svar, isNull);
> > +}
>
> - src/backend/executor/execMain.c
>
> > @@ -196,6 +198,51 @@ standard_ExecutorStart(QueryDesc *queryDesc, int
> eflags)
> > Assert(queryDesc->sourceText != NULL);
> > estate->es_sourceText = queryDesc->sourceText;
> >
> > + /*
> > + * The executor doesn't work with session variables directly.
> Values of
> > + * related session variables are copied to dedicated array, and
> this array
> > + * is passed to executor.
> > + */
>
> Why? Is that a performance measure? The comment should explain that.
>
> - parallel safety
>
> > --- a/src/backend/optimizer/util/clauses.c
> > +++ b/src/backend/optimizer/util/clauses.c
> > @@ -935,6 +936,13 @@ max_parallel_hazard_walker(Node *node,
> max_parallel_hazard_context *context)
> > if (param->paramkind == PARAM_EXTERN)
> > return false;
> >
> > + /* We doesn't support passing session variables to workers */
> > + if (param->paramkind == PARAM_VARIABLE)
> > + {
> > + if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED,
> context))
> > + return true;
> > + }
>
> Even if a later patch alleviates that restriction, this patch should
> document that
> session variables imply "parallel restricted". I have added that to
> doc/src/sgml/parallel.sgml.
>
> Attached are the first two patches with my edits (the first patch is
> unchanged;
> I just add it again to keep the cfbot happy.
>

Probably you didn't attach new files - the second patch is not complete. Or
you didn't make changes there?

Regards

Pavel

>
> I hope to get to review the other patches at some later time.
>
> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-31 06:57:31
Message-ID: 263ef86d2cc97751e4833d79f3713d4a02b4cfb0.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Wed, 2024-07-31 at 08:41 +0200, Pavel Stehule wrote:
> Probably you didn't attach new files - the second patch is not complete. Or you didn't make changes there?

Hm. What is missing?

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-31 07:04:08
Message-ID: CAFj8pRBEN2LbGs-djJMQLNsM9jLgKixwkjgduZFJAZy5Kd=mqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 31. 7. 2024 v 8:57 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Wed, 2024-07-31 at 08:41 +0200, Pavel Stehule wrote:
> > Probably you didn't attach new files - the second patch is not complete.
> Or you didn't make changes there?
>
> Hm. What is missing?
>

let.sgml,
session_variable.c
svariable_receiver.c
session_variable.h
...

Regards

Pavel

>
> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-31 09:45:00
Message-ID: f7e8030fdd1f1515e0ab960126a6d924b4936af8.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Wed, 2024-07-31 at 09:04 +0200, Pavel Stehule wrote:
> st 31. 7. 2024 v 8:57 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> napsal:
> > On Wed, 2024-07-31 at 08:41 +0200, Pavel Stehule wrote:
> > > Probably you didn't attach new files - the second patch is not complete. Or you didn't make changes there?
> >
> > Hm.  What is missing?
>
> let.sgml,
> session_variable.c
> svariable_receiver.c 
> session_variable.h
> ...

Argh, I forgit the new files, sorry.

The attached patches should be complete.

Yours,
Laurenz Albe

Attachment Content-Type Size
v20240731-0001-Enhancing-catalog-for-support-session-vari.patch text/x-patch 132.7 KB
v20240731-0002-Storage-for-session-variables-and-SQL-inte.patch text/x-patch 145.4 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-07-31 22:05:54
Message-ID: CAFj8pRAVN=uw=qUZGQqug6UfG4c21Y1+VTbs_99w0sdqfHN-cg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

st 31. 7. 2024 v 11:45 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Wed, 2024-07-31 at 09:04 +0200, Pavel Stehule wrote:
> > st 31. 7. 2024 v 8:57 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
> napsal:
> > > On Wed, 2024-07-31 at 08:41 +0200, Pavel Stehule wrote:
> > > > Probably you didn't attach new files - the second patch is not
> complete. Or you didn't make changes there?
> > >
> > > Hm. What is missing?
> >
> > let.sgml,
> > session_variable.c
> > svariable_receiver.c
> > session_variable.h
> > ...
>
> Argh, I forgit the new files, sorry.
>
> The attached patches should be complete.
>

merged Laurenz's patches

Regards

Pavel

>
> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240801-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240801-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240801-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240801-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240801-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240801-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240801-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 11.9 KB
v20240801-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240801-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240801-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240801-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240801-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240801-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240801-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240801-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240801-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240801-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240801-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240801-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB
v20240801-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.5 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-01 06:12:13
Message-ID: CAFj8pRAFaaeRnM3F9BV5FLh-MgqY1t_v1QowoXi7HJ_bD1kX5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase + fix format in doc

Regards

Pavel

Attachment Content-Type Size
v20240801-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240801-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240801-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240801-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240801-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240801-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240801-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 12.0 KB
v20240801-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240801-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240801-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240801-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240801-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240801-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240801-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240801-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240801-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240801-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240801-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240801-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.5 KB
v20240801-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Erik Rijkers <er(at)xs4all(dot)nl>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-01 07:45:34
Message-ID: b3a7ec1f-6460-a40a-6bac-d4a70494d3c5@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

doc-build fails: a slash tumbled backwards in doc/src/sgml:

$ grep 'xref.*.\\>' *.sgml
plpgsql.sgml: (see <xref linkend="ddl-session-variables"\>).

That should simply be a forward slash, of course.

Thanks,

Erik Rijkers

Op 8/1/24 om 08:12 schreef Pavel Stehule:
> Hi
>
> fresh rebase + fix format in doc
>
> Regards
>
> Pavel
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Erik Rijkers <er(at)xs4all(dot)nl>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-01 07:48:16
Message-ID: CAFj8pRDGhn05o9PxTAnTzHnoF5SCxFU4e9JiXVCkfW0tYgTxhw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 1. 8. 2024 v 9:45 odesílatel Erik Rijkers <er(at)xs4all(dot)nl> napsal:

> doc-build fails: a slash tumbled backwards in doc/src/sgml:
>
> $ grep 'xref.*.\\>' *.sgml
> plpgsql.sgml: (see <xref linkend="ddl-session-variables"\>).
>
> That should simply be a forward slash, of course.
>

should be fixed in my today patchset

>
> Thanks,
>
> Erik Rijkers
>
>
>
>
> Op 8/1/24 om 08:12 schreef Pavel Stehule:
> > Hi
> >
> > fresh rebase + fix format in doc
> >
> > Regards
> >
> > Pavel
> >
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-01 11:22:01
Message-ID: d1fea4cc5d74100b69fb4f5ceaadc2a6979a8c87.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, 2024-08-01 at 08:12 +0200, Pavel Stehule wrote:
> fresh rebase + fix format in doc

Thanks!

I'm curious, but too lazy to build the patch now, so I'm asking:
what did you do about this error?

> CREATE VARIABLE var AS date;
> LET var = current_date;
> PREPARE stmt(date) AS SELECT $1;
> EXECUTE stmt(var);
> ERROR: paramid of PARAM_VARIABLE param is out of range

Or does a later patch take care of that?

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-01 11:24:58
Message-ID: CAFj8pRAK5TFMxuEOa9PcF4CSc7GxEpgo9w0zRWpTvyMPH7Xmng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 1. 8. 2024 v 13:22 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Thu, 2024-08-01 at 08:12 +0200, Pavel Stehule wrote:
> > fresh rebase + fix format in doc
>
> Thanks!
>
> I'm curious, but too lazy to build the patch now, so I'm asking:
> what did you do about this error?
>

I try to investigate this issue now.

The patchset is just merging of your work

> > CREATE VARIABLE var AS date;
> > LET var = current_date;
> > PREPARE stmt(date) AS SELECT $1;
> > EXECUTE stmt(var);
> > ERROR: paramid of PARAM_VARIABLE param is out of range
>

>
> Or does a later patch take care of that?
>

This is a clear bug, and I have to fix it. I hope so I'll do this today

>
> Yours,
> Laurenz Albe
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-01 22:02:27
Message-ID: CAFj8pRDQjOYF5yCUzPfAXgeVUUW0qV5XdeoG0mJy2dPrjGNFSQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 1. 8. 2024 v 13:22 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Thu, 2024-08-01 at 08:12 +0200, Pavel Stehule wrote:
> > fresh rebase + fix format in doc
>
> Thanks!
>
> I'm curious, but too lazy to build the patch now, so I'm asking:
> what did you do about this error?
>
> > CREATE VARIABLE var AS date;
> > LET var = current_date;
> > PREPARE stmt(date) AS SELECT $1;
> > EXECUTE stmt(var);
> > ERROR: paramid of PARAM_VARIABLE param is out of range
>
> Or does a later patch take care of that?
>

It is working with patch "allow read an value of session variable directly
from expression executor"

It looks very similar to evaluation of parameters of CALL statements.
Without the mentioned patch, the CALL statements don't allow variables as
an argument. I blocked usage of session variables as EXECUTE parameters
until direct access to session variables in expression evaluation is
supported.

Regards

Pavel

> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240801-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240801-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 13.6 KB
v20240801-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240801-0020-transactional-variables.patch text/x-patch 39.2 KB
v20240801-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240801-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240801-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.5 KB
v20240801-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240801-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240801-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240801-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240801-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240801-0011-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240801-0008-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240801-0007-plpgsql-tests.patch text/x-patch 16.9 KB
v20240801-0006-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240801-0005-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240801-0004-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240801-0003-regress-tests.patch text/x-patch 1.8 KB
v20240801-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 146.3 KB
v20240801-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-03 05:40:00
Message-ID: CAFj8pRBCVm_6a3O0S7kKUxmu1A4026FAodo=4zGf+vLQy1-0TQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix build plpgsql

Regards

Pavel

Attachment Content-Type Size
v20240803-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240803-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240803-0020-transactional-variables.patch text/x-patch 39.2 KB
v20240803-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240803-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240803-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240803-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240803-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.5 KB
v20240803-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240803-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240803-0011-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240803-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240803-0008-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240803-0007-plpgsql-tests.patch text/x-patch 16.9 KB
v20240803-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240803-0006-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240803-0003-regress-tests.patch text/x-patch 1.8 KB
v20240803-0005-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240803-0004-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240803-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 146.3 KB
v20240803-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-07 10:00:14
Message-ID: CAFj8pRAskimJmB9Q8pHDa8YoLphVoZMH1xPeGBK8Eze=u+_hBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase + usage hash_seq_init_with_hash_value

Attention - regress tests fails due problem with
hash_seq_init_with_hash_value

Regards

Pavel

Attachment Content-Type Size
v20240807-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240807-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240807-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240807-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240807-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240807-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240807-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.5 KB
v20240807-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240807-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240807-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240807-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240807-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240807-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240807-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240807-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240807-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240807-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240807-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240807-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 146.9 KB
v20240807-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-08 05:17:00
Message-ID: CAFj8pRCRbyjPMOjq=1QSrks1R1WRy91wn3ib+ipmp=Cwn6Qckg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase + revert usage of hash_seq_init_with_hash_value

regards

Pavel

Attachment Content-Type Size
v20240808-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240808-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240808-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240808-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240808-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240808-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.3 KB
v20240808-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.5 KB
v20240808-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 36.0 KB
v20240808-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240808-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240808-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240808-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240808-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240808-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240808-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240808-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240808-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240808-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240808-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 146.8 KB
v20240808-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-15 05:55:15
Message-ID: CAFj8pRDF-F5diNTXr206QfQFauFNK1vu_7NARXd0dtdwGTWLMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

út 30. 7. 2024 v 21:46 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> This is my review of the second patch in the series.
>
> Again, I mostly changed code comments and documentation.
>
> Noteworthy remarks:
>
> - A general reminder: single line comments should start with a lower case
> letter and have to period in the end:
>

Should it be "have not to period in the end" ?

>
> /* this is a typical single line comment */
>

I fixed almost all without parts related to psql and executor - there
almost all current comments break the mentioned rule. So I use the style
used in these files. I can fix it (if you like it) - or it can be fixed
generally in a separated patch set.

> - Variable as parameter:
>
> CREATE VARIABLE var AS date;
> LET var = current_date;
> PREPARE stmt(date) AS SELECT $1;
> EXECUTE stmt(var);
> ERROR: paramid of PARAM_VARIABLE param is out of range
>
> Is that working as intended? I don't understand the error message.
>

fixed in 0002 patch (variables cannot be used as EXECUTE argument) and 0014
(enable usage variables as an argument of EXECUTE)

>
> Perhaps there is a bug in src/backend/executor/execExpr.c.
>
> - IdentifyVariable
>
> > --- a/src/backend/catalog/namespace.c
> > +++ b/src/backend/catalog/namespace.c
> > [...]
> > +/*
> > + * IdentifyVariable - try to find variable identified by list of
> names.
> > [...]
>
> The function comment doesn't make clear to me what the function does.
> Perhaps that is so confusing because the function seems to serve several
> purposes (during parsing, in ANALYZE, and to identify shadowed variables
> in a later patch).
>
> I rewrote the function comment, but didn't touch the code or code
> comments.
>

merged

>
> Perhaps part of the reason why this function is so complicated is that
> you support things like this:
>
> CREATE SCHEMA sch;
> CREATE TYPE cp AS (a integer, b integer);
> CREATE VARIABLE sch.v AS cp;
> LET sch.v = (1, 2);
> SELECT sch.v.b;
> b
> ═══
> 2
> (1 row)
>
> test=# SELECT test.sch.v.b;
> b
> ═══
> 2
> (1 row)
>
> We don't support that for tables:
>
> CREATE TABLE tab (c cp);
> INSERT INTO tab VALUES (ROW(42, 43));
> SELECT tab.c.b FROM tab;
> ERROR: cross-database references are not implemented: tab.c.b
>
> You have to use extra parentheses:
>
> SELECT (tab.c).b FROM tab;
> b
> ════
> 43
> (1 row)
>
> I'd say that this should be the same for session variables.
> What do you think?
>

I prefer the current state, but I don't have a very strong opinion about
it. It can save 115 lines of almost trivial code, but I think the user
experience can be much worse. Using composite types in tables is not too
common a pattern (and when I read some recommendations for Oracle, it is an
antipattern), but usage of composite variables is common (it can hold a
row). Moreover, we talked long about possible identifier's collisions, and
the pattern schema.variable is very good protection against possible
collisions. Probably the pattern catalog.schema.variable.field is not too
interesting but the support has 50 lines.

More, the plpgsql supports pattern label.variable.field, so can be little
bit unfriendly if session variables doesn't support "similar" pattern

create type t as (x int, y int);
do $$
<<lab1>>declare v t;
begin
v := (20,20); raise notice '%', lab1.v.x;
end $$;
NOTICE: 20
DO

> Code comments:
>
> - There are lots of variables declared at the beginning, but they are
> only
> used in code blocks further down. For clarity, you should declare a
> variable in the code block where it is used.
>

moved

>
> - + /*
> + * In this case, "a" is used as catalog name -
> check it.
> + */
> + if (strcmp(a, get_database_name(MyDatabaseId)) !=
> 0)
> + {
> + if (!noerror)
> + ereport(ERROR,
> +
> (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> + errmsg("cross-database references
> are not implemented: %s",
> + NameListToString(names))));
> + }
> + else
> + {
>
> There needn't be an "else", since the ereport() will never return.
> Less indentation is better.
>
>
done

> - src/backend/commands/session_variable.c
>
> There is one comment that confuses me and that I did not edit:
>
> > +Datum
> > +GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
> > +{
> > + SVariable svar;
> > +
> > + svar = get_session_variable(varid);
> > +
> > + /*
> > + * Although svar is freshly validated in this point, the
> svar->is_valid can
> > + * be false, due possible accepting invalidation message inside
> domain
> > + * check. Now, the validation is done after lock, that can also
> accept
> > + * invalidation message, so validation should be trustful.
> > + *
> > + * For now, we don't need to repeat validation. Only svar should
> be valid
> > + * pointer.
> > + */
>

This comment is related to assertions. Before I had there
`Assert(svar->is_valid)`, because I expected it. But it was not always
true. And although it is true, we don't need to validate a variable,
because at this moment, the variable should be locked, and then we can
return content safely.

> > + Assert(svar);
> > +
> > + *typid = svar->typid;
> > +
> > + return copy_session_variable_value(svar, isNull);
> > +}
>
>

> - src/backend/executor/execMain.c
>
> > @@ -196,6 +198,51 @@ standard_ExecutorStart(QueryDesc *queryDesc, int
> eflags)
> > Assert(queryDesc->sourceText != NULL);
> > estate->es_sourceText = queryDesc->sourceText;
> >
> > + /*
> > + * The executor doesn't work with session variables directly.
> Values of
> > + * related session variables are copied to dedicated array, and
> this array
> > + * is passed to executor.
> > + */
>
> Why? Is that a performance measure? The comment should explain that.
>

Session variables are volatile internally - some function that uses LET
statements can be called more times inside a query. This behavior is not
consistent with plpgsql's variables or external parameters. And if we want
to support parallel queries, then volatile session variables can be pretty
messy (and unusable). If we want the same behaviour for queries with or
without parallel support, then the session variables should be "stable"
(like stable functions). Simple implementation is using "snapshot" of
values of used session variables when query is started. This "snapshot" is
immutable, so we don't need to make a copy more times.

I changed this comment

<-->/*
<--> * The executor doesn't work with session variables directly. Values of
<--> * related session variables are copied to a dedicated array, and this
array
<--> * is passed to the executor. This array is stable "snapshot" of values
of used
<--> * session variables. There are three benefits of this strategy:
<--> *
<--> * - consistency with external parameters and plpgsql variables,
<--> *
<--> * - session variables can be parallel safe,
<--> *
<--> * - we don't need make fresh copy for any read of session variable
<--> * (this is necessary because the internally the session variable can
<--> * be changed inside query execution time, and then a reference to
<--> * previously returned value can be corrupted).
<--> */

> - parallel safety
>
> > --- a/src/backend/optimizer/util/clauses.c
> > +++ b/src/backend/optimizer/util/clauses.c
> > @@ -935,6 +936,13 @@ max_parallel_hazard_walker(Node *node,
> max_parallel_hazard_context *context)
> > if (param->paramkind == PARAM_EXTERN)
> > return false;
> >
> > + /* We doesn't support passing session variables to workers */
> > + if (param->paramkind == PARAM_VARIABLE)
> > + {
> > + if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED,
> context))
> > + return true;
> > + }
>
> Even if a later patch alleviates that restriction, this patch should
> document that
> session variables imply "parallel restricted". I have added that to
> doc/src/sgml/parallel.sgml.
>

merged (and removed in 0015)

>
> Attached are the first two patches with my edits (the first patch is
> unchanged;
> I just add it again to keep the cfbot happy.
>
> I hope to get to review the other patches at some later time.
>
> Yours,
> Laurenz Albe
>

Attached new patchset

Regards

Pavel

Attachment Content-Type Size
v20240815-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.1 KB
v20240815-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240815-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240815-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240815-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB
v20240815-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240815-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240815-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240815-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240815-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240815-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240815-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240815-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20240815-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20240815-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20240815-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240815-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240815-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240815-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240815-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-27 06:15:42
Message-ID: 04ec666686e9e21cb515617df06885c66f3d34ce.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, 2024-08-15 at 07:55 +0200, Pavel Stehule wrote:
> út 30. 7. 2024 v 21:46 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> napsal:
> > - A general reminder: single line comments should start with a lower case
> >   letter and have to period in the end:
>
> Should it be "have not to period in the end" ?

I made a typo. I mean "have *no* period in the end".

> I fixed almost all without parts related to psql and executor - there almost all
> current comments break the mentioned rule. So I use the style used in these files.
> I can fix it (if you like it) - or it can be fixed generally in a separated patch set.

Thanks. I also noticed that a lot of existing comments break that rule,
so I think that it is fine if you stick with the way that the surrounding
code does it.

> > - Variable as parameter:
> >
> >   CREATE VARIABLE var AS date;
> >   LET var = current_date;
> >   PREPARE stmt(date) AS SELECT $1;
> >   EXECUTE stmt(var);
> >   ERROR:  paramid of PARAM_VARIABLE param is out of range
> >
> >   Is that working as intended?  I don't understand the error message.
>
> fixed in 0002 patch (variables cannot be used as EXECUTE argument) and 0014 (enable usage variables as an argument of EXECUTE)

Thanks.

> >   > --- a/src/backend/catalog/namespace.c
> >   > +++ b/src/backend/catalog/namespace.c
> >   > [...]
> >   > +/*
> >   > + * IdentifyVariable - try to find variable identified by list of names.
> >   > [...]
> >
> >   Perhaps part of the reason why this function is so complicated is that
> >   you support things like this:
> >
> >     CREATE SCHEMA sch;
> >     CREATE TYPE cp AS (a integer, b integer);
> >     CREATE VARIABLE sch.v AS cp;
> >     LET sch.v = (1, 2);
> >     SELECT sch.v.b;
> >      b
> >     ═══
> >      2
> >     (1 row)
> >
> >     test=# SELECT test.sch.v.b;
> >      b
> >     ═══
> >      2
> >     (1 row)
> >
> >   We don't support that for tables:
> >
> >     CREATE TABLE tab (c cp);
> >     INSERT INTO tab VALUES (ROW(42, 43));
> >     SELECT tab.c.b FROM tab;
> >     ERROR:  cross-database references are not implemented: tab.c.b
> >
> >   You have to use extra parentheses:
> >
> >     SELECT (tab.c).b FROM tab;
> >      b 
> >     ════
> >      43
> >     (1 row)
> >
> >   I'd say that this should be the same for session variables.
> >   What do you think?
>
> I prefer the current state, but I don't have a very strong opinion about it.
> It can save 115 lines of almost trivial code, but I think the user experience
> can be much worse.  Using composite types in tables is not too common a
> pattern (and when I read some recommendations for Oracle, it is an antipattern),
> but usage of composite variables is common (it can hold a row). Moreover,
> we talked long about possible identifier's collisions, and the pattern
> schema.variable is very good protection against possible collisions.
> Probably the pattern catalog.schema.variable.field is not too interesting
> but the support has 50 lines.
>
> More, the plpgsql supports pattern label.variable.field, so can be little bit
> unfriendly if session variables doesn't support "similar" pattern

I see your point, and I'm fine with leaving it as it is.

>
>
> > - src/backend/commands/session_variable.c
> >
> >   There is one comment that confuses me and that I did not edit:
> >
> >   > +Datum
> >   > +GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
> >   > +{
> >   > +   SVariable   svar;
> >   > +
> >   > +   svar = get_session_variable(varid);
> >   > +
> >   > +   /*
> >   > +    * Although svar is freshly validated in this point, the svar->is_valid can
> >   > +    * be false, due possible accepting invalidation message inside domain
> >   > +    * check. Now, the validation is done after lock, that can also accept
> >   > +    * invalidation message, so validation should be trustful.
> >   > +    *
> >   > +    * For now, we don't need to repeat validation. Only svar should be valid
> >   > +    * pointer.
> >   > +    */
>
> This comment is related to assertions. Before I had there `Assert(svar->is_valid)`,
> because I expected it. But it was not always true. And although it is true,
> we don't need to validate a variable, because at this moment, the variable
> should be locked, and then we can return content safely.

I guess my main problem is the word "trustful". I don't recognize that word.
Perhaps you can reword the comment along the lines of your above explanation.

>
> > - src/backend/executor/execMain.c
> >
> >   > @@ -196,6 +198,51 @@ standard_ExecutorStart(QueryDesc *queryDesc, int eflags)
> >   >     Assert(queryDesc->sourceText != NULL);
> >   >     estate->es_sourceText = queryDesc->sourceText;
> >   >
> >   > +   /*
> >   > +    * The executor doesn't work with session variables directly. Values of
> >   > +    * related session variables are copied to dedicated array, and this array
> >   > +    * is passed to executor.
> >   > +    */
> >
> >   Why?  Is that a performance measure?  The comment should explain that.
>
> Session variables are volatile internally - some function that uses LET statements
> can be called more times inside a query. This behavior is not consistent with
> plpgsql's variables or external parameters. And if we want to support parallel
> queries, then volatile session variables can be pretty messy (and unusable).
> If we want the same behaviour for queries with or without parallel support,
> then the session variables should be "stable" (like stable functions).
> Simple implementation is using "snapshot" of values of used session variables
> when query is started. This "snapshot" is immutable, so we don't need to make
> a copy more times.
>
> I changed this comment

Thanks.

> > - parallel safety
> >
> >   > --- a/src/backend/optimizer/util/clauses.c
> >   > +++ b/src/backend/optimizer/util/clauses.c
> >   > @@ -935,6 +936,13 @@ max_parallel_hazard_walker(Node *node, max_parallel_hazard_context *context)
> >   >         if (param->paramkind == PARAM_EXTERN)
> >   >             return false;
> >   >
> >   > +       /* We doesn't support passing session variables to workers */
> >   > +       if (param->paramkind == PARAM_VARIABLE)
> >   > +       {
> >   > +           if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED, context))
> >   > +               return true;
> >   > +       }
> >
> >   Even if a later patch alleviates that restriction, this patch should document that
> >   session variables imply "parallel restricted".  I have added that to doc/src/sgml/parallel.sgml.
> >
>
> merged (and removed in 0015)

Thanks.

I hope I can do some more review at some point in the future...

I sincerely hope that this patch set gets merged at some point.
The big obstacle is that it is so large. That's probably because it is pretty
feature-complete (but, as we have found, not totally free of bugs).

Judging from the amount of time I put into my review so far, I guess that this
patch set would keep a committer busy for several weeks. Perhaps the only way to
get this done would be to make you a committer...

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-27 06:52:27
Message-ID: CAFj8pRCy8NTG3ewOrH0KLQgrMpVMSzPjhoLKW=c1Jjz8QWNSKw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

út 27. 8. 2024 v 8:15 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Thu, 2024-08-15 at 07:55 +0200, Pavel Stehule wrote:
> > út 30. 7. 2024 v 21:46 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
> napsal:
> > > - A general reminder: single line comments should start with a lower
> case
> > > letter and have to period in the end:
> >
> > Should it be "have not to period in the end" ?
>
> I made a typo. I mean "have *no* period in the end".
>
> > I fixed almost all without parts related to psql and executor - there
> almost all
> > current comments break the mentioned rule. So I use the style used in
> these files.
> > I can fix it (if you like it) - or it can be fixed generally in a
> separated patch set.
>
> Thanks. I also noticed that a lot of existing comments break that rule,
> so I think that it is fine if you stick with the way that the surrounding
> code does it.
>
> > > - Variable as parameter:
> > >
> > > CREATE VARIABLE var AS date;
> > > LET var = current_date;
> > > PREPARE stmt(date) AS SELECT $1;
> > > EXECUTE stmt(var);
> > > ERROR: paramid of PARAM_VARIABLE param is out of range
> > >
> > > Is that working as intended? I don't understand the error message.
> >
> > fixed in 0002 patch (variables cannot be used as EXECUTE argument) and
> 0014 (enable usage variables as an argument of EXECUTE)
>
> Thanks.
>
> > > > --- a/src/backend/catalog/namespace.c
> > > > +++ b/src/backend/catalog/namespace.c
> > > > [...]
> > > > +/*
> > > > + * IdentifyVariable - try to find variable identified by list of
> names.
> > > > [...]
> > >
> > > Perhaps part of the reason why this function is so complicated is
> that
> > > you support things like this:
> > >
> > > CREATE SCHEMA sch;
> > > CREATE TYPE cp AS (a integer, b integer);
> > > CREATE VARIABLE sch.v AS cp;
> > > LET sch.v = (1, 2);
> > > SELECT sch.v.b;
> > > b
> > > ═══
> > > 2
> > > (1 row)
> > >
> > > test=# SELECT test.sch.v.b;
> > > b
> > > ═══
> > > 2
> > > (1 row)
> > >
> > > We don't support that for tables:
> > >
> > > CREATE TABLE tab (c cp);
> > > INSERT INTO tab VALUES (ROW(42, 43));
> > > SELECT tab.c.b FROM tab;
> > > ERROR: cross-database references are not implemented: tab.c.b
> > >
> > > You have to use extra parentheses:
> > >
> > > SELECT (tab.c).b FROM tab;
> > > b
> > > ════
> > > 43
> > > (1 row)
> > >
> > > I'd say that this should be the same for session variables.
> > > What do you think?
> >
> > I prefer the current state, but I don't have a very strong opinion about
> it.
> > It can save 115 lines of almost trivial code, but I think the user
> experience
> > can be much worse. Using composite types in tables is not too common a
> > pattern (and when I read some recommendations for Oracle, it is an
> antipattern),
> > but usage of composite variables is common (it can hold a row). Moreover,
> > we talked long about possible identifier's collisions, and the pattern
> > schema.variable is very good protection against possible collisions.
> > Probably the pattern catalog.schema.variable.field is not too interesting
> > but the support has 50 lines.
> >
> > More, the plpgsql supports pattern label.variable.field, so can be
> little bit
> > unfriendly if session variables doesn't support "similar" pattern
>
> I see your point, and I'm fine with leaving it as it is.
>
> >
> >
> > > - src/backend/commands/session_variable.c
> > >
> > > There is one comment that confuses me and that I did not edit:
> > >
> > > > +Datum
> > > > +GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
> > > > +{
> > > > + SVariable svar;
> > > > +
> > > > + svar = get_session_variable(varid);
> > > > +
> > > > + /*
> > > > + * Although svar is freshly validated in this point, the
> svar->is_valid can
> > > > + * be false, due possible accepting invalidation message
> inside domain
> > > > + * check. Now, the validation is done after lock, that can
> also accept
> > > > + * invalidation message, so validation should be trustful.
> > > > + *
> > > > + * For now, we don't need to repeat validation. Only svar
> should be valid
> > > > + * pointer.
> > > > + */
> >
> > This comment is related to assertions. Before I had there
> `Assert(svar->is_valid)`,
> > because I expected it. But it was not always true. And although it is
> true,
> > we don't need to validate a variable, because at this moment, the
> variable
> > should be locked, and then we can return content safely.
>
> I guess my main problem is the word "trustful". I don't recognize that
> word.
> Perhaps you can reword the comment along the lines of your above
> explanation.
>

I'll try to change it

>
> >
> > > - src/backend/executor/execMain.c
> > >
> > > > @@ -196,6 +198,51 @@ standard_ExecutorStart(QueryDesc *queryDesc,
> int eflags)
> > > > Assert(queryDesc->sourceText != NULL);
> > > > estate->es_sourceText = queryDesc->sourceText;
> > > >
> > > > + /*
> > > > + * The executor doesn't work with session variables directly.
> Values of
> > > > + * related session variables are copied to dedicated array,
> and this array
> > > > + * is passed to executor.
> > > > + */
> > >
> > > Why? Is that a performance measure? The comment should explain
> that.
> >
> > Session variables are volatile internally - some function that uses LET
> statements
> > can be called more times inside a query. This behavior is not consistent
> with
> > plpgsql's variables or external parameters. And if we want to support
> parallel
> > queries, then volatile session variables can be pretty messy (and
> unusable).
> > If we want the same behaviour for queries with or without parallel
> support,
> > then the session variables should be "stable" (like stable functions).
> > Simple implementation is using "snapshot" of values of used session
> variables
> > when query is started. This "snapshot" is immutable, so we don't need to
> make
> > a copy more times.
> >
> > I changed this comment
>
> Thanks.
>
> > > - parallel safety
> > >
> > > > --- a/src/backend/optimizer/util/clauses.c
> > > > +++ b/src/backend/optimizer/util/clauses.c
> > > > @@ -935,6 +936,13 @@ max_parallel_hazard_walker(Node *node,
> max_parallel_hazard_context *context)
> > > > if (param->paramkind == PARAM_EXTERN)
> > > > return false;
> > > >
> > > > + /* We doesn't support passing session variables to workers
> */
> > > > + if (param->paramkind == PARAM_VARIABLE)
> > > > + {
> > > > + if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED,
> context))
> > > > + return true;
> > > > + }
> > >
> > > Even if a later patch alleviates that restriction, this patch should
> document that
> > > session variables imply "parallel restricted". I have added that to
> doc/src/sgml/parallel.sgml.
> > >
> >
> > merged (and removed in 0015)
>
> Thanks.
>
>
> I hope I can do some more review at some point in the future...
>
> I sincerely hope that this patch set gets merged at some point.
> The big obstacle is that it is so large. That's probably because it is
> pretty
> feature-complete (but, as we have found, not totally free of bugs).
>

Any feature that builds its own system catalog cannot be short. The first
two patches have 300KB, like all others and just basic support for reading
and writing. All other features have 300KB. On second hand almost all code
is simple, and there are no changes in critical parts of Postgres. The size
and complexity of JSONPath is level higher. I can throw 200KB from another
300KB patch set which can be better for review, but it can be harder to
maintain this patch set. I'll try it, and I'll send a reduced version.

> Judging from the amount of time I put into my review so far, I guess that
> this
> patch set would keep a committer busy for several weeks. Perhaps the only
> way to
> get this done would be to make you a committer...
>

:-)

Unfortunately, I am very bad at languages, I had a lot of problems in basic
school just with Czech lang, Russian and English was more terrible) - so I
very appreciate your work on this patch.

Thank you very much

Pavel

> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-27 14:52:00
Message-ID: 6114b2c070485a96156d6fb116bdb0ec0b11d8ca.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

time""On Tue, 2024-08-27 at 08:52 +0200, Pavel Stehule wrote:
> I can throw 200KB from another 300KB patch set which can be better for review, but it
> can be harder to maintain this patch set. I'll try it, and I'll send a reduced version.

That was not a criticism, and I think the way you split up the patch set right now
is as good as it probably gets. Ideally, one could say something like "we need at least
patch 1 to 4, 5 and 6 are optional, but desirable, all others can easily be deferred
to a later time".

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-29 17:33:46
Message-ID: CAFj8pRB-ey7mCnKqMhBBrkv2mXOvTLfAEBy2LZxQsWPCBvguGQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

út 27. 8. 2024 v 8:52 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> út 27. 8. 2024 v 8:15 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
> napsal:
>
>> On Thu, 2024-08-15 at 07:55 +0200, Pavel Stehule wrote:
>> > út 30. 7. 2024 v 21:46 odesílatel Laurenz Albe <
>> laurenz(dot)albe(at)cybertec(dot)at> napsal:
>> > > - A general reminder: single line comments should start with a lower
>> case
>> > > letter and have to period in the end:
>> >
>> > Should it be "have not to period in the end" ?
>>
>> I made a typo. I mean "have *no* period in the end".
>>
>> > I fixed almost all without parts related to psql and executor - there
>> almost all
>> > current comments break the mentioned rule. So I use the style used in
>> these files.
>> > I can fix it (if you like it) - or it can be fixed generally in a
>> separated patch set.
>>
>> Thanks. I also noticed that a lot of existing comments break that rule,
>> so I think that it is fine if you stick with the way that the surrounding
>> code does it.
>>
>> > > - Variable as parameter:
>> > >
>> > > CREATE VARIABLE var AS date;
>> > > LET var = current_date;
>> > > PREPARE stmt(date) AS SELECT $1;
>> > > EXECUTE stmt(var);
>> > > ERROR: paramid of PARAM_VARIABLE param is out of range
>> > >
>> > > Is that working as intended? I don't understand the error message.
>> >
>> > fixed in 0002 patch (variables cannot be used as EXECUTE argument) and
>> 0014 (enable usage variables as an argument of EXECUTE)
>>
>> Thanks.
>>
>> > > > --- a/src/backend/catalog/namespace.c
>> > > > +++ b/src/backend/catalog/namespace.c
>> > > > [...]
>> > > > +/*
>> > > > + * IdentifyVariable - try to find variable identified by list of
>> names.
>> > > > [...]
>> > >
>> > > Perhaps part of the reason why this function is so complicated is
>> that
>> > > you support things like this:
>> > >
>> > > CREATE SCHEMA sch;
>> > > CREATE TYPE cp AS (a integer, b integer);
>> > > CREATE VARIABLE sch.v AS cp;
>> > > LET sch.v = (1, 2);
>> > > SELECT sch.v.b;
>> > > b
>> > > ═══
>> > > 2
>> > > (1 row)
>> > >
>> > > test=# SELECT test.sch.v.b;
>> > > b
>> > > ═══
>> > > 2
>> > > (1 row)
>> > >
>> > > We don't support that for tables:
>> > >
>> > > CREATE TABLE tab (c cp);
>> > > INSERT INTO tab VALUES (ROW(42, 43));
>> > > SELECT tab.c.b FROM tab;
>> > > ERROR: cross-database references are not implemented: tab.c.b
>> > >
>> > > You have to use extra parentheses:
>> > >
>> > > SELECT (tab.c).b FROM tab;
>> > > b
>> > > ════
>> > > 43
>> > > (1 row)
>> > >
>> > > I'd say that this should be the same for session variables.
>> > > What do you think?
>> >
>> > I prefer the current state, but I don't have a very strong opinion
>> about it.
>> > It can save 115 lines of almost trivial code, but I think the user
>> experience
>> > can be much worse. Using composite types in tables is not too common a
>> > pattern (and when I read some recommendations for Oracle, it is an
>> antipattern),
>> > but usage of composite variables is common (it can hold a row).
>> Moreover,
>> > we talked long about possible identifier's collisions, and the pattern
>> > schema.variable is very good protection against possible collisions.
>> > Probably the pattern catalog.schema.variable.field is not too
>> interesting
>> > but the support has 50 lines.
>> >
>> > More, the plpgsql supports pattern label.variable.field, so can be
>> little bit
>> > unfriendly if session variables doesn't support "similar" pattern
>>
>> I see your point, and I'm fine with leaving it as it is.
>>
>> >
>> >
>> > > - src/backend/commands/session_variable.c
>> > >
>> > > There is one comment that confuses me and that I did not edit:
>> > >
>> > > > +Datum
>> > > > +GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
>> > > > +{
>> > > > + SVariable svar;
>> > > > +
>> > > > + svar = get_session_variable(varid);
>> > > > +
>> > > > + /*
>> > > > + * Although svar is freshly validated in this point, the
>> svar->is_valid can
>> > > > + * be false, due possible accepting invalidation message
>> inside domain
>> > > > + * check. Now, the validation is done after lock, that can
>> also accept
>> > > > + * invalidation message, so validation should be trustful.
>> > > > + *
>> > > > + * For now, we don't need to repeat validation. Only svar
>> should be valid
>> > > > + * pointer.
>> > > > + */
>> >
>> > This comment is related to assertions. Before I had there
>> `Assert(svar->is_valid)`,
>> > because I expected it. But it was not always true. And although it is
>> true,
>> > we don't need to validate a variable, because at this moment, the
>> variable
>> > should be locked, and then we can return content safely.
>>
>> I guess my main problem is the word "trustful". I don't recognize that
>> word.
>> Perhaps you can reword the comment along the lines of your above
>> explanation.
>>
>
> I'll try to change it
>

is this better

<-->/*
<--> * Although svar is freshly validated in this point, the svar->is_valid
can
<--> * be false, due possible accepting invalidation message inside domain
<--> * check. But now, the variable, and all dependencies are locked, so we
<--> * don't need to repeat validation.
<--> */

>
>
>>
>> >
>> > > - src/backend/executor/execMain.c
>> > >
>> > > > @@ -196,6 +198,51 @@ standard_ExecutorStart(QueryDesc *queryDesc,
>> int eflags)
>> > > > Assert(queryDesc->sourceText != NULL);
>> > > > estate->es_sourceText = queryDesc->sourceText;
>> > > >
>> > > > + /*
>> > > > + * The executor doesn't work with session variables directly.
>> Values of
>> > > > + * related session variables are copied to dedicated array,
>> and this array
>> > > > + * is passed to executor.
>> > > > + */
>> > >
>> > > Why? Is that a performance measure? The comment should explain
>> that.
>> >
>> > Session variables are volatile internally - some function that uses LET
>> statements
>> > can be called more times inside a query. This behavior is not
>> consistent with
>> > plpgsql's variables or external parameters. And if we want to support
>> parallel
>> > queries, then volatile session variables can be pretty messy (and
>> unusable).
>> > If we want the same behaviour for queries with or without parallel
>> support,
>> > then the session variables should be "stable" (like stable functions).
>> > Simple implementation is using "snapshot" of values of used session
>> variables
>> > when query is started. This "snapshot" is immutable, so we don't need
>> to make
>> > a copy more times.
>> >
>> > I changed this comment
>>
>> Thanks.
>>
>> > > - parallel safety
>> > >
>> > > > --- a/src/backend/optimizer/util/clauses.c
>> > > > +++ b/src/backend/optimizer/util/clauses.c
>> > > > @@ -935,6 +936,13 @@ max_parallel_hazard_walker(Node *node,
>> max_parallel_hazard_context *context)
>> > > > if (param->paramkind == PARAM_EXTERN)
>> > > > return false;
>> > > >
>> > > > + /* We doesn't support passing session variables to
>> workers */
>> > > > + if (param->paramkind == PARAM_VARIABLE)
>> > > > + {
>> > > > + if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED,
>> context))
>> > > > + return true;
>> > > > + }
>> > >
>> > > Even if a later patch alleviates that restriction, this patch
>> should document that
>> > > session variables imply "parallel restricted". I have added that
>> to doc/src/sgml/parallel.sgml.
>> > >
>> >
>> > merged (and removed in 0015)
>>
>> Thanks.
>>
>>
>> I hope I can do some more review at some point in the future...
>>
>> I sincerely hope that this patch set gets merged at some point.
>> The big obstacle is that it is so large. That's probably because it is
>> pretty
>> feature-complete (but, as we have found, not totally free of bugs).
>>
>
> Any feature that builds its own system catalog cannot be short. The first
> two patches have 300KB, like all others and just basic support for reading
> and writing. All other features have 300KB. On second hand almost all code
> is simple, and there are no changes in critical parts of Postgres. The size
> and complexity of JSONPath is level higher. I can throw 200KB from another
> 300KB patch set which can be better for review, but it can be harder to
> maintain this patch set. I'll try it, and I'll send a reduced version.
>
>
>> Judging from the amount of time I put into my review so far, I guess that
>> this
>> patch set would keep a committer busy for several weeks. Perhaps the
>> only way to
>> get this done would be to make you a committer...
>>
>
> :-)
>
> Unfortunately, I am very bad at languages, I had a lot of problems in
> basic school just with Czech lang, Russian and English was more terrible) -
> so I very appreciate your work on this patch.
>
> Thank you very much
>
> Pavel
>

Regards

Pavel

>
>
>> Yours,
>> Laurenz Albe
>>
>

Attachment Content-Type Size
v20240829-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240829-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240829-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240829-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240829-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240829-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20240829-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20240829-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20240829-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240829-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240829-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240829-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240829-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240829-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240829-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240829-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240829-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240829-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240829-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.0 KB
v20240829-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-08-29 18:17:06
Message-ID: CAFj8pRAy7KxMOJKcuqHQZJH2DOh2r7KmcBfh9FgAmw5gC95-SA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

út 27. 8. 2024 v 16:52 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> time""On Tue, 2024-08-27 at 08:52 +0200, Pavel Stehule wrote:
> > I can throw 200KB from another 300KB patch set which can be better for
> review, but it
> > can be harder to maintain this patch set. I'll try it, and I'll send a
> reduced version.
>
> That was not a criticism, and I think the way you split up the patch set
> right now
> is as good as it probably gets. Ideally, one could say something like "we
> need at least
> patch 1 to 4, 5 and 6 are optional, but desirable, all others can easily
> be deferred
> to a later time".
>

It was mentioned here more times (I thought).

1..4 are fundamental
5..6 optional (6 are just tests)

others can be deferred (5-6 can be deferred too). Without support of
temporary session variables, it is not too probable to repeatedly CREATE,
DROP the same variable in one session, so memory usage can be similar to
today's workarounds, but against workarounds, session variables use types
and access rights. Note - plpgsql doesn't try to delete compiled code from
cache immediately too - so the behaviour implemented in 1..4 is "similar"
to plpgsql func cache

14 .. allow you to use session variables as arguments of CALL or EXECUTE
statement, and variables can be used in plpgsql simple expr.
15 .. variables don't block parallelism
16 .. the result of plpgsql simple expr can be assigned to session variables
17 .. expr with session variable can be inlined in SQL

14-17 are performance related

7 - was requested by some people - some functionality can be possibly
replaced by plpgsql_check.
It has only 40 rows - it just raise warning or error when some conditions
are true

Regards

Pavel

>
> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-09-02 14:00:51
Message-ID: 3850a85012d040827b10193189edbe2c23a64f8f.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, 2024-08-29 at 19:33 +0200, Pavel Stehule wrote:
> > > > >   > +   /*
> > > > >   > +    * Although svar is freshly validated in this point, the svar->is_valid can
> > > > >   > +    * be false, due possible accepting invalidation message inside domain
> > > > >   > +    * check. Now, the validation is done after lock, that can also accept
> > > > >   > +    * invalidation message, so validation should be trustful.
> > > > >   > +    *
> > > > >   > +    * For now, we don't need to repeat validation. Only svar should be valid
> > > > >   > +    * pointer.
> > > > >   > +    */
> > > >
> > > > This comment is related to assertions. Before I had there `Assert(svar->is_valid)`,
> > > > because I expected it. But it was not always true. And although it is true,
> > > > we don't need to validate a variable, because at this moment, the variable
> > > > should be locked, and then we can return content safely.
> > >
> > > I guess my main problem is the word "trustful".  I don't recognize that word.
> > > Perhaps you can reword the comment along the lines of your above explanation.
> >
> >
> > I'll try to change it
>
> is this better
>
> <-->/*
> <--> * Although svar is freshly validated in this point, the svar->is_valid can
> <--> * be false, due possible accepting invalidation message inside domain
> <--> * check. But now, the variable, and all dependencies are locked, so we
> <--> * don't need to repeat validation.
> <--> */

Much better.

Here is an improved version:

Although "svar" is freshly validated in this point, svar->is_valid can
be false, if an invalidation message ws processed during the domain check.
But the variable and all its dependencies are locked now, so we don't need
to repeat the validation.

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-09-03 11:41:31
Message-ID: CAFj8pRBvUwfs96MX2_=unHQ107diUOK4S_WD=E4XBXkpXG3VjA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 2. 9. 2024 v 16:00 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Thu, 2024-08-29 at 19:33 +0200, Pavel Stehule wrote:
> > > > > > > + /*
> > > > > > > + * Although svar is freshly validated in this point, the
> svar->is_valid can
> > > > > > > + * be false, due possible accepting invalidation message
> inside domain
> > > > > > > + * check. Now, the validation is done after lock, that
> can also accept
> > > > > > > + * invalidation message, so validation should be
> trustful.
> > > > > > > + *
> > > > > > > + * For now, we don't need to repeat validation. Only
> svar should be valid
> > > > > > > + * pointer.
> > > > > > > + */
> > > > >
> > > > > This comment is related to assertions. Before I had there
> `Assert(svar->is_valid)`,
> > > > > because I expected it. But it was not always true. And although it
> is true,
> > > > > we don't need to validate a variable, because at this moment, the
> variable
> > > > > should be locked, and then we can return content safely.
> > > >
> > > > I guess my main problem is the word "trustful". I don't recognize
> that word.
> > > > Perhaps you can reword the comment along the lines of your above
> explanation.
> > >
> > >
> > > I'll try to change it
> >
> > is this better
> >
> > <-->/*
> > <--> * Although svar is freshly validated in this point, the
> svar->is_valid can
> > <--> * be false, due possible accepting invalidation message inside
> domain
> > <--> * check. But now, the variable, and all dependencies are locked, so
> we
> > <--> * don't need to repeat validation.
> > <--> */
>
> Much better.
>
> Here is an improved version:
>
> Although "svar" is freshly validated in this point, svar->is_valid can
> be false, if an invalidation message ws processed during the domain
> check.
> But the variable and all its dependencies are locked now, so we don't
> need
> to repeat the validation.
>
>

merged

thank you

Regards

Pavel

> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20240903-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240903-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240903-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240903-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240903-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240903-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20240903-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20240903-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20240903-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240903-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240903-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240903-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240903-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240903-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240903-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240903-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240903-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240903-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240903-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.0 KB
v20240903-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-09-12 05:15:34
Message-ID: CAFj8pRCDWjgo=yLEK-jRDe5VwuNSQSmMqPPmysQf9nHA8gifnw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase

regards

Pavel

Attachment Content-Type Size
v20240912-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240912-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240912-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240912-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240912-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240912-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20240912-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20240912-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20240912-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240912-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240912-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240912-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240912-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240912-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240912-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240912-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240912-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240912-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240912-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.0 KB
v20240912-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-09-18 06:21:44
Message-ID: CAFj8pRA2jbXRTGgM1co8gLCNttgaH8miRUSSauMJKWgousDsDg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase

regards

Pavel

Attachment Content-Type Size
v20240918-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240918-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240918-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240918-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240918-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20240918-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20240918-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20240918-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240918-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240918-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20240918-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240918-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240918-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240918-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240918-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240918-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240918-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240918-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240918-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.0 KB
v20240918-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-09-22 08:43:22
Message-ID: CAFj8pRA6nJRg8oq5k_Cdk5oH5_FjtViG8XLmHKrkqOuiMT_CKQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix assertion failure after
https://github.com/postgres/postgres/commit/24f5205948093a96edf8213294b3d585ac3fe1fb

the analyze routine for LetStmt was fixed

<-->/*
<--> * The query is executed as utility command by nested executor call.
<--> * Assigned queryId is required in this case.
<--> */
<-->if (IsQueryIdEnabled())

Regards

Pavel

Attachment Content-Type Size
v20240922-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20240922-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20240922-0019-transactional-variables.patch text/x-patch 39.2 KB
v20240922-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20240922-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20240922-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20240922-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20240922-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20240922-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20240922-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20240922-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20240922-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20240922-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20240922-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20240922-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20240922-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20240922-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20240922-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20240922-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.2 KB
v20240922-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-09 04:24:56
Message-ID: CAFj8pRBWMLP3Vyr8z+19eaiJKQoVtBfmDhNJFKXDX6uFzd4vBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase

Regards

Pavel

Attachment Content-Type Size
v20241009-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241009-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241009-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241009-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241009-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241009-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241009-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241009-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241009-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241009-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241009-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20241009-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241009-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20241009-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241009-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241009-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241009-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20241009-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.1 KB
v20241009-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.6 KB
v20241009-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.2 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-23 04:11:08
Message-ID: c7eee33c5051f973ab256ee7202c15771c33f47d.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

I have gone over patch 3 from the set and worked on the comments.

Apart from that, I have modified your patch as follows:

> +/*
> + * pg_session_variables - designed for testing
> + *
> + * This is a function designed for testing and debugging. It returns the
> + * content of sessionvars as-is, and can therefore display entries about
> + * session variables that were dropped but for which this backend didn't
> + * process the shared invalidations yet.
> + */
> +Datum
> +pg_session_variables(PG_FUNCTION_ARGS)
> +{
> +#define NUM_PG_SESSION_VARIABLES_ATTS 8
> +
> + elog(DEBUG1, "pg_session_variables start");

I don't think that message is necessary, particularly with DEBUG1.
I have removed this message and the "end" message as well.

> + while ((svar = (SVariable) hash_seq_search(&status)) != NULL)
> + {
> + Datum values[NUM_PG_SESSION_VARIABLES_ATTS];
> + bool nulls[NUM_PG_SESSION_VARIABLES_ATTS];
> + HeapTuple tp;
> + bool var_is_valid = false;
> +
> + memset(values, 0, sizeof(values));
> + memset(nulls, 0, sizeof(nulls));

Instead of explicitly zeroing out the arrays, I have used an empty initializer
in the definition, like

bool nulls[NUM_PG_SESSION_VARIABLES_ATTS] = {};

That should have the same effect.
If you don't like that, I have no real problem with your original code.

> + values[0] = ObjectIdGetDatum(svar->varid);
> + values[3] = ObjectIdGetDatum(svar->typid);

You are using the type ID without checking if it exists in the catalog.
I think that is a bug.

There is a dependency between the variable and the type, but if a concurrent
session drops both the variable and the data type, the non-existing type ID
would still show up in the function output.
Even worse, the OID could have been reused for a different type since.

I am attaching just patch number 3 and leave you to adapt the patch set,
but I don't think any of the other patches should be affected.

Yours,
Laurenz Albe

Attachment Content-Type Size
v20241023-0003-function-pg_session_variables-for-cleanin.patch text/x-patch 4.2 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-24 08:29:02
Message-ID: afb4e296d7ce57986f23bcfdee39b259b8f85f56.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

... and here is a review for patch 4

I didn't change any code, just added the odd article to a comment.

While running the regression tests with "make installcheck", I noticed two problems:

--- /home/laurenz/postgresql/src/test/regress/expected/session_variables.out 2024-10-24 11:14:06.717663613 +0300
+++ /home/laurenz/postgresql/src/test/regress/results/session_variables.out 2024-10-24 11:15:37.999286228 +0300
@@ -30,6 +30,7 @@
GRANT ALL ON SCHEMA svartest TO regress_variable_owner;
CREATE VARIABLE svartest.var1 AS int;
CREATE ROLE regress_variable_reader;
+ERROR: role "regress_variable_reader" already exists

I suggest that patch 0001 should drop role "regress_variable_reader" again.

@@ -107,7 +108,7 @@
CONTEXT: SQL function "sqlfx" statement 1
SELECT plpgsqlfx(20);
ERROR: permission denied for session variable var1
-CONTEXT: SQL expression "$1 + var1"
+CONTEXT: PL/pgSQL expression "$1 + var1"

That looks like bit rot from your commit 4af123ad45.

Yours,
Laurenz Albe

Attachment Content-Type Size
v20241024-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-25 05:21:34
Message-ID: CAFj8pRAxSiA68tS=ky64A9fhKGstRVpgQfPotNmMF0-4GuisRQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 23. 10. 2024 v 6:11 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> I have gone over patch 3 from the set and worked on the comments.
>
> Apart from that, I have modified your patch as follows:
>
> > +/*
> > + * pg_session_variables - designed for testing
> > + *
> > + * This is a function designed for testing and debugging. It returns
> the
> > + * content of sessionvars as-is, and can therefore display entries about
> > + * session variables that were dropped but for which this backend didn't
> > + * process the shared invalidations yet.
> > + */
> > +Datum
> > +pg_session_variables(PG_FUNCTION_ARGS)
> > +{
> > +#define NUM_PG_SESSION_VARIABLES_ATTS 8
> > +
> > + elog(DEBUG1, "pg_session_variables start");
>
> I don't think that message is necessary, particularly with DEBUG1.
> I have removed this message and the "end" message as well.
>

removed

>
> > + while ((svar = (SVariable) hash_seq_search(&status)) !=
> NULL)
> > + {
> > + Datum
> values[NUM_PG_SESSION_VARIABLES_ATTS];
> > + bool
> nulls[NUM_PG_SESSION_VARIABLES_ATTS];
> > + HeapTuple tp;
> > + bool var_is_valid = false;
> > +
> > + memset(values, 0, sizeof(values));
> > + memset(nulls, 0, sizeof(nulls));
>
> Instead of explicitly zeroing out the arrays, I have used an empty
> initializer
> in the definition, like
>
> bool nulls[NUM_PG_SESSION_VARIABLES_ATTS] = {};
>
> That should have the same effect.
> If you don't like that, I have no real problem with your original code.
>

I prefer the original way - minimally it is a common pattern. I didn't find
any usage of `= {} ` in code

> > + values[0] = ObjectIdGetDatum(svar->varid);
> > + values[3] = ObjectIdGetDatum(svar->typid);
>
> You are using the type ID without checking if it exists in the catalog.
> I think that is a bug.
>

The original idea was using typid as hint identification of deleted
variables. The possibility that this id will not be consistent for the
current catalogue was expected. And it
is a reason why the result type is just Oid and not regtype. Without it,
pg_session_variables shows just empty rows (except oid) for dropped not yet
purged variables.

>
> There is a dependency between the variable and the type, but if a
> concurrent
> session drops both the variable and the data type, the non-existing type ID
> would still show up in the function output.
> Even worse, the OID could have been reused for a different type since.
>

I agree so usage `select typid::regtype, ... from pg_session_variables(.. `

can be dangerous, but it is the reason why we have there typname column.

Showing typid has some information value, but I don't think it is
absolutely necessary. I see some possible changes:

1. no change
2. remove typid column
3. show typid only when variable is valid, and using regtype as output
type, remove typname

What do you prefer?

I'll send the attachment with merging changes for patch 4

Regards

Pavel

>
> I am attaching just patch number 3 and leave you to adapt the patch set,
> but I don't think any of the other patches should be affected.
>

The comments from your patch are merged

>
> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-25 07:41:40
Message-ID: 986faf36db4ebdcbe8397e2c15bb691dbe631ec8.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, 2024-10-25 at 07:21 +0200, Pavel Stehule wrote:
> > > +     elog(DEBUG1, "pg_session_variables start");
> >
> > I don't think that message is necessary, particularly with DEBUG1.
> > I have removed this message and the "end" message as well.
>
> removed

Thanks.

> > > +                     memset(values, 0, sizeof(values));
> > > +                     memset(nulls, 0, sizeof(nulls));
> >
> > Instead of explicitly zeroing out the arrays, I have used an empty initializer
> > in the definition, like
> >
> >   bool          nulls[NUM_PG_SESSION_VARIABLES_ATTS] = {};
> >
> > That should have the same effect.
> > If you don't like that, I have no real problem with your original code.
>
> I prefer the original way - minimally it is a common pattern. I didn't find any usage of `= {} ` in code

That's alright by me.

> > > +                     values[0] = ObjectIdGetDatum(svar->varid);
> > > +                     values[3] = ObjectIdGetDatum(svar->typid);
> >
> > You are using the type ID without checking if it exists in the catalog.
> > I think that is a bug.
>
> The original idea was using typid as hint identification of deleted variables. The possibility
> that this id will not be consistent for the current catalogue was expected. And it
> is a reason why the result type is just Oid and not regtype. Without it, pg_session_variables
> shows just empty rows (except oid) for dropped not yet purged variables.

I see your point. It is for testing and debugging only.

>
> owing typid has some information value, but I don't think it is absolutely necessary. I see some possible changes:
>
> 1. no change
> 2. remove typid column
> 3. show typid only when variable is valid, and using regtype as output type, remove typname
>
> What do you prefer?

I'd say leave it as it is. I agree that it is not dangerous, and if it is intentional that
non-existing type IDs might be displayed, I have no problem with it.

Yours,
Laurenz Albe


From: James Pang <jamespang886(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2024-10-25 07:58:39
Message-ID: CAHgTRffZBJkNRm3gyv_JcreuztuSV6WZxQzEw8-P7V3Pj10W+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Yes, a lot new coming sessions running some "select" and sql
parsing/planning there, including some partition tables in the query. but
there were other sessions DML on these tables at the same time too

Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> 於 2024年7月19日週五 下午7:41寫道:

> On Sat, 2021-04-10 at 08:58 +0200, Pavel Stehule wrote:
> > I am sending a strongly updated patch for schema variables.
> >
> > I rewrote an execution of a LET statement. In the previous
> implementation I hacked
> > STMT_SELECT. Now, I introduced a new statement STMT_LET, and I
> implemented a new
> > executor node SetVariable. Now I think this implementation is much
> cleaner.
> > Implementation with own executor node reduces necessary work on PL side
> - and allows
> > the LET statement to be prepared - what is important from a security
> view.
> >
> > I'll try to write a second implementation based on a cleaner
> implementation like
> > utility command too. I expect so this version will be more simple, but
> utility
> > commands cannot be prepared, and probably, there should be special
> support for
> > any PL. I hope a cleaner implementation can help to move this patch.
> >
> > We can choose one variant in the next step and this variant can be
> finalized.
> >
> > Notes, comments?
>
> Thank you!
>
> I tried to give the patch a spin, but it doesn't apply any more,
> and there are too many conflicts for me to fix manually.
>
> So I had a look at the documentation:
>
> > --- a/doc/src/sgml/advanced.sgml
> > +++ b/doc/src/sgml/advanced.sgml
>
> > + <para>
> > + The value of a schema variable is local to the current session.
> Retrieving
> > + a variable's value returns either a NULL or a default value, unless
> its value
> > + is set to something else in the current session with a LET command.
> The content
> > + of a variable is not transactional. This is the same as in regular
> variables
> > + in PL languages.
> > + </para>
> > +
> > + <para>
> > + Schema variables are retrieved by the <command>SELECT</command> SQL
> command.
> > + Their value is set with the <command>LET</command> SQL command.
> > + While schema variables share properties with tables, their value
> cannot be updated
> > + with an <command>UPDATE</command> command.
>
> "PL languages" -> "procedural languages". Perhaps a link to the
> "procedural Languages"
> chapter would be a good idea.
> I don't think we should say "regular" variables: are there irregular
> variables?
>
> My feeling is that "SQL statement <command>XY</command>" is better than
> "<command>XY</command> SQL command".
>
> I think the last sentence should go. The properties they share with
> tables are
> that they live in a schema and can be used with SELECT.
> Also, it is not necessary to mention that they cannot be UPDATEd. They
> cannot
> be TRUNCATEd or CALLed either, so why mention UPDATE specifically?
>
> > --- a/doc/src/sgml/catalogs.sgml
> > +++ b/doc/src/sgml/catalogs.sgml
>
> > + <row>
> > + <entry><structfield>varisnotnull</structfield></entry>
> > + <entry><type>boolean</type></entry>
> > + <entry></entry>
> > + <entry>
> > + True if the schema variable doesn't allow null value. The
> default value is false.
> > + </entry>
> > + </row>
>
> I think the attribute should be called "varnotnull", similar to
> "attnotnull".
> This attribute determines whether the variable is NOT NULL or not, not
> about
> its current setting.
>
> There is a plural missing: "doesn't allow null valueS".
>
> > + <row>
> > + <entry><structfield>vareoxaction</structfield></entry>
> > + <entry><type>char</type></entry>
> > + <entry></entry>
> > + <entry>
> > + <literal>n</literal> = no action, <literal>d</literal> = drop
> the variable,
> > + <literal>r</literal> = reset the variable to its default value.
> > + </entry>
> > + </row>
>
> Perhaps the name "varxactendaction" would be better.
>
> A descriptive sentence is missing.
>
> > --- /dev/null
> > +++ b/doc/src/sgml/ref/create_variable.sgml
>
> > + <para>
> > + The value of a schema variable is local to the current session.
> Retrieving
> > + a variable's value returns either a NULL or a default value, unless
> its value
> > + is set to something else in the current session with a LET command.
> The content
> > + of a variable is not transactional. This is the same as in regular
> variables in PL languages.
> > + </para>
>
> "regular variables in PL languages" -> "variables in procedural languages"
>
> > + <para>
> > + Schema variables are retrieved by the <command>SELECT</command> SQL
> command.
> > + Their value is set with the <command>LET</command> SQL command.
> > + While schema variables share properties with tables, their value
> cannot be updated
> > + with an <command>UPDATE</command> command.
> > + </para>
>
> That's just a literal copy from the tutorial section. I have the same
> comments
> as there.
>
> > + <varlistentry>
> > + <term><literal>NOT NULL</literal></term>
> > + <listitem>
> > + <para>
> > + The <literal>NOT NULL</literal> clause forbids to set the
> variable to
> > + a null value. A variable created as NOT NULL and without an
> explicitly
> > + declared default value cannot be read until it is initialized by
> a LET
> > + command. This obliges the user to explicitly initialize the
> variable
> > + content before reading it.
> > + </para>
> > + </listitem>
> > + </varlistentry>
>
> What is the reason for that behavior? I'd have expected that a NOT NULL
> variable needs a default value.
>
> > --- /dev/null
> > +++ b/doc/src/sgml/ref/let.sgml
>
> > + <varlistentry>
> > + <term><literal>sql_expression</literal></term>
> > + <listitem>
> > + <para>
> > + An SQL expression. The result is cast into the schema variable's
> type.
> > + </para>
> > + </listitem>
> > + </varlistentry>
>
> Always, even if there is no assignment or implicit cast?
>
> I see no such wording fir INSERT or UPDATE, so if only assignment casts
> are used,
> the second sentence should be removed.
>
> > --- a/doc/src/sgml/ref/pg_restore.sgml
> > +++ b/doc/src/sgml/ref/pg_restore.sgml
>
> > + <varlistentry>
> > + <term><option>-A <replaceable
> class="parameter">schema_variable</replaceable></option></term>
> > + <term><option>--variable=<replaceable
> class="parameter">schema_variable</replaceable></option></term>
> > + <listitem>
> > + <para>
> > + Restore a named schema variable only. Multiple schema
> variables may be specified with
> > + multiple <option>-A</option> switches.
> > + </para>
> > + </listitem>
> > + </varlistentry>
>
> Do we need that? We have no such option for functions and other
> non-relations.
>
> And if we really want such an option for "pg_restore", why not for
> "pg_dump"?
>
> Yours,
> Laurenz Albe
>
>
>


From: James Pang <jamespang886(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: proposal: schema variables
Date: 2024-10-25 07:59:26
Message-ID: CAHgTRfeag7Dv3SzUH0vrUGkkyF4cEzja9T+POE0BriCDQjDL4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

sorry, I sent to wrong email. please ignore.

James Pang <jamespang886(at)gmail(dot)com> 於 2024年10月25日週五 下午3:58寫道:

> Yes, a lot new coming sessions running some "select" and sql
> parsing/planning there, including some partition tables in the query. but
> there were other sessions DML on these tables at the same time too
>
> Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> 於 2024年7月19日週五 下午7:41寫道:
>
>> On Sat, 2021-04-10 at 08:58 +0200, Pavel Stehule wrote:
>> > I am sending a strongly updated patch for schema variables.
>> >
>> > I rewrote an execution of a LET statement. In the previous
>> implementation I hacked
>> > STMT_SELECT. Now, I introduced a new statement STMT_LET, and I
>> implemented a new
>> > executor node SetVariable. Now I think this implementation is much
>> cleaner.
>> > Implementation with own executor node reduces necessary work on PL side
>> - and allows
>> > the LET statement to be prepared - what is important from a security
>> view.
>> >
>> > I'll try to write a second implementation based on a cleaner
>> implementation like
>> > utility command too. I expect so this version will be more simple, but
>> utility
>> > commands cannot be prepared, and probably, there should be special
>> support for
>> > any PL. I hope a cleaner implementation can help to move this patch.
>> >
>> > We can choose one variant in the next step and this variant can be
>> finalized.
>> >
>> > Notes, comments?
>>
>> Thank you!
>>
>> I tried to give the patch a spin, but it doesn't apply any more,
>> and there are too many conflicts for me to fix manually.
>>
>> So I had a look at the documentation:
>>
>> > --- a/doc/src/sgml/advanced.sgml
>> > +++ b/doc/src/sgml/advanced.sgml
>>
>> > + <para>
>> > + The value of a schema variable is local to the current session.
>> Retrieving
>> > + a variable's value returns either a NULL or a default value,
>> unless its value
>> > + is set to something else in the current session with a LET
>> command. The content
>> > + of a variable is not transactional. This is the same as in regular
>> variables
>> > + in PL languages.
>> > + </para>
>> > +
>> > + <para>
>> > + Schema variables are retrieved by the <command>SELECT</command>
>> SQL command.
>> > + Their value is set with the <command>LET</command> SQL command.
>> > + While schema variables share properties with tables, their value
>> cannot be updated
>> > + with an <command>UPDATE</command> command.
>>
>> "PL languages" -> "procedural languages". Perhaps a link to the
>> "procedural Languages"
>> chapter would be a good idea.
>> I don't think we should say "regular" variables: are there irregular
>> variables?
>>
>> My feeling is that "SQL statement <command>XY</command>" is better than
>> "<command>XY</command> SQL command".
>>
>> I think the last sentence should go. The properties they share with
>> tables are
>> that they live in a schema and can be used with SELECT.
>> Also, it is not necessary to mention that they cannot be UPDATEd. They
>> cannot
>> be TRUNCATEd or CALLed either, so why mention UPDATE specifically?
>>
>> > --- a/doc/src/sgml/catalogs.sgml
>> > +++ b/doc/src/sgml/catalogs.sgml
>>
>> > + <row>
>> > + <entry><structfield>varisnotnull</structfield></entry>
>> > + <entry><type>boolean</type></entry>
>> > + <entry></entry>
>> > + <entry>
>> > + True if the schema variable doesn't allow null value. The
>> default value is false.
>> > + </entry>
>> > + </row>
>>
>> I think the attribute should be called "varnotnull", similar to
>> "attnotnull".
>> This attribute determines whether the variable is NOT NULL or not, not
>> about
>> its current setting.
>>
>> There is a plural missing: "doesn't allow null valueS".
>>
>> > + <row>
>> > + <entry><structfield>vareoxaction</structfield></entry>
>> > + <entry><type>char</type></entry>
>> > + <entry></entry>
>> > + <entry>
>> > + <literal>n</literal> = no action, <literal>d</literal> = drop
>> the variable,
>> > + <literal>r</literal> = reset the variable to its default value.
>> > + </entry>
>> > + </row>
>>
>> Perhaps the name "varxactendaction" would be better.
>>
>> A descriptive sentence is missing.
>>
>> > --- /dev/null
>> > +++ b/doc/src/sgml/ref/create_variable.sgml
>>
>> > + <para>
>> > + The value of a schema variable is local to the current session.
>> Retrieving
>> > + a variable's value returns either a NULL or a default value, unless
>> its value
>> > + is set to something else in the current session with a LET command.
>> The content
>> > + of a variable is not transactional. This is the same as in regular
>> variables in PL languages.
>> > + </para>
>>
>> "regular variables in PL languages" -> "variables in procedural languages"
>>
>> > + <para>
>> > + Schema variables are retrieved by the <command>SELECT</command> SQL
>> command.
>> > + Their value is set with the <command>LET</command> SQL command.
>> > + While schema variables share properties with tables, their value
>> cannot be updated
>> > + with an <command>UPDATE</command> command.
>> > + </para>
>>
>> That's just a literal copy from the tutorial section. I have the same
>> comments
>> as there.
>>
>> > + <varlistentry>
>> > + <term><literal>NOT NULL</literal></term>
>> > + <listitem>
>> > + <para>
>> > + The <literal>NOT NULL</literal> clause forbids to set the
>> variable to
>> > + a null value. A variable created as NOT NULL and without an
>> explicitly
>> > + declared default value cannot be read until it is initialized by
>> a LET
>> > + command. This obliges the user to explicitly initialize the
>> variable
>> > + content before reading it.
>> > + </para>
>> > + </listitem>
>> > + </varlistentry>
>>
>> What is the reason for that behavior? I'd have expected that a NOT NULL
>> variable needs a default value.
>>
>> > --- /dev/null
>> > +++ b/doc/src/sgml/ref/let.sgml
>>
>> > + <varlistentry>
>> > + <term><literal>sql_expression</literal></term>
>> > + <listitem>
>> > + <para>
>> > + An SQL expression. The result is cast into the schema variable's
>> type.
>> > + </para>
>> > + </listitem>
>> > + </varlistentry>
>>
>> Always, even if there is no assignment or implicit cast?
>>
>> I see no such wording fir INSERT or UPDATE, so if only assignment casts
>> are used,
>> the second sentence should be removed.
>>
>> > --- a/doc/src/sgml/ref/pg_restore.sgml
>> > +++ b/doc/src/sgml/ref/pg_restore.sgml
>>
>> > + <varlistentry>
>> > + <term><option>-A <replaceable
>> class="parameter">schema_variable</replaceable></option></term>
>> > + <term><option>--variable=<replaceable
>> class="parameter">schema_variable</replaceable></option></term>
>> > + <listitem>
>> > + <para>
>> > + Restore a named schema variable only. Multiple schema
>> variables may be specified with
>> > + multiple <option>-A</option> switches.
>> > + </para>
>> > + </listitem>
>> > + </varlistentry>
>>
>> Do we need that? We have no such option for functions and other
>> non-relations.
>>
>> And if we really want such an option for "pg_restore", why not for
>> "pg_dump"?
>>
>> Yours,
>> Laurenz Albe
>>
>>
>>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-25 20:38:01
Message-ID: CAFj8pRAjU-X6rEE9=1++PdtXOPc2uo=yu-tcFXByi-kN3B_7Vw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

čt 24. 10. 2024 v 10:29 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> ... and here is a review for patch 4
>
> I didn't change any code, just added the odd article to a comment.
>
> While running the regression tests with "make installcheck", I noticed two
> problems:
>
> ---
> /home/laurenz/postgresql/src/test/regress/expected/session_variables.out
> 2024-10-24 11:14:06.717663613 +0300
> +++
> /home/laurenz/postgresql/src/test/regress/results/session_variables.out
> 2024-10-24 11:15:37.999286228 +0300
> @@ -30,6 +30,7 @@
> GRANT ALL ON SCHEMA svartest TO regress_variable_owner;
> CREATE VARIABLE svartest.var1 AS int;
> CREATE ROLE regress_variable_reader;
> +ERROR: role "regress_variable_reader" already exists
>

> I suggest that patch 0001 should drop role "regress_variable_reader" again.
>

I did it,

>
> @@ -107,7 +108,7 @@
> CONTEXT: SQL function "sqlfx" statement 1
> SELECT plpgsqlfx(20);
> ERROR: permission denied for session variable var1
> -CONTEXT: SQL expression "$1 + var1"
> +CONTEXT: PL/pgSQL expression "$1 + var1"
>
> That looks like bit rot from your commit 4af123ad45.
>

fixed

merged your changes of comments

>
> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20241025-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241025-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241025-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241025-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241025-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241025-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241025-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241025-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241025-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241025-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241025-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20241025-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241025-0008-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20241025-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241025-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241025-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20241025-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241025-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241025-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.4 KB
v20241025-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-28 07:01:26
Message-ID: CAFj8pRC+hPCc2X88xC=pTJoqmVPApDsageZOMyqaxi5788WxHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase

Regards

Pavel

Attachment Content-Type Size
v20241028-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241028-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241028-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241028-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241028-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241028-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241028-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241028-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241028-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241028-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241028-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20241028-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241028-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241028-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241028-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241028-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20241028-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241028-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241028-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.3 KB
v20241028-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-10-29 07:16:42
Message-ID: CAFj8pRDJ9cq00VYSHxs6LsoHNWjhYXyWWBtV6UgeWwhs0AHa9A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

again, necessary rebase

Regards

Pavel

Attachment Content-Type Size
v20241029-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241029-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241029-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241029-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241029-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241029-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241029-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241029-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241029-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241029-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241029-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241029-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20241029-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241029-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241029-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241029-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20241029-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241029-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241029-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 147.3 KB
v20241029-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.1 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-02 05:46:12
Message-ID: ecd67165d1e1645b21bda924c927590435584b27.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Tue, 2024-10-29 at 08:16 +0100, Pavel Stehule wrote:
> again, necessary rebase

I have started looking at patch 5, and I have some questions and comments.

- The commit message is headed "memory cleaning after DROP VARIABLE", but
the rest of the commit message speaks of sinval messages. These two
things are independent, aren't they? And both lead to the need to validate
the variables, right?

Then this code comment would for example be wrong:

/* true after accepted sinval message */
static bool needs_validation = false;

It also becomes "true" after DROP VARIABLE, right?
I am happy to fix the comment, but I want to understand the patch first.

- I see that the patch adds cleanup of invalid session variable to each
COMMIT. Is that a good idea? I'd expect that it is good enough to clean
up whenever session variables are accessed.
Calling remove_invalid_session_variables() during each COMMIT will affect
all transactions, and I don't see the benefit.

Also, do we need to call it during pg_session_variables()?

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-02 07:36:30
Message-ID: CAFj8pRBuhB_jgsGx4-Nhpow0vi7g98RjKwTRPM3dSbiKjWdqQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 2. 11. 2024 v 6:46 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Tue, 2024-10-29 at 08:16 +0100, Pavel Stehule wrote:
> > again, necessary rebase
>
> I have started looking at patch 5, and I have some questions and comments.
>
> - The commit message is headed "memory cleaning after DROP VARIABLE", but
> the rest of the commit message speaks of sinval messages. These two
> things are independent, aren't they? And both lead to the need to
> validate
> the variables, right?
>

Maybe it can be formulated differently, but it is true. There are a lot of
sinval messages, but in this case
only sinval messages related to DROP VARIABLE are interesting.

> Then this code comment would for example be wrong:
>
> /* true after accepted sinval message */
> static bool needs_validation = false;
>
> It also becomes "true" after DROP VARIABLE, right?
> I am happy to fix the comment, but I want to understand the patch first.
>

sinval message can be raised by any operation over the pg_variable table.

<-><-->if (hashvalue == 0 || svar->hashvalue == hashvalue)
<-><-->{
<-><--><-->svar->is_valid = false;
+<-><--><-->needs_validation = true;
+<-><-->}
+<->}

When I execute DROP VARIABLE, then the hash value is specified, but the
hash can be zero for some massive cleaning, and there are other events that
can send sinval message. I think an ANALYZE does this. So the comment /*
true after accepted sinval message */ is more accurate than /* true after
DROP VARIABLE */.

>
> - I see that the patch adds cleanup of invalid session variable to each
> COMMIT. Is that a good idea? I'd expect that it is good enough to clean
> up whenever session variables are accessed.
> Calling remove_invalid_session_variables() during each COMMIT will affect
> all transactions, and I don't see the benefit.
>

If I remember well, there were two reasons why I did it.

1. Minimize the unwanted surprises for users that will check memory usage -
So if you drop the variables, then the allocated space is released in
possibly near time. The rule - allocated space is released, when in the
next transaction you use any session variable looks a little bit crazy
(although I think so there will not be real significant difference in
functionality). Correct me, if I am wrong, but I don't remember any memory
(or resource) cleaning in Postgres, that is delayed to second transactions.
I agree, there is overhead of cleaning, but this can be very fast when the
user doesn't use session variables, because the hash table with session
variables is not initialized. I can imagine some usage some hooks there as
alternative

2. The main reason why it is implemented is implementation of temporal
variables with RESET or DROP on transaction end. Related code should be
triggered at commit time, it cannot be delayed.

> Also, do we need to call it during pg_session_variables()?
>

I think it can be removed. Originally pg_session_variables showed only
valid variables, but it is not true now.

Regards

Pavel

>
> Yours,
> Laurenz Albe
>


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-04 09:24:09
Message-ID: abc289edfab94d803afcc84b9c8a2160110a2340.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sat, 2024-11-02 at 08:36 +0100, Pavel Stehule wrote:
> so 2. 11. 2024 v 6:46 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> napsal:
> > - The commit message is headed "memory cleaning after DROP VARIABLE", but
> >   the rest of the commit message speaks of sinval messages.  These two
> >   things are independent, aren't they?  And both lead to the need to validate
> >   the variables, right?
>
> Maybe it can be formulated differently, but it is true. There are a lot of sinval messages, but in this case
> only sinval messages related to DROP VARIABLE are interesting.

Okay...

> >   Then this code comment would for example be wrong:
> >
> >      /* true after accepted sinval message */
> >      static bool needs_validation = false;
> >
> >   It also becomes "true" after DROP VARIABLE, right?
> >   I am happy to fix the comment, but I want to understand the patch first.
> >
>
> sinval message can be raised by any operation over the pg_variable table.

I set a watchpoint on "needs_validation", and when I run DROP VARIABLE, it is called
directly from the command:

Hardware watchpoint 2: needs_validation

Old value = false
New value = true
0x00000000006ad44c in SessionVariableDropPostprocess (varid=<optimized out>) at session_variable.c:169
169 svar->drop_lxid = MyProc->vxid.lxid;
(gdb) where
#0 0x00000000006ad44c in SessionVariableDropPostprocess (varid=<optimized out>) at session_variable.c:169
#1 0x0000000000625dec in DropVariableById (varid=<optimized out>) at pg_variable.c:259
#2 0x00000000005fec57 in doDeletion (object=0x4ac85e8, flags=0) at dependency.c:1450
...
#8 0x00000000008bb7e0 in standard_ProcessUtility (pstmt=0x49ac700, queryString=0x49abbb0 "DROP VARIABLE a;", readOnlyTree=<optimized out>,
context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x49acac0, qc=0x7ffe19d2db60) at utility.c:1076
...
#12 0x00000000008b6742 in exec_simple_query (query_string=0x49abbb0 "DROP VARIABLE a;") at postgres.c:1283

Later, there is a sinval message and "pg_variable_cache_callback()" is called, which sets
"needs_validation" again.

Perhaps my confustion is as follows: if DROP VARIABLE sends an invalidation message,
and the handler sets "needs_validation", why is it necessary to set "needs_validation"
in SessionVariableDropPostprocess() too?

If we didn't set "needs_validation" in SessionVariableDropPostprocess(), the comment
would be true.

> > - I see that the patch adds cleanup of invalid session variable to each
> >   COMMIT.  Is that a good idea?  I'd expect that it is good enough to clean
> >   up whenever session variables are accessed.
> >   Calling remove_invalid_session_variables() during each COMMIT will affect
> >   all transactions, and I don't see the benefit.
>
> If I remember well, there were two reasons why I did it.
>
> 1. Minimize the unwanted surprises for users that will check memory usage - So if you
> drop the variables, then the allocated space is released in possibly near time.
> The rule - allocated space is released, when in the next transaction you use any
> session variable looks a little bit crazy (although I think so there will not be real
> significant difference in functionality).
> Correct me, if I am wrong, but I don't remember any memory (or resource) cleaning
> in Postgres, that is delayed to second transactions. I agree, there is overhead of cleaning,
> but this can be very fast when the user doesn't use session variables, because the hash table
> with session variables is not initialized. I can imagine some usage some hooks there as alternative

I don't think that is a good enough reason.

Memory used by an idle backend is not totally predictable for other reasons as well:
- the catalog cache
- memory that PostgreSQL freed, but that is kept in the malloc arena so that
it can be reused for the next malloc() call

I believe that the disadvantage of keeping some memory allocated across transaction
is not as bad as the pain of going through all variables on each COMMIT.
If you have set one or two session variables and run a lot of statements in
autocommit mode, that is an unnecessary overhead.

> 2. The main reason why it is implemented is implementation of temporal variables
> with RESET or DROP on transaction end. Related code should be triggered at
> commit time, it cannot be delayed.

That makes sense.

If I remember right, temporary variables are an optional feature.
So I suggest that you move AtPreEOXact_SessionVariables() to the patch that adds
temporary session variables.

> >   Also, do we need to call it during pg_session_variables()?
>
> I think it can be removed. Originally pg_session_variables showed only valid variables, but it is not true now.

Right.

I'll wait for your reaction to my above suggestions before I start working on the comments.

Yours,
Laurenz Albe


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-06 18:24:20
Message-ID: CAFj8pRBPXTcw_3fpKtgVthV2+9rZGhxitZ40DnAwCrK601TZZg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

only fresh rebase

Regards

Pavel

Attachment Content-Type Size
v20241106-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241106-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241106-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241106-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241106-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241106-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241106-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241106-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241106-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241106-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241106-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241106-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241106-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241106-0010-implementation-of-temporary-session-variables.patch text/x-patch 39.3 KB
v20241106-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241106-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 22.4 KB
v20241106-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241106-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241106-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241106-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 130.0 KB

From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-10 15:24:19
Message-ID: ndtfl4tsnpkb7m7hwvnmlpsascpgd3a7xvjmjhtxffsbrgygtm@4du6zsmnnwq5
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi folks,

Thanks for continuing this work. As a side note, I would like to mention
how strange the situation in this CF item is. If I understand correctly,
there are two hackers threads discussing the same patch, with recent
patches posted in both of them. This is obviously confusing, e.g. the
main concern from another thread, about names clashing, wasn't even
mentioned in this one. Is it possible to reconcile development in one
thread?


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-10 16:19:09
Message-ID: CAFj8pRAu4XvNCGu1751t=2YEqLqTjDA3FavMExm2S0KYQq=DdQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 10. 11. 2024 v 16:24 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> Hi folks,
>
> Thanks for continuing this work. As a side note, I would like to mention
> how strange the situation in this CF item is. If I understand correctly,
> there are two hackers threads discussing the same patch, with recent
> patches posted in both of them. This is obviously confusing, e.g. the
> main concern from another thread, about names clashing, wasn't even
> mentioned in this one. Is it possible to reconcile development in one
> thread?
>

This is probably my error. I don't try to organize threads, just I'll try
to reply in the thread where I got a question.

Regards

Pavel


From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-10 17:41:07
Message-ID: ssk7uqvu7rirq4vl4ns7vvr5efvgqwpuonu3qpfl6tem7ypifw@jchzp34fhqje
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> On Sun, Nov 10, 2024 at 05:19:09PM GMT, Pavel Stehule wrote:
> ne 10. 11. 2024 v 16:24 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> napsal:
>
> > Hi folks,
> >
> > Thanks for continuing this work. As a side note, I would like to mention
> > how strange the situation in this CF item is. If I understand correctly,
> > there are two hackers threads discussing the same patch, with recent
> > patches posted in both of them. This is obviously confusing, e.g. the
> > main concern from another thread, about names clashing, wasn't even
> > mentioned in this one. Is it possible to reconcile development in one
> > thread?
> >
>
> This is probably my error. I don't try to organize threads, just I'll try
> to reply in the thread where I got a question.

It's fine. I just would appreciate some clarity about which patch to
look at. To confirm, the series in this thread contains everything from
the other one, plus some improvements, right?


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-10 17:51:40
Message-ID: CAFj8pRAsEoeZv0HEnA8CKgFKDSQ-wYw18Os1vdksWCV7ez2bVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> ne 10. 11. 2024 v 16:24 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> napsal:
>
>> Hi folks,
>>
>> Thanks for continuing this work. As a side note, I would like to mention
>> how strange the situation in this CF item is. If I understand correctly,
>> there are two hackers threads discussing the same patch, with recent
>> patches posted in both of them. This is obviously confusing, e.g. the
>> main concern from another thread, about names clashing, wasn't even
>> mentioned in this one. Is it possible to reconcile development in one
>> thread?
>>
>
> This is probably my error. I don't try to organize threads, just I'll try
> to reply in the thread where I got a question.
>

I thought a lot of time about better solutions for identifier collisions
and I really don't think so there is some consistent user friendly syntax.
Personally I think there is an easy already implemented solution -
convention - just use a dedicated schema for variables and this schema
should not be in the search path. Or use secondary convention - like using
prefix "__" for session variables. Common convention is using "_" for
PLpgSQL variables. I searched how this issue is solved in other databases,
or in standard, and I found nothing special. The Oracle and SQL/PSM has a
concept of visibility - the variables are not visible outside packages or
modules, but Postgres has nothing similar. It can be emulated by a
dedicated schema without inserting a search path, but it is less strong.

I think we can introduce an alternative syntax, that will not be user
friendly or readable friendly, but it can be without collisions - or can
decrease possible risks.

It is nothing new - SQL does it with old, "new" syntax of inner joins, or
in Postgres we can

where salary < 40000

or

where pg_catalog.int4lt(salary, 40000);

or some like we use for operators OPERATOR(*schema*.*operatorname*)

So introducing VARIABLE(schema.variablename) syntax as an alternative
syntax for accessing variables I really like. I strongly prefer to use this
as only alternative (secondary) syntax, because I don't think it is
friendly syntax or writing friendly, but it is safe, and I can imagine
tools that can replace generic syntax to this special, or that detects
generic syntax and shows some warning. Then users can choose what they
prefer. Two syntaxes - generic and special can be good enough for all - and
this can be perfectly consistent with current Postgres.

Regards

Pavel

> Regards
>
> Pavel
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-10 18:04:34
Message-ID: CAFj8pRBHrwi6M=QtB_DXjh++r6rEf1HPo1fRM0jN2PJ-CyG0YA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 10. 11. 2024 v 18:41 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Sun, Nov 10, 2024 at 05:19:09PM GMT, Pavel Stehule wrote:
> > ne 10. 11. 2024 v 16:24 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> > napsal:
> >
> > > Hi folks,
> > >
> > > Thanks for continuing this work. As a side note, I would like to
> mention
> > > how strange the situation in this CF item is. If I understand
> correctly,
> > > there are two hackers threads discussing the same patch, with recent
> > > patches posted in both of them. This is obviously confusing, e.g. the
> > > main concern from another thread, about names clashing, wasn't even
> > > mentioned in this one. Is it possible to reconcile development in one
> > > thread?
> > >
> >
> > This is probably my error. I don't try to organize threads, just I'll try
> > to reply in the thread where I got a question.
>
> It's fine. I just would appreciate some clarity about which patch to
> look at. To confirm, the series in this thread contains everything from
> the other one, plus some improvements, right?
>

I don't remember any change that can be visible for users in this thread.
Laurens does very precious code review (thank you again) - there are bigger
changes in comments, and less changes in code - some parts of code are
moved between patches, some lines were redundant and removed, some lines
were artefacts of some git work and were cleaned. Some redundant tests were
removed. There is no new code.

Regards

Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-10 18:09:04
Message-ID: CAFj8pRB5Db7bRupXG0MYKTWp8qj6wWtgJV0Guw31XarTKzaf+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 10. 11. 2024 v 18:51 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
>
>>
>>
>> ne 10. 11. 2024 v 16:24 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
>> napsal:
>>
>>> Hi folks,
>>>
>>> Thanks for continuing this work. As a side note, I would like to mention
>>> how strange the situation in this CF item is. If I understand correctly,
>>> there are two hackers threads discussing the same patch, with recent
>>> patches posted in both of them. This is obviously confusing, e.g. the
>>> main concern from another thread, about names clashing, wasn't even
>>> mentioned in this one. Is it possible to reconcile development in one
>>> thread?
>>>
>>
>> This is probably my error. I don't try to organize threads, just I'll try
>> to reply in the thread where I got a question.
>>
>
> I thought a lot of time about better solutions for identifier collisions
> and I really don't think so there is some consistent user friendly syntax.
> Personally I think there is an easy already implemented solution -
> convention - just use a dedicated schema for variables and this schema
> should not be in the search path. Or use secondary convention - like using
> prefix "__" for session variables. Common convention is using "_" for
> PLpgSQL variables. I searched how this issue is solved in other databases,
> or in standard, and I found nothing special. The Oracle and SQL/PSM has a
> concept of visibility - the variables are not visible outside packages or
> modules, but Postgres has nothing similar. It can be emulated by a
> dedicated schema without inserting a search path, but it is less strong.
>

There can be more collisions in Oracle, because the functions without
arguments don't need parentheses. Postgres is safer, because this syntax is
not allowed.

>
> I think we can introduce an alternative syntax, that will not be user
> friendly or readable friendly, but it can be without collisions - or can
> decrease possible risks.
>
> It is nothing new - SQL does it with old, "new" syntax of inner joins, or
> in Postgres we can
>
> where salary < 40000
>
> or
>
> where pg_catalog.int4lt(salary, 40000);
>
>
> or some like we use for operators OPERATOR(*schema*.*operatorname*)
>
> So introducing VARIABLE(schema.variablename) syntax as an alternative
> syntax for accessing variables I really like. I strongly prefer to use this
> as only alternative (secondary) syntax, because I don't think it is
> friendly syntax or writing friendly, but it is safe, and I can imagine
> tools that can replace generic syntax to this special, or that detects
> generic syntax and shows some warning. Then users can choose what they
> prefer. Two syntaxes - generic and special can be good enough for all - and
> this can be perfectly consistent with current Postgres.
>
> Regards
>
> Pavel
>
>
>> Regards
>>
>> Pavel
>>
>>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-10 22:41:31
Message-ID: CAFj8pRBGffSQjtwsoF-8KffOveMAH9P7R7VVDXW2DTBY0_eosA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 4. 11. 2024 v 10:24 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> On Sat, 2024-11-02 at 08:36 +0100, Pavel Stehule wrote:
> > so 2. 11. 2024 v 6:46 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
> napsal:
> > > - The commit message is headed "memory cleaning after DROP VARIABLE",
> but
> > > the rest of the commit message speaks of sinval messages. These two
> > > things are independent, aren't they? And both lead to the need to
> validate
> > > the variables, right?
> >
> > Maybe it can be formulated differently, but it is true. There are a lot
> of sinval messages, but in this case
> > only sinval messages related to DROP VARIABLE are interesting.
>
> Okay...
>
> > > Then this code comment would for example be wrong:
> > >
> > > /* true after accepted sinval message */
> > > static bool needs_validation = false;
> > >
> > > It also becomes "true" after DROP VARIABLE, right?
> > > I am happy to fix the comment, but I want to understand the patch
> first.
> > >
> >
> > sinval message can be raised by any operation over the pg_variable table.
>
> I set a watchpoint on "needs_validation", and when I run DROP VARIABLE, it
> is called
> directly from the command:
>
> Hardware watchpoint 2: needs_validation
>
> Old value = false
> New value = true
> 0x00000000006ad44c in SessionVariableDropPostprocess (varid=<optimized
> out>) at session_variable.c:169
> 169 svar->drop_lxid = MyProc->vxid.lxid;
> (gdb) where
> #0 0x00000000006ad44c in SessionVariableDropPostprocess (varid=<optimized
> out>) at session_variable.c:169
> #1 0x0000000000625dec in DropVariableById (varid=<optimized out>) at
> pg_variable.c:259
> #2 0x00000000005fec57 in doDeletion (object=0x4ac85e8, flags=0) at
> dependency.c:1450
> ...
> #8 0x00000000008bb7e0 in standard_ProcessUtility (pstmt=0x49ac700,
> queryString=0x49abbb0 "DROP VARIABLE a;", readOnlyTree=<optimized out>,
> context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
> dest=0x49acac0, qc=0x7ffe19d2db60) at utility.c:1076
> ...
> #12 0x00000000008b6742 in exec_simple_query (query_string=0x49abbb0 "DROP
> VARIABLE a;") at postgres.c:1283
>
> Later, there is a sinval message and "pg_variable_cache_callback()" is
> called, which sets
> "needs_validation" again.
>
> Perhaps my confustion is as follows: if DROP VARIABLE sends an
> invalidation message,
> and the handler sets "needs_validation", why is it necessary to set
> "needs_validation"
> in SessionVariableDropPostprocess() too?
>
> If we didn't set "needs_validation" in SessionVariableDropPostprocess(),
> the comment
> would be true.
>

I thought about it, and it is redundant. I removed it. All tests passed
still.

> > > - I see that the patch adds cleanup of invalid session variable to each
> > > COMMIT. Is that a good idea? I'd expect that it is good enough to
> clean
> > > up whenever session variables are accessed.
> > > Calling remove_invalid_session_variables() during each COMMIT will
> affect
> > > all transactions, and I don't see the benefit.
> >
> > If I remember well, there were two reasons why I did it.
> >
> > 1. Minimize the unwanted surprises for users that will check memory
> usage - So if you
> > drop the variables, then the allocated space is released in possibly
> near time.
> > The rule - allocated space is released, when in the next transaction
> you use any
> > session variable looks a little bit crazy (although I think so there
> will not be real
> > significant difference in functionality).
> > Correct me, if I am wrong, but I don't remember any memory (or
> resource) cleaning
> > in Postgres, that is delayed to second transactions. I agree, there
> is overhead of cleaning,
> > but this can be very fast when the user doesn't use session
> variables, because the hash table
> > with session variables is not initialized. I can imagine some usage
> some hooks there as alternative
>
> I don't think that is a good enough reason.
>
> Memory used by an idle backend is not totally predictable for other
> reasons as well:
> - the catalog cache
> - memory that PostgreSQL freed, but that is kept in the malloc arena so
> that
> it can be reused for the next malloc() call
>
> I believe that the disadvantage of keeping some memory allocated across
> transaction
> is not as bad as the pain of going through all variables on each COMMIT.
> If you have set one or two session variables and run a lot of statements in
> autocommit mode, that is an unnecessary overhead.
>
> > 2. The main reason why it is implemented is implementation of temporal
> variables
> > with RESET or DROP on transaction end. Related code should be
> triggered at
> > commit time, it cannot be delayed.
>
> That makes sense.
>
> If I remember right, temporary variables are an optional feature.
> So I suggest that you move AtPreEOXact_SessionVariables() to the patch
> that adds
> temporary session variables.
>

moved

>
> > > Also, do we need to call it during pg_session_variables()?
> >
> > I think it can be removed. Originally pg_session_variables showed only
> valid variables, but it is not true now.
>

removed

>
> Right.
>
> I'll wait for your reaction to my above suggestions before I start working
> on the comments.
>

new patch set attached

Regards

Pavel

>
> Yours,
> Laurenz Albe
>

Attachment Content-Type Size
v20241110-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241110-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241110-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241110-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241110-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241110-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241110-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241110-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241110-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241110-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241110-0010-implementation-of-temporary-session-variables.patch text/x-patch 40.2 KB
v20241110-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241110-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241110-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241110-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241110-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.7 KB
v20241110-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241110-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241110-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241110-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 130.0 KB

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-13 14:24:02
Message-ID: 8842f664d3b4c909d97fd56d374d899fac9a5b84.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Thanks for the updated patch set.

Here is my review of patch 0005:

> --- a/src/backend/access/transam/xact.c
> +++ b/src/backend/access/transam/xact.c
> +#include "commands/session_variable.h"

You probably forgot to move that to the patch for temporary variables.
I did that.

> --- a/src/backend/commands/session_variable.c
> +++ b/src/backend/commands/session_variable.c
> @@ -83,6 +92,19 @@ static HTAB *sessionvars = NULL; /* hash table for session variables */
>
> static MemoryContext SVariableMemoryContext = NULL;
>
> +/* true after accepted sinval message */
> +static bool needs_validation = false;
> +
> +/*
> + * The content of session variables is not removed immediately. When it
> + * is possible we do this at the transaction end. But when the transaction failed,
> + * we cannot do it, because we lost access to the system catalog. So we
> + * try to do it in the next transaction before any get or set of any session
> + * variable. We don't want to repeat this opening cleaning in transaction,
> + * So we store the id of the transaction where opening validation was done.
> + */
> +static LocalTransactionId validated_lxid = InvalidLocalTransactionId;

I have moved the reference to the transaction end to the temporary variable
patch.

I have gone over the comments in patch 0005 and 0006.
I hope I got everything right. Attached is an updated patch set.

Yours,
Laurenz Albe

Attachment Content-Type Size
v20241113-0001-Enhancing-catalog-for-support-session-vari.patch text/x-patch 130.0 KB
v20241113-0002-Storage-for-session-variables-and-SQL-inte.patch text/x-patch 145.2 KB
v20241113-0003-function-pg_session_variables-for-cleaning.patch text/x-patch 4.3 KB
v20241113-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241113-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
v20241113-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241113-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241113-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241113-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241113-0010-implementation-of-temporary-session-variab.patch text/x-patch 42.2 KB
v20241113-0011-Implementation-ON-TRANSACTION-END-RESET-cl.patch text/x-patch 14.6 KB
v20241113-0012-Implementation-of-DEFAULT-clause-default-e.patch text/x-patch 33.7 KB
v20241113-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-c.patch text/x-patch 35.6 KB
v20241113-0014-allow-read-an-value-of-session-variable-di.patch text/x-patch 13.3 KB
v20241113-0015-allow-parallel-execution-queries-with-sess.patch text/x-patch 11.9 KB
v20241113-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241113-0017-expression-with-session-variables-can-be-i.patch text/x-patch 4.2 KB
v20241113-0018-this-patch-changes-error-message-column-do.patch text/x-patch 29.2 KB
v20241113-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241113-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-13 15:06:37
Message-ID: CAFj8pRARuJrNxTDTQN_UmvM4OG7ser9v8+bx=K+P4YjeUZepZA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 13. 11. 2024 v 15:24 odesílatel Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
napsal:

> Thanks for the updated patch set.
>
> Here is my review of patch 0005:
>
> > --- a/src/backend/access/transam/xact.c
> > +++ b/src/backend/access/transam/xact.c
> > +#include "commands/session_variable.h"
>
> You probably forgot to move that to the patch for temporary variables.
> I did that.
>

+1

> > --- a/src/backend/commands/session_variable.c
> > +++ b/src/backend/commands/session_variable.c
> > @@ -83,6 +92,19 @@ static HTAB *sessionvars = NULL; /* hash table for
> session variables */
> >
> > static MemoryContext SVariableMemoryContext = NULL;
> >
> > +/* true after accepted sinval message */
> > +static bool needs_validation = false;
> > +
> > +/*
> > + * The content of session variables is not removed immediately. When it
> > + * is possible we do this at the transaction end. But when the
> transaction failed,
> > + * we cannot do it, because we lost access to the system catalog. So we
> > + * try to do it in the next transaction before any get or set of any
> session
> > + * variable. We don't want to repeat this opening cleaning in
> transaction,
> > + * So we store the id of the transaction where opening validation was
> done.
> > + */
> > +static LocalTransactionId validated_lxid = InvalidLocalTransactionId;
>
> I have moved the reference to the transaction end to the temporary variable
> patch.
>

+1

> I have gone over the comments in patch 0005 and 0006.
> I hope I got everything right. Attached is an updated patch set.
>

Thank you

Pavel

>
> Yours,
> Laurenz Albe
>


From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-13 16:34:59
Message-ID: 3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> On Sun, Nov 10, 2024 at 06:51:40PM GMT, Pavel Stehule wrote:
> ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> napsal:
> I thought a lot of time about better solutions for identifier collisions
> and I really don't think so there is some consistent user friendly syntax.
> Personally I think there is an easy already implemented solution -
> convention - just use a dedicated schema for variables and this schema
> should not be in the search path. Or use secondary convention - like using
> prefix "__" for session variables. Common convention is using "_" for
> PLpgSQL variables. I searched how this issue is solved in other databases,
> or in standard, and I found nothing special. The Oracle and SQL/PSM has a
> concept of visibility - the variables are not visible outside packages or
> modules, but Postgres has nothing similar. It can be emulated by a
> dedicated schema without inserting a search path, but it is less strong.
>
> I think we can introduce an alternative syntax, that will not be user
> friendly or readable friendly, but it can be without collisions - or can
> decrease possible risks.
>
> It is nothing new - SQL does it with old, "new" syntax of inner joins, or
> in Postgres we can
>
> where salary < 40000
>
> or
>
> where pg_catalog.int4lt(salary, 40000);
>
>
> or some like we use for operators OPERATOR(*schema*.*operatorname*)
>
> So introducing VARIABLE(schema.variablename) syntax as an alternative
> syntax for accessing variables I really like. I strongly prefer to use this
> as only alternative (secondary) syntax, because I don't think it is
> friendly syntax or writing friendly, but it is safe, and I can imagine
> tools that can replace generic syntax to this special, or that detects
> generic syntax and shows some warning. Then users can choose what they
> prefer. Two syntaxes - generic and special can be good enough for all - and
> this can be perfectly consistent with current Postgres.

As far as I recall, last time this topic was discussed in hackers, two
options were proposed: the one with VARIABLE(name), what you mention
here; and another one with adding variables to the FROM clause. The
VARIABLE(...) syntax didn't get much negative feedback, so I guess why
not -- if you find it fitting, it would be interesting to see the
implementation.

I'm afraid it should not be just an alternative syntax, but the only one
allowed, because otherwise I don't see how scenarious like "drop a
column with the same name" could be avoided. As in the previous thread:

-- we've got a variable b at the same time
SELECT a, b FROM table1;

Then dropping the column b, but everything still works beause the
variable b got silently picked up. But if it would be required to say
VARIABLE(b), then all fine.

And to make sure we're on the same page, could you post couple of
examples from curretly existing tests in the patch, how are they going
to look like with this proposal?

About adding variables to the FROM clause. Looks like this option was
quite popular, and you've mentioned some technical challenges
implementing that. If you'd like to go with another approach, it would
be great to elaborate on that -- maybe even with a PoC, to make a
convincing point here.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-13 18:18:40
Message-ID: CAFj8pRA8iu-S132zbyGsuVxii9hptKvzgxbLxexL+x+aC4rsog@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 13. 11. 2024 v 17:35 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Sun, Nov 10, 2024 at 06:51:40PM GMT, Pavel Stehule wrote:
> > ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule <
> pavel(dot)stehule(at)gmail(dot)com>
> > napsal:
> > I thought a lot of time about better solutions for identifier collisions
> > and I really don't think so there is some consistent user friendly
> syntax.
> > Personally I think there is an easy already implemented solution -
> > convention - just use a dedicated schema for variables and this schema
> > should not be in the search path. Or use secondary convention - like
> using
> > prefix "__" for session variables. Common convention is using "_" for
> > PLpgSQL variables. I searched how this issue is solved in other
> databases,
> > or in standard, and I found nothing special. The Oracle and SQL/PSM has a
> > concept of visibility - the variables are not visible outside packages or
> > modules, but Postgres has nothing similar. It can be emulated by a
> > dedicated schema without inserting a search path, but it is less strong.
> >
> > I think we can introduce an alternative syntax, that will not be user
> > friendly or readable friendly, but it can be without collisions - or can
> > decrease possible risks.
> >
> > It is nothing new - SQL does it with old, "new" syntax of inner joins, or
> > in Postgres we can
> >
> > where salary < 40000
> >
> > or
> >
> > where pg_catalog.int4lt(salary, 40000);
> >
> >
> > or some like we use for operators OPERATOR(*schema*.*operatorname*)
> >
> > So introducing VARIABLE(schema.variablename) syntax as an alternative
> > syntax for accessing variables I really like. I strongly prefer to use
> this
> > as only alternative (secondary) syntax, because I don't think it is
> > friendly syntax or writing friendly, but it is safe, and I can imagine
> > tools that can replace generic syntax to this special, or that detects
> > generic syntax and shows some warning. Then users can choose what they
> > prefer. Two syntaxes - generic and special can be good enough for all -
> and
> > this can be perfectly consistent with current Postgres.
>
> As far as I recall, last time this topic was discussed in hackers, two
> options were proposed: the one with VARIABLE(name), what you mention
> here; and another one with adding variables to the FROM clause. The
> VARIABLE(...) syntax didn't get much negative feedback, so I guess why
> not -- if you find it fitting, it would be interesting to see the
> implementation.
>
> I'm afraid it should not be just an alternative syntax, but the only one
> allowed, because otherwise I don't see how scenarious like "drop a
> column with the same name" could be avoided. As in the previous thread:
>
> -- we've got a variable b at the same time
> SELECT a, b FROM table1;
>

I am sorry, but I am in very strong opposition against this idea. Nobody
did reply to my questions, that can change my opinion.

1. This introduces possible inconsistency between LET syntax and SELECT
syntax.
What will be the syntax of LET?

LET var = var FROM var

PLpgSQL does something, and it is really strange, and source of some
unwanted bugs. See https://commitfest.postgresql.org/50/5044/

With current design I can support

LET var = expr with wars

or

LET var = (QUERY with vars)

It is perfectly consistent. The expressions will be expressions.

2. I don't know of any product in the world that introduced the same
requirement. So this syntax will be proprietary (SQL/PSM it really doesn't
require) and shock for any users that know other databases. Proprietary
syntax in this area far from syntaxes of other products is hell. Try to
explain to users the working with OUT variables of Postgres's procedures
and functions. And there is some deeper logic.

3. There is a simple solution - convention. Use your own schema like vars,
and use session variables in this schema, When this schema will not be on
the search path, then there is not a collision.
Variables living in schema. Nobody without CREATE right can create it. So
it is safe. Or use prefix in __ for variables in the search path.

4. this requirement introduces syntax inconsistency between plpgsql
variables and session variables - which breaks one goal of the patch -
introducing some global variables for plpgsql (and for all PL).

5. Using more variables and FROM clauses decrease readability of FROM clause

SELECT v1, v2, a, b, c FROM t1, v1, v2, t2, ...

6. Usually composite variables don't want to unpack. When you should use
FROM clause, then composite variables will be unpacked. Then all fields can
be possibly in collision with all other column name

Example

CREATE TYPE t1 AS (id int, name varchar)
CREATE TABLE tab(id int, name varchar)
CREATE VARIABLE var1 AS t1;

SELECT id, name, foo(var1) FROM tab, var1;

Now I have a collision in columns id, name, and everywhere I need to use
aliases. Without necessity to use var in FROM clause, I can just write

SELECT id, name, foo(var) FROM tab

and there is not any risk of collision

> Then dropping the column b, but everything still works beause the
> variable b got silently picked up. But if it would be required to say
> VARIABLE(b), then all fine.
>

but same risk you have any time in plpgsql - all time. I don't remember any
bug report related to this issue.

>
> And to make sure we're on the same page, could you post couple of
> examples from curretly existing tests in the patch, how are they going
> to look like with this proposal?
>
> About adding variables to the FROM clause. Looks like this option was
> quite popular, and you've mentioned some technical challenges
> implementing that. If you'd like to go with another approach, it would
> be great to elaborate on that -- maybe even with a PoC, to make a
> convincing point here.
>

There is not any problem with implementation. I see the main problem with
usability, and I really don't want to implement some like LET var = var
FROM var; I am sorry
It fixes one issue, but it increases possible collisions - so the variables
will be unusable.

Regards

Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-14 07:41:26
Message-ID: CAFj8pRDV_jp9Lsc7aN_HL48yjTFMKtCw1KVEcgxK4D0=d93xeA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 13. 11. 2024 v 17:35 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Sun, Nov 10, 2024 at 06:51:40PM GMT, Pavel Stehule wrote:
> > ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule <
> pavel(dot)stehule(at)gmail(dot)com>
> > napsal:
> > I thought a lot of time about better solutions for identifier collisions
> > and I really don't think so there is some consistent user friendly
> syntax.
> > Personally I think there is an easy already implemented solution -
> > convention - just use a dedicated schema for variables and this schema
> > should not be in the search path. Or use secondary convention - like
> using
> > prefix "__" for session variables. Common convention is using "_" for
> > PLpgSQL variables. I searched how this issue is solved in other
> databases,
> > or in standard, and I found nothing special. The Oracle and SQL/PSM has a
> > concept of visibility - the variables are not visible outside packages or
> > modules, but Postgres has nothing similar. It can be emulated by a
> > dedicated schema without inserting a search path, but it is less strong.
> >
> > I think we can introduce an alternative syntax, that will not be user
> > friendly or readable friendly, but it can be without collisions - or can
> > decrease possible risks.
> >
> > It is nothing new - SQL does it with old, "new" syntax of inner joins, or
> > in Postgres we can
> >
> > where salary < 40000
> >
> > or
> >
> > where pg_catalog.int4lt(salary, 40000);
> >
> >
> > or some like we use for operators OPERATOR(*schema*.*operatorname*)
> >
> > So introducing VARIABLE(schema.variablename) syntax as an alternative
> > syntax for accessing variables I really like. I strongly prefer to use
> this
> > as only alternative (secondary) syntax, because I don't think it is
> > friendly syntax or writing friendly, but it is safe, and I can imagine
> > tools that can replace generic syntax to this special, or that detects
> > generic syntax and shows some warning. Then users can choose what they
> > prefer. Two syntaxes - generic and special can be good enough for all -
> and
> > this can be perfectly consistent with current Postgres.
>
> As far as I recall, last time this topic was discussed in hackers, two
> options were proposed: the one with VARIABLE(name), what you mention
> here; and another one with adding variables to the FROM clause. The
> VARIABLE(...) syntax didn't get much negative feedback, so I guess why
> not -- if you find it fitting, it would be interesting to see the
> implementation.
>
> I'm afraid it should not be just an alternative syntax, but the only one
> allowed, because otherwise I don't see how scenarious like "drop a
> column with the same name" could be avoided. As in the previous thread:
>
> -- we've got a variable b at the same time
> SELECT a, b FROM table1;
>
> Then dropping the column b, but everything still works beause the
> variable b got silently picked up. But if it would be required to say
> VARIABLE(b), then all fine.
>

In this scenario you will get a warning related to variable shadowing
(before you drop a column).

I think this issue can be partially similar to creating two equally named
tables in different schemas (both schemas are in search path). When you
drop one table, the query will work, but the result is different. It is the
same issue. The SQL has no concept of shadowing and on the base line it is
not necessary. But when you integrate SQL with some procedural code then
you should solve this issue (or accept). This issue is real, and it is in
every procedural enhancement of SQL that I know with the same syntax. On
the other hand I doubt this is a real issue. The changes of system
catalogue are tested before production - so probably you will read a
warning about a shadowed variable, and probably you will get different
results, because variable b has the same value for all rows, and probably
will have different value than column b. I can imagine the necessity of
disabling this warning on production systems. Shadowing by self is not an
issue, probably, but it is a signal of code quality problems.

But this scenario is real, and then it is a question if the warning about
shadowed variables should be only optional and if it can be disabled. Maybe
not. Generally the shadowing is a strange concept - it is safeguard against
serious issues, but it should not be used generally and everywhere the
developer should rename the conflict identifiers.

Regards

Pavel

> And to make sure we're on the same page, could you post couple of
> examples from curretly existing tests in the patch, how are they going
> to look like with this proposal?
>
> About adding variables to the FROM clause. Looks like this option was
> quite popular, and you've mentioned some technical challenges
> implementing that. If you'd like to go with another approach, it would
> be great to elaborate on that -- maybe even with a PoC, to make a
> convincing point here.
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-15 04:45:58
Message-ID: CAFj8pRB9X5XOU1gRfMAvF-uQMNFr6VqwTzzxxfqRjUeJ_0BN7g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

čt 14. 11. 2024 v 8:41 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> st 13. 11. 2024 v 17:35 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> napsal:
>
>> > On Sun, Nov 10, 2024 at 06:51:40PM GMT, Pavel Stehule wrote:
>> > ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule <
>> pavel(dot)stehule(at)gmail(dot)com>
>> > napsal:
>> > I thought a lot of time about better solutions for identifier collisions
>> > and I really don't think so there is some consistent user friendly
>> syntax.
>> > Personally I think there is an easy already implemented solution -
>> > convention - just use a dedicated schema for variables and this schema
>> > should not be in the search path. Or use secondary convention - like
>> using
>> > prefix "__" for session variables. Common convention is using "_" for
>> > PLpgSQL variables. I searched how this issue is solved in other
>> databases,
>> > or in standard, and I found nothing special. The Oracle and SQL/PSM has
>> a
>> > concept of visibility - the variables are not visible outside packages
>> or
>> > modules, but Postgres has nothing similar. It can be emulated by a
>> > dedicated schema without inserting a search path, but it is less strong.
>> >
>> > I think we can introduce an alternative syntax, that will not be user
>> > friendly or readable friendly, but it can be without collisions - or can
>> > decrease possible risks.
>> >
>> > It is nothing new - SQL does it with old, "new" syntax of inner joins,
>> or
>> > in Postgres we can
>> >
>> > where salary < 40000
>> >
>> > or
>> >
>> > where pg_catalog.int4lt(salary, 40000);
>> >
>> >
>> > or some like we use for operators OPERATOR(*schema*.*operatorname*)
>> >
>> > So introducing VARIABLE(schema.variablename) syntax as an alternative
>> > syntax for accessing variables I really like. I strongly prefer to use
>> this
>> > as only alternative (secondary) syntax, because I don't think it is
>> > friendly syntax or writing friendly, but it is safe, and I can imagine
>> > tools that can replace generic syntax to this special, or that detects
>> > generic syntax and shows some warning. Then users can choose what they
>> > prefer. Two syntaxes - generic and special can be good enough for all -
>> and
>> > this can be perfectly consistent with current Postgres.
>>
>> As far as I recall, last time this topic was discussed in hackers, two
>> options were proposed: the one with VARIABLE(name), what you mention
>> here; and another one with adding variables to the FROM clause. The
>> VARIABLE(...) syntax didn't get much negative feedback, so I guess why
>> not -- if you find it fitting, it would be interesting to see the
>> implementation.
>>
>> I'm afraid it should not be just an alternative syntax, but the only one
>> allowed, because otherwise I don't see how scenarious like "drop a
>> column with the same name" could be avoided. As in the previous thread:
>>
>> -- we've got a variable b at the same time
>> SELECT a, b FROM table1;
>>
>> Then dropping the column b, but everything still works beause the
>> variable b got silently picked up. But if it would be required to say
>> VARIABLE(b), then all fine.
>>
>
> In this scenario you will get a warning related to variable shadowing
> (before you drop a column).
>
> I think this issue can be partially similar to creating two equally named
> tables in different schemas (both schemas are in search path). When you
> drop one table, the query will work, but the result is different. It is the
> same issue. The SQL has no concept of shadowing and on the base line it is
> not necessary. But when you integrate SQL with some procedural code then
> you should solve this issue (or accept). This issue is real, and it is in
> every procedural enhancement of SQL that I know with the same syntax. On
> the other hand I doubt this is a real issue. The changes of system
> catalogue are tested before production - so probably you will read a
> warning about a shadowed variable, and probably you will get different
> results, because variable b has the same value for all rows, and probably
> will have different value than column b. I can imagine the necessity of
> disabling this warning on production systems. Shadowing by self is not an
> issue, probably, but it is a signal of code quality problems.
>
> But this scenario is real, and then it is a question if the warning about
> shadowed variables should be only optional and if it can be disabled. Maybe
> not. Generally the shadowing is a strange concept - it is safeguard against
> serious issues, but it should not be used generally and everywhere the
> developer should rename the conflict identifiers.
>

There can be another example against usage of the FROM clause for
variables. Because it solves just one special case, but others are not
covered.

Theoretically, variables can have the same names as tables. The table
overshadows the variable, so it can work. But when somebody drops the
variable, then the query still can work. So requirement of usage variable
in FROM clause protects us just against drop column, but not against
dropping table. In Postgres the dropping table is possibly risky due
search_path (that introduces shadowing concept) without introduction
variables. There is a possibility of this issue, but how common is this
issue?

Regards

Pavel

>
> Regards
>
> Pavel
>
>
>> And to make sure we're on the same page, could you post couple of
>> examples from curretly existing tests in the patch, how are they going
>> to look like with this proposal?
>>
>> About adding variables to the FROM clause. Looks like this option was
>> quite popular, and you've mentioned some technical challenges
>> implementing that. If you'd like to go with another approach, it would
>> be great to elaborate on that -- maybe even with a PoC, to make a
>> convincing point here.
>>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 06:10:31
Message-ID: CAFj8pRBoWPDTOwn5FmMzc+1qiopw+N04U26nviOdF61fs8A2wQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 13. 11. 2024 v 17:35 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Sun, Nov 10, 2024 at 06:51:40PM GMT, Pavel Stehule wrote:
> > ne 10. 11. 2024 v 17:19 odesílatel Pavel Stehule <
> pavel(dot)stehule(at)gmail(dot)com>
> > napsal:
> > I thought a lot of time about better solutions for identifier collisions
> > and I really don't think so there is some consistent user friendly
> syntax.
> > Personally I think there is an easy already implemented solution -
> > convention - just use a dedicated schema for variables and this schema
> > should not be in the search path. Or use secondary convention - like
> using
> > prefix "__" for session variables. Common convention is using "_" for
> > PLpgSQL variables. I searched how this issue is solved in other
> databases,
> > or in standard, and I found nothing special. The Oracle and SQL/PSM has a
> > concept of visibility - the variables are not visible outside packages or
> > modules, but Postgres has nothing similar. It can be emulated by a
> > dedicated schema without inserting a search path, but it is less strong.
> >
> > I think we can introduce an alternative syntax, that will not be user
> > friendly or readable friendly, but it can be without collisions - or can
> > decrease possible risks.
> >
> > It is nothing new - SQL does it with old, "new" syntax of inner joins, or
> > in Postgres we can
> >
> > where salary < 40000
> >
> > or
> >
> > where pg_catalog.int4lt(salary, 40000);
> >
> >
> > or some like we use for operators OPERATOR(*schema*.*operatorname*)
> >
> > So introducing VARIABLE(schema.variablename) syntax as an alternative
> > syntax for accessing variables I really like. I strongly prefer to use
> this
> > as only alternative (secondary) syntax, because I don't think it is
> > friendly syntax or writing friendly, but it is safe, and I can imagine
> > tools that can replace generic syntax to this special, or that detects
> > generic syntax and shows some warning. Then users can choose what they
> > prefer. Two syntaxes - generic and special can be good enough for all -
> and
> > this can be perfectly consistent with current Postgres.
>
> As far as I recall, last time this topic was discussed in hackers, two
> options were proposed: the one with VARIABLE(name), what you mention
> here; and another one with adding variables to the FROM clause. The
> VARIABLE(...) syntax didn't get much negative feedback, so I guess why
> not -- if you find it fitting, it would be interesting to see the
> implementation.
>
> I'm afraid it should not be just an alternative syntax, but the only one
> allowed, because otherwise I don't see how scenarious like "drop a
> column with the same name" could be avoided. As in the previous thread:
>
> -- we've got a variable b at the same time
> SELECT a, b FROM table1;
>
> Then dropping the column b, but everything still works beause the
> variable b got silently picked up. But if it would be required to say
> VARIABLE(b), then all fine.
>
> And to make sure we're on the same page, could you post couple of
> examples from curretly existing tests in the patch, how are they going
> to look like with this proposal?
>

What do you think about the following design? I can implement a warning
"variable_usage_guard" when the variable is accessed without using
VARIABLE() syntax. We can discuss later if this warning can be enabled by
default or not. There I am open to any variant.

So for variable public.a and table public.foo(a, b)

I can write

LET a = 10; -- there is not possible collision
LET a = a + 1; -- there is not possible collision, no warning

SELECT a, b FROM foo; -- there is a collision - and warning "variable a is
shadowed"
SELECT VARIABLE(a), b FROM foo; -- no collision, no warning

After ALTER TABLE foo DROP COLUMN a;

SELECT a, b FROM foo; -- possible warning "the usage in variable without
safe syntax",
SELECT VARIABLE(a), b FROM foo; -- no warning

I think this design can be good for all. variable_usage_guard can be
enabled by default. If somebody uses conventions for collision protection,
then he can safely disable it.

Comments, notes?

Regards

Pavel

> About adding variables to the FROM clause. Looks like this option was
> quite popular, and you've mentioned some technical challenges
> implementing that. If you'd like to go with another approach, it would
> be great to elaborate on that -- maybe even with a PoC, to make a
> convincing point here.
>


From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 14:27:30
Message-ID: stckyvkl4yyzvgjsaawojs3xikke7mmds5bhv7l7qerclywywk@h4v4n43xm6u2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> On Sat, Nov 16, 2024 at 07:10:31AM GMT, Pavel Stehule wrote:

Sorry, got distracted. Let me try to answer step by step.

> > As far as I recall, last time this topic was discussed in hackers, two
> > options were proposed: the one with VARIABLE(name), what you mention
> > here; and another one with adding variables to the FROM clause. The
> > VARIABLE(...) syntax didn't get much negative feedback, so I guess why
> > not -- if you find it fitting, it would be interesting to see the
> > implementation.
> >
> > I'm afraid it should not be just an alternative syntax, but the only one
> > allowed, because otherwise I don't see how scenarious like "drop a
> > column with the same name" could be avoided. As in the previous thread:
> >
> > -- we've got a variable b at the same time
> > SELECT a, b FROM table1;
> >
>
> I am sorry, but I am in very strong opposition against this idea. Nobody
> did reply to my questions, that can change my opinion.

From your reply it's not quite clear, are you opposed to have a mandatory
VARIABLE syntax, or having variables in the FROM clause? My main proposal was
about the former, but the points that are following seems to talk about the
latter. I think it's fine to reject the idea about the FROM clause, as long as
you got some reasonable arguments.

> > Then dropping the column b, but everything still works beause the
> > variable b got silently picked up. But if it would be required to say
> > VARIABLE(b), then all fine.
>
> but same risk you have any time in plpgsql - all time. I don't remember any
> bug report related to this issue.

Which exactly scenario about plpgsql do you have in mind? Just have tried to
declare a variable inside a plpgsql function with the same name as a table
column, and got an error about an ambiguous reference.

> Theoretically, variables can have the same names as tables. The table
> overshadows the variable, so it can work. But when somebody drops the
> variable, then the query still can work. So requirement of usage variable
> in FROM clause protects us just against drop column, but not against
> dropping table. In Postgres the dropping table is possibly risky due
> search_path (that introduces shadowing concept) without introduction
> variables. There is a possibility of this issue, but how common is this
> issue?

This sounds to me like an argument against allowing name clashing between
variables and tables. It makes even more sense, since session variables are in
many ways similar to tables.

> I think this issue can be partially similar to creating two equally named
> tables in different schemas (both schemas are in search path). When you
> drop one table, the query will work, but the result is different. It is the
> same issue. The SQL has no concept of shadowing and on the base line it is
> not necessary.

The point is that most of users are aware about schemas and search path
dangers. But to me such a precedent is not an excuse to introduce a new feature
with similar traps, which folks would have to learn by making mistakes. Judging
from the feedback to this patch over time, I've got an impression that lots of
people are also not fans of that.

> > Then dropping the column b, but everything still works beause the
> > variable b got silently picked up. But if it would be required to say
> > VARIABLE(b), then all fine.
> >
>
> In this scenario you will get a warning related to variable shadowing
> (before you drop a column).
>
> [...]
>
> What do you think about the following design? I can implement a warning
> "variable_usage_guard" when the variable is accessed without using
> VARIABLE() syntax. We can discuss later if this warning can be enabled by
> default or not. There I am open to any variant.

I don't follow what are you winning by that? In the context of problem above
(i.e. dropping a column), such a warning is functionally equivalend to a
warning about shadowing.

The problem is that it doesn't sound very appealing to have a feature, which
requires some extra efforts to be used in a right way (e.g. put everything into
a special vars schema, or keep an eye on logs). Most certainly there are such
bits in PostgreSQL today, with all the best practices, crowd wisdom, etc. But
the bar for new features in this sense is much higher, you can see it from the
feedback to this patch. Thus I believe it makes sense, from purely tactical
reasons, to not try to convince half of the community to lower the bar, but
instead try to modify the feature to make it more acceptable, even if some
parts you might not like.

Btw, could you repeat, what was exactly your argument against mandatory
VARIABLE() syntax? It's somehow scattered across many replies, would be great
to summarize it in a couple of phrases.

> Shadowing by self is not an issue, probably, but it is a signal of code
> quality problems.

Agree, but I'm afraid code quality of an average application using PostgreSQL
is quite low, so here we are.

As a side note, I've recently caught myself thinking "it would be cool to have
session variables here". The use case was preparing a policy for RLS, based on
some session-level data set by an application. This session-level data is of a
composite data type, so simple current_setting is cumbersome to use, and a
temporary table will be dropped at the end, taking the policy with it due to
the recorded dependency between them. Thus a session variable of some composite
type sounds like a good fit.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 14:34:58
Message-ID: CAFj8pRAX4Pmh_pNcOFF7r_hHkdDNnZ7iwEb_7JyxOzZ8ZrxpXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

> As a side note, I've recently caught myself thinking "it would be cool to
> have
> session variables here". The use case was preparing a policy for RLS,
> based on
> some session-level data set by an application. This session-level data is
> of a
> composite data type, so simple current_setting is cumbersome to use, and a
> temporary table will be dropped at the end, taking the policy with it due
> to
> the recorded dependency between them. Thus a session variable of some
> composite
> type sounds like a good fit.
>

yes, RLS support is one mentioned use case, and strong reason the access
rights are implemented there.

Regards

Pavel


From: Wolfgang Walther <walther(at)technowledgy(dot)de>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 14:56:53
Message-ID: 78f3c264-658a-4007-ab79-4cc913fba675@technowledgy.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Dmitry Dolgov:
> This sounds to me like an argument against allowing name clashing between
> variables and tables. It makes even more sense, since session variables are in
> many ways similar to tables.

+1

My mental model of a session variable is similar to a single-row,
optionally global temporary, table.

Is there any substantial difference that I am not aware of?

Best,

Wolfgang


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Wolfgang Walther <walther(at)technowledgy(dot)de>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 15:36:19
Message-ID: CAFj8pRCeh3u9rSqq0me52iik9+pNUvYeb8OgbuFxJArrb4VDjA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 16. 11. 2024 v 15:56 odesílatel Wolfgang Walther <walther(at)technowledgy(dot)de>
napsal:

> Dmitry Dolgov:
> > This sounds to me like an argument against allowing name clashing between
> > variables and tables. It makes even more sense, since session variables
> are in
> > many ways similar to tables.
>
> +1
>

It doesn't help too much, because the unique tuple (schema, name), and
there is a search path.

Secondly, the pg_class is not good enough for description of scalar
variables, and enhancing pg_class for scalar variables can be messy.

>
> My mental model of a session variable is similar to a single-row,
> optionally global temporary, table.
>
> Is there any substantial difference that I am not aware of?
>

What I know, the variables are used as query parameters, not as relations -
Oracle, DB2, MSSQL, MySQL, ...

semantically, yes - it is a global temporary object, but it can be scalar
or composite value - it is not row.

(global (temp)) table can hold 0, 1 or more rows (and rows are always
composite of 0..n fields). The variable holds a value of some type.
Proposed session variables are like plpgsql variables (only with different
scope). In Postgres there is a difference between a scalar variable and
composite variable with one field.

Regards

Pavel

> Best,
>
> Wolfgang
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 15:41:10
Message-ID: CAFj8pRDn7W+80gxYUuPTsgAOZZRkjjZ_=SG6ZRO4a2TKQwnPJg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase - based on Laurenz's patch set

Regards

Pavel

Attachment Content-Type Size
v20241116-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241116-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241116-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241116-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241116-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241116-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241116-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241116-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241116-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241116-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241116-0010-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
v20241116-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241116-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241116-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241116-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241116-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
v20241116-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241116-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241116-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241116-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

From: Wolfgang Walther <walther(at)technowledgy(dot)de>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 17:13:38
Message-ID: 0e35aece-a138-4ee1-9bb8-92a4a55ff149@technowledgy.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Pavel Stehule:
> (global (temp)) table can hold 0, 1 or more rows (and rows are always
> composite of 0..n fields). The variable holds a value of some type.
> Proposed session variables are like plpgsql variables (only with
> different scope). In Postgres there is a difference between a scalar
> variable and composite variable with one field.

I can store composite values in table columns, too. A table column can
either be scalar or composite in that sense.

So, maybe rephrase: Single-row, single-column (global (temp)) table =
variable. One "cell" of that table.

For me, the major difference between a variable and a table is, that the
table has 0...n rows and 0...m columns, while the variable has *exactly*
one in both cases, not 0 either.

I must put tables into FROM, why not those nice mini-tables called
variables as well? Because they are potentially scalar, you say!

But: I can already put functions returning scalar values into FROM:

  SELECT * FROM format('hello');

The function returns a plain string only.

I don't know. This just "fits" for me.

Or to put it differently: I don't really care whether I have to write
"(SELECT variable FROM variable)" instead of just "variable". I don't
want session variables for the syntax, I want session variables, because
they are **so much better** than custom GUCs.

Best,

Wolfgang


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Wolfgang Walther <walther(at)technowledgy(dot)de>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 22:07:29
Message-ID: CAFj8pRDjdzhQ48o4H8FsjtLkc7cHdUzmvpAV6Bi1srE70uj8Yg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 16. 11. 2024 v 18:13 odesílatel Wolfgang Walther <walther(at)technowledgy(dot)de>
napsal:

> Pavel Stehule:
> > (global (temp)) table can hold 0, 1 or more rows (and rows are always
> > composite of 0..n fields). The variable holds a value of some type.
> > Proposed session variables are like plpgsql variables (only with
> > different scope). In Postgres there is a difference between a scalar
> > variable and composite variable with one field.
>
> I can store composite values in table columns, too. A table column can
> either be scalar or composite in that sense.
>
> So, maybe rephrase: Single-row, single-column (global (temp)) table =
> variable. One "cell" of that table.
>

the tables are tables and variables are variables. For tables you have
INSERT, UPDATE, DELETE commands, for variables you have a LET command.

and scalar is not a single column composite.

The session variables can in some particular use cases replace global temp
tables, but this is not the goal. I would like to see global temp tables in
Postgres too. Maybe session variables prepare a field for this, because
some people better understand global temp objects. But again my proposal is
not related to global temp tables. This is a different feature.

>
> For me, the major difference between a variable and a table is, that the
> table has 0...n rows and 0...m columns, while the variable has *exactly*
> one in both cases, not 0 either.
>
> I must put tables into FROM, why not those nice mini-tables called
> variables as well? Because they are potentially scalar, you say!
>
> But: I can already put functions returning scalar values into FROM:
>
> SELECT * FROM format('hello');
>
> The function returns a plain string only.
>
> I don't know. This just "fits" for me.
>

There are more issues - one - when you use some composite in FROM clause,
then you expect an unpacked result. But there are a lot of uses, when
unpackaging is not wanted. There is a syntax for this but it is really not
intuitive and not well readable.

>
> Or to put it differently: I don't really care whether I have to write
> "(SELECT variable FROM variable)" instead of just "variable". I don't
> want session variables for the syntax, I want session variables, because
> they are **so much better** than custom GUCs.
>

session variables are better than GUC for the proposed purpose. But it
should look like variables. The software should respect standards or common
typical usage when it is possible. If we introduce fully proprietary
design, then it will be hell for all people who know any other databases.
And I don't see a strong benefit from this syntax. It solves just one case,
it doesn't solve other possible issues, and it introduces another possible
risk.

Regards

Pavel

> Best,
>
> Wolfgang
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-16 22:49:42
Message-ID: CAFj8pRCcGp02OYYAtCxXTO8Lr2fctCUSiKBOmKtThTXwquFzcw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 16. 11. 2024 v 15:27 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Sat, Nov 16, 2024 at 07:10:31AM GMT, Pavel Stehule wrote:
>
> Sorry, got distracted. Let me try to answer step by step.
>
> > > As far as I recall, last time this topic was discussed in hackers, two
> > > options were proposed: the one with VARIABLE(name), what you mention
> > > here; and another one with adding variables to the FROM clause. The
> > > VARIABLE(...) syntax didn't get much negative feedback, so I guess why
> > > not -- if you find it fitting, it would be interesting to see the
> > > implementation.
> > >
> > > I'm afraid it should not be just an alternative syntax, but the only
> one
> > > allowed, because otherwise I don't see how scenarious like "drop a
> > > column with the same name" could be avoided. As in the previous thread:
> > >
> > > -- we've got a variable b at the same time
> > > SELECT a, b FROM table1;
> > >
> >
> > I am sorry, but I am in very strong opposition against this idea. Nobody
> > did reply to my questions, that can change my opinion.
>
> From your reply it's not quite clear, are you opposed to have a mandatory
> VARIABLE syntax, or having variables in the FROM clause? My main proposal
> was
> about the former, but the points that are following seems to talk about the
> latter. I think it's fine to reject the idea about the FROM clause, as
> long as
> you got some reasonable arguments.
>

I am against a requirement to specify a variable in the FROM clause.

>
> > > Then dropping the column b, but everything still works beause the
> > > variable b got silently picked up. But if it would be required to say
> > > VARIABLE(b), then all fine.
> >
> > but same risk you have any time in plpgsql - all time. I don't remember
> any
> > bug report related to this issue.
>
> Which exactly scenario about plpgsql do you have in mind? Just have tried
> to
> declare a variable inside a plpgsql function with the same name as a table
> column, and got an error about an ambiguous reference.
>

Until you execute the query, you cannot know if there is a conflict or not.
So you can change table structure and you can change the procedure's code,
and there can be an invisible conflict until execution and query
evaluation. The conflict between PL/pgSQL and SQL raises an error. The
conflict between session variables and SQL raises warnings. The issue is
detected.

>
> > Theoretically, variables can have the same names as tables. The table
> > overshadows the variable, so it can work. But when somebody drops the
> > variable, then the query still can work. So requirement of usage variable
> > in FROM clause protects us just against drop column, but not against
> > dropping table. In Postgres the dropping table is possibly risky due
> > search_path (that introduces shadowing concept) without introduction
> > variables. There is a possibility of this issue, but how common is this
> > issue?
>
> This sounds to me like an argument against allowing name clashing between
> variables and tables. It makes even more sense, since session variables
> are in
> many ways similar to tables.
>
>
It doesn't help too much. It can fix just one issue. But you can have
tables with the same name in different schemas inside schemas from
search_path. Unique table names solve nothing.

> > I think this issue can be partially similar to creating two equally named
> > tables in different schemas (both schemas are in search path). When you
> > drop one table, the query will work, but the result is different. It is
> the
> > same issue. The SQL has no concept of shadowing and on the base line it
> is
> > not necessary.
>
> The point is that most of users are aware about schemas and search path
> dangers. But to me such a precedent is not an excuse to introduce a new
> feature
> with similar traps, which folks would have to learn by making mistakes.
> Judging
> from the feedback to this patch over time, I've got an impression that
> lots of
> people are also not fans of that.
>

Unfortunately - I don't believe so there is some syntax without traps. You
can check all implementations in other databases. These designs are very
different, and all have some issues and all have some limits. It is native
- you are trying to join the procedural and functional world.

I understand the risks. These risks are there. But there is no silver
bullet - all proposed designs fixed just one case, and not others, and then
I don't see a strong enough benefit to introduce design that is far from
common usage. Maybe I have a different experience, because I am a man from
the stored procedures area, and the risk of collisions is a known issue
well solved by common conventions and in postgres by
plpgsql.variable_conflict setting. The proposed patch set has very similar
functionality. I think the introduction of VARIABLE(xx) syntax and safe
syntax guard warning the usage of variables can be safe in how it is
possible. But still I want to allow "short" "usual" usage to people who use
a safe convention. There is no risk when you use a safe prefix or safe
schema.

>
> > > Then dropping the column b, but everything still works beause the
> > > variable b got silently picked up. But if it would be required to say
> > > VARIABLE(b), then all fine.
> > >
> >
> > In this scenario you will get a warning related to variable shadowing
> > (before you drop a column).
> >
> > [...]
> >
> > What do you think about the following design? I can implement a warning
> > "variable_usage_guard" when the variable is accessed without using
> > VARIABLE() syntax. We can discuss later if this warning can be enabled by
> > default or not. There I am open to any variant.
>
> I don't follow what are you winning by that? In the context of problem
> above
> (i.e. dropping a column), such a warning is functionally equivalend to a
> warning about shadowing.
>
> The problem is that it doesn't sound very appealing to have a feature,
> which
> requires some extra efforts to be used in a right way (e.g. put everything
> into
> a special vars schema, or keep an eye on logs). Most certainly there are
> such
> bits in PostgreSQL today, with all the best practices, crowd wisdom, etc.
> But
> the bar for new features in this sense is much higher, you can see it from
> the
> feedback to this patch. Thus I believe it makes sense, from purely tactical
> reasons, to not try to convince half of the community to lower the bar, but
> instead try to modify the feature to make it more acceptable, even if some
> parts you might not like.
>
> Btw, could you repeat, what was exactly your argument against mandatory
> VARIABLE() syntax? It's somehow scattered across many replies, would be
> great
> to summarize it in a couple of phrases.
>
> > Shadowing by self is not an issue, probably, but it is a signal of code
> > quality problems.
>
> Agree, but I'm afraid code quality of an average application using
> PostgreSQL
> is quite low, so here we are.
>
> As a side note, I've recently caught myself thinking "it would be cool to
> have
> session variables here". The use case was preparing a policy for RLS,
> based on
> some session-level data set by an application. This session-level data is
> of a
> composite data type, so simple current_setting is cumbersome to use, and a
> temporary table will be dropped at the end, taking the policy with it due
> to
> the recorded dependency between them. Thus a session variable of some
> composite
> type sounds like a good fit.
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-17 04:41:00
Message-ID: CAFj8pRBVCOv=VhpprPsVa6AoE=i=Y9s-HRcMvYnyWaOJaJPm-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 16. 11. 2024 v 23:49 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> so 16. 11. 2024 v 15:27 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> napsal:
>
>> > On Sat, Nov 16, 2024 at 07:10:31AM GMT, Pavel Stehule wrote:
>>
>> Sorry, got distracted. Let me try to answer step by step.
>>
>> > > As far as I recall, last time this topic was discussed in hackers, two
>> > > options were proposed: the one with VARIABLE(name), what you mention
>> > > here; and another one with adding variables to the FROM clause. The
>> > > VARIABLE(...) syntax didn't get much negative feedback, so I guess why
>> > > not -- if you find it fitting, it would be interesting to see the
>> > > implementation.
>> > >
>> > > I'm afraid it should not be just an alternative syntax, but the only
>> one
>> > > allowed, because otherwise I don't see how scenarious like "drop a
>> > > column with the same name" could be avoided. As in the previous
>> thread:
>> > >
>> > > -- we've got a variable b at the same time
>> > > SELECT a, b FROM table1;
>> > >
>> >
>> > I am sorry, but I am in very strong opposition against this idea.
>> Nobody
>> > did reply to my questions, that can change my opinion.
>>
>> From your reply it's not quite clear, are you opposed to have a mandatory
>> VARIABLE syntax, or having variables in the FROM clause? My main proposal
>> was
>> about the former, but the points that are following seems to talk about
>> the
>> latter. I think it's fine to reject the idea about the FROM clause, as
>> long as
>> you got some reasonable arguments.
>>
>
> I am against a requirement to specify a variable in the FROM clause.
>
>
>>
>> > > Then dropping the column b, but everything still works beause the
>> > > variable b got silently picked up. But if it would be required to say
>> > > VARIABLE(b), then all fine.
>> >
>> > but same risk you have any time in plpgsql - all time. I don't remember
>> any
>> > bug report related to this issue.
>>
>> Which exactly scenario about plpgsql do you have in mind? Just have tried
>> to
>> declare a variable inside a plpgsql function with the same name as a table
>> column, and got an error about an ambiguous reference.
>>
>
> Until you execute the query, you cannot know if there is a conflict or
> not. So you can change table structure and you can change the procedure's
> code, and there can be an invisible conflict until execution and query
> evaluation. The conflict between PL/pgSQL and SQL raises an error. The
> conflict between session variables and SQL raises warnings. The issue is
> detected.
>
>
>
>>
>> > Theoretically, variables can have the same names as tables. The table
>> > overshadows the variable, so it can work. But when somebody drops the
>> > variable, then the query still can work. So requirement of usage
>> variable
>> > in FROM clause protects us just against drop column, but not against
>> > dropping table. In Postgres the dropping table is possibly risky due
>> > search_path (that introduces shadowing concept) without introduction
>> > variables. There is a possibility of this issue, but how common is this
>> > issue?
>>
>> This sounds to me like an argument against allowing name clashing between
>> variables and tables. It makes even more sense, since session variables
>> are in
>> many ways similar to tables.
>>
>>
> It doesn't help too much. It can fix just one issue. But you can have
> tables with the same name in different schemas inside schemas from
> search_path. Unique table names solve nothing.
>

the combination of pg_class and pg_attribute cannot describe scalar
variables (without hacks). Then you need to enhance pg_class, which can be
confusing. And on the second hand almost all columns in pg_class have no
sense for variables. And when variables and tables are in different tables,
you cannot ensure a unique name. Variables are similar to tables only in
possibility to hold a value. That is all. But variables don't store data to
file, don't store data in pages, don't allow usage of other storages or
formats, and don't support foreign storage. The similarity between
variables and tables is like the similarity between horses and cars. Both
can help with moving.

>
>> > I think this issue can be partially similar to creating two equally
>> named
>> > tables in different schemas (both schemas are in search path). When you
>> > drop one table, the query will work, but the result is different. It is
>> the
>> > same issue. The SQL has no concept of shadowing and on the base line it
>> is
>> > not necessary.
>>
>> The point is that most of users are aware about schemas and search path
>> dangers. But to me such a precedent is not an excuse to introduce a new
>> feature
>> with similar traps, which folks would have to learn by making mistakes.
>> Judging
>> from the feedback to this patch over time, I've got an impression that
>> lots of
>> people are also not fans of that.
>>
>
> Unfortunately - I don't believe so there is some syntax without traps. You
> can check all implementations in other databases. These designs are very
> different, and all have some issues and all have some limits. It is native
> - you are trying to join the procedural and functional world.
>
> I understand the risks. These risks are there. But there is no silver
> bullet - all proposed designs fixed just one case, and not others, and then
> I don't see a strong enough benefit to introduce design that is far from
> common usage. Maybe I have a different experience, because I am a man from
> the stored procedures area, and the risk of collisions is a known issue
> well solved by common conventions and in postgres by
> plpgsql.variable_conflict setting. The proposed patch set has very similar
> functionality. I think the introduction of VARIABLE(xx) syntax and safe
> syntax guard warning the usage of variables can be safe in how it is
> possible. But still I want to allow "short" "usual" usage to people who use
> a safe convention. There is no risk when you use a safe prefix or safe
> schema.
>
>
>
>>
>> > > Then dropping the column b, but everything still works beause the
>> > > variable b got silently picked up. But if it would be required to say
>> > > VARIABLE(b), then all fine.
>> > >
>> >
>> > In this scenario you will get a warning related to variable shadowing
>> > (before you drop a column).
>> >
>> > [...]
>> >
>> > What do you think about the following design? I can implement a warning
>> > "variable_usage_guard" when the variable is accessed without using
>> > VARIABLE() syntax. We can discuss later if this warning can be enabled
>> by
>> > default or not. There I am open to any variant.
>>
>> I don't follow what are you winning by that? In the context of problem
>> above
>> (i.e. dropping a column), such a warning is functionally equivalend to a
>> warning about shadowing.
>>
>> The problem is that it doesn't sound very appealing to have a feature,
>> which
>> requires some extra efforts to be used in a right way (e.g. put
>> everything into
>> a special vars schema, or keep an eye on logs). Most certainly there are
>> such
>> bits in PostgreSQL today, with all the best practices, crowd wisdom, etc.
>> But
>> the bar for new features in this sense is much higher, you can see it
>> from the
>> feedback to this patch. Thus I believe it makes sense, from purely
>> tactical
>> reasons, to not try to convince half of the community to lower the bar,
>> but
>> instead try to modify the feature to make it more acceptable, even if some
>> parts you might not like.
>>
>> Btw, could you repeat, what was exactly your argument against mandatory
>> VARIABLE() syntax? It's somehow scattered across many replies, would be
>> great
>> to summarize it in a couple of phrases.
>>
>> > Shadowing by self is not an issue, probably, but it is a signal of code
>> > quality problems.
>>
>> Agree, but I'm afraid code quality of an average application using
>> PostgreSQL
>> is quite low, so here we are.
>>
>> As a side note, I've recently caught myself thinking "it would be cool to
>> have
>> session variables here". The use case was preparing a policy for RLS,
>> based on
>> some session-level data set by an application. This session-level data is
>> of a
>> composite data type, so simple current_setting is cumbersome to use, and a
>> temporary table will be dropped at the end, taking the policy with it due
>> to
>> the recorded dependency between them. Thus a session variable of some
>> composite
>> type sounds like a good fit.
>>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Wolfgang Walther <walther(at)technowledgy(dot)de>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-17 04:53:17
Message-ID: CAFj8pRCb-vvO6_HJy_Kx7gE4NEiq6w_PAHng2zuGUs6SyjD4UQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

so 16. 11. 2024 v 23:07 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> so 16. 11. 2024 v 18:13 odesílatel Wolfgang Walther <
> walther(at)technowledgy(dot)de> napsal:
>
>> Pavel Stehule:
>> > (global (temp)) table can hold 0, 1 or more rows (and rows are always
>> > composite of 0..n fields). The variable holds a value of some type.
>> > Proposed session variables are like plpgsql variables (only with
>> > different scope). In Postgres there is a difference between a scalar
>> > variable and composite variable with one field.
>>
>> I can store composite values in table columns, too. A table column can
>> either be scalar or composite in that sense.
>>
>> So, maybe rephrase: Single-row, single-column (global (temp)) table =
>> variable. One "cell" of that table.
>>
>
> the tables are tables and variables are variables. For tables you have
> INSERT, UPDATE, DELETE commands, for variables you have a LET command.
>
> and scalar is not a single column composite.
>

example

assignment to scalar versus single composite

LET a = 10
LET a.a = 10 or LET a = ROW(10)

Single column tables can be the result of some ALTERS - or sometimes you
can use a table type. But for example, plpgsql, very strongly differs
between scalar and composite variables. So introducing the "new" concept -
single field composite is scalar introduces strong inconsistency there.

Regards

Pavel

>
> The session variables can in some particular use cases replace global temp
> tables, but this is not the goal. I would like to see global temp tables in
> Postgres too. Maybe session variables prepare a field for this, because
> some people better understand global temp objects. But again my proposal is
> not related to global temp tables. This is a different feature.
>
>
>>
>> For me, the major difference between a variable and a table is, that the
>> table has 0...n rows and 0...m columns, while the variable has *exactly*
>> one in both cases, not 0 either.
>>
>> I must put tables into FROM, why not those nice mini-tables called
>> variables as well? Because they are potentially scalar, you say!
>>
>> But: I can already put functions returning scalar values into FROM:
>>
>> SELECT * FROM format('hello');
>>
>> The function returns a plain string only.
>>
>> I don't know. This just "fits" for me.
>>
>
> There are more issues - one - when you use some composite in FROM clause,
> then you expect an unpacked result. But there are a lot of uses, when
> unpackaging is not wanted. There is a syntax for this but it is really not
> intuitive and not well readable.
>
>
>>
>> Or to put it differently: I don't really care whether I have to write
>> "(SELECT variable FROM variable)" instead of just "variable". I don't
>> want session variables for the syntax, I want session variables, because
>> they are **so much better** than custom GUCs.
>>
>
> session variables are better than GUC for the proposed purpose. But it
> should look like variables. The software should respect standards or common
> typical usage when it is possible. If we introduce fully proprietary
> design, then it will be hell for all people who know any other databases.
> And I don't see a strong benefit from this syntax. It solves just one case,
> it doesn't solve other possible issues, and it introduces another possible
> risk.
>
> Regards
>
> Pavel
>
>
>> Best,
>>
>> Wolfgang
>>
>>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-19 19:14:01
Message-ID: CAFj8pRB_E1GM_YGT-ti4bXka6mhLdAAFeTe+BHgHFYC+qb-76g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I wrote POC of VARIABLE(varname) syntax support

here is a copy from regress test

SET session_variables_ambiguity_warning TO on;
SET session_variables_use_fence_warning_guard TO on;
SET search_path TO 'public';
CREATE VARIABLE a AS int;
LET a = 10;
CREATE TABLE test_table(a int, b int);
INSERT INTO test_table VALUES(20, 20);
-- no warning
SELECT a;
a..
----
10
(1 row)

-- warning variable is shadowed
SELECT a, b FROM test_table;
WARNING: session variable "a" is shadowed
LINE 1: SELECT a, b FROM test_table;
^
DETAIL: Session variables can be shadowed by columns, routine's variables
and routine's arguments with the same name.
a | b..
----+----
20 | 20
(1 row)

-- no warning
SELECT variable(a) FROM test_table;
a..
----
10
(1 row)

ALTER TABLE test_table DROP COLUMN a;
-- warning - variable fence is not used
SELECT a, b FROM test_table;
WARNING: session variable "a" is not used inside variable fence
LINE 1: SELECT a, b FROM test_table;
^
DETAIL: The collision of session variable' names and column names is
possible.
a | b..
----+----
10 | 20
(1 row)

-- no warning
SELECT variable(a), b FROM test_table;
a | b..
----+----
10 | 20
(1 row)

DROP VARIABLE a;
DROP TABLE test_table;
SET session_variables_ambiguity_warning TO DEFAULT;
SET session_variables_use_fence_warning_guard TO DEFAULT;
SET search_path TO DEFAULT;

Regards

Pavel

Attachment Content-Type Size
0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
0019-transactional-variables.patch text/x-patch 39.2 KB
0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
0021-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 14.7 KB
0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
0010-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
0006-plpgsql-tests.patch text/x-patch 16.9 KB
0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-19 21:30:00
Message-ID: CAFj8pRDy4jhPE8K+Y_0xHqCjWnG65byF+CQFg6Tk+9MwgHYsAw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

testing farms reports some issue related to introduction new parser node. I
increased verbosity

Regards

Pavel

Attachment Content-Type Size
v20241119-2-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241119-2-0021-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 14.7 KB
v20241119-2-0022-set-verbosity-mode-in-regress-tests.patch text/x-patch 1.4 KB
v20241119-2-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241119-2-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241119-2-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241119-2-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241119-2-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241119-2-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241119-2-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241119-2-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241119-2-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241119-2-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241119-2-0010-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
v20241119-2-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241119-2-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241119-2-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241119-2-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
v20241119-2-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241119-2-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241119-2-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241119-2-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-20 07:25:53
Message-ID: CAFj8pRA_JetqEqFcZMxhOTBVCHWbvftNipv25OZjhhbe8k4_sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix missing support for VariableFence in raw_expression_tree_walker_impl

Regards

Pavel

Attachment Content-Type Size
v20241120-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241120-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241120-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241120-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241120-0021-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 15.5 KB
v20241120-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241120-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241120-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241120-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241120-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241120-0010-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
v20241120-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241120-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241120-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241120-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241120-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
v20241120-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241120-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241120-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241120-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241120-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-20 13:29:10
Message-ID: CAB-JLwZfrsXZVOVVANieoPixKVRc_4HORVbkCPoSOLJe4DNXLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Em ter., 19 de nov. de 2024 às 16:15, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
escreveu:

> I wrote POC of VARIABLE(varname) syntax support
>

Not related with POC of VARIABLE but seeing your patches ...

Wouldn't it be better to use just one syntax and message for what to do ON
COMMIT ?

When creating a new variable you use
CREATE VARIABLE ... ON COMMIT DROP | ON TRANSACTION END RESET

On PSQL \dV+ you show
Transactional end action

Maybe all them could be just ON COMMIT
CREATE VARIABLE ... [ON COMMIT {NO ACTION, DROP, RESET}] and \dV+ just "on
commit" on title column

regards
Marcos


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-20 13:52:16
Message-ID: CAFj8pRCaFzRKWx3y64RQzw1-Jb8g4-LPu3b5byH9=us5JTRGgg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

st 20. 11. 2024 v 14:29 odesílatel Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
napsal:

> Em ter., 19 de nov. de 2024 às 16:15, Pavel Stehule <
> pavel(dot)stehule(at)gmail(dot)com> escreveu:
>
>> I wrote POC of VARIABLE(varname) syntax support
>>
>
> Not related with POC of VARIABLE but seeing your patches ...
>
> Wouldn't it be better to use just one syntax and message for what to do ON
> COMMIT ?
>
> When creating a new variable you use
> CREATE VARIABLE ... ON COMMIT DROP | ON TRANSACTION END RESET
>
> On PSQL \dV+ you show
> Transactional end action
>
> Maybe all them could be just ON COMMIT
> CREATE VARIABLE ... [ON COMMIT {NO ACTION, DROP, RESET}] and \dV+ just "on
> commit" on title column
>

ON COMMIT DROP is related to temporary objects. In this case, you don't
need to think about ROLLBACK, because in this case, the temp objects are
removed implicitly.

ON TRANSACTION END RESET can be used for non temporary objects too. So this
is a little bit of a different feature. But the reset is executed if the
transaction is ended by ROLLBACK too. So using a syntax just ON COMMIT can
be a little bit messy. TRANSACTION END is more intuitive, I think. If I
remember there was a proposal ON COMMIT OR ROLLBACK, but I think
TRANSACTION END is better and more intuitive, and better describes what is
implemented. I can imagine to support clauses ON COMMIT RESET or ON
ROLLBACK RESET that can be used independently, but for this time, I don't
want to increase a complexity now - reset is just at transaction end
without dependency if the transaction was committed or rollbacked.

Regards

Pavel

> regards
> Marcos
>


From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-20 14:14:55
Message-ID: CAB-JLwYMw1pORoZxA9XeR52Svps6ah=ATgRDHdGQBT+j+Uy7qQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Em qua., 20 de nov. de 2024 às 10:52, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
escreveu:

> COMMIT can be a little bit messy. TRANSACTION END is more intuitive, I
> think.
>
>>
Exactly to be not messy I would just ON COMMIT for all, and DOCs can
explain that this option is ignored for temp objects and do the same at the
end of transaction, independently if commited or rolled back


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-20 14:57:23
Message-ID: CAFj8pRAhYzyJX=3==si+195Bu6DGLLKGjZthe9LnmsekAGjyaA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 20. 11. 2024 v 15:15 odesílatel Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
napsal:

> Em qua., 20 de nov. de 2024 às 10:52, Pavel Stehule <
> pavel(dot)stehule(at)gmail(dot)com> escreveu:
>
>> COMMIT can be a little bit messy. TRANSACTION END is more intuitive, I
>> think.
>>
>>>
> Exactly to be not messy I would just ON COMMIT for all, and DOCs can
> explain that this option is ignored for temp objects and do the same at the
> end of transaction, independently if commited or rolled back
>

I feel it differently - when I read ON COMMIT, then I expect really just a
COMMIT event, not ROLLBACK. Attention - the metadata about variables are
transactional, but the variables are not transactional (by default).

But this feeling can be subjective. The objective argument against using ON
COMMIT like ON TRANSACTION END is fact, so we lost a possibility for a more
precious setting.

I can imagine scenarios with ON COMMIT RESET - and variable can hold some
last value from transaction, or ON ROLLBACK RESET - and variable can hold
some computed value from successfully ended transaction - last inserted id.

In this case, I don't see a problem to reopen a discussion about syntax or
postpone this feature. I think the possibility to reset variables at some
specified time can be an interesting feature (that can increase safety,
because the application doesn't need to solve initial setup), but from the
list of implemented features for session variables, this is not too far
from the end. If TRANSACTION END is not intuitive - with exactly the same
functionality can be RESET AT TRANSACTION START - so the ON TRANSACTION END
can be transformed to ON BEGIN RESET, and this syntax can be maybe better,
because it signalize, for every transaction, the variable will be
initialized to default. What do you think? Can be ON BEGIN RESET acceptable
for you.

Regards

Pavel


From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-20 20:13:13
Message-ID: 20241120201313.t4wbhld4ktgielaf@erthalion.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> On Tue, Nov 19, 2024 at 08:14:01PM +0100, Pavel Stehule wrote:
> Hi
>
> I wrote POC of VARIABLE(varname) syntax support

Thanks, the results look good. I'm still opposed the idea of having a
warning, and think it has to be an error -- but it's my subjective
opinion. Lets see if there are more votes on that topic.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-21 04:07:09
Message-ID: CAFj8pRDDTfQdE9kZjRvLSAVtd1jfEKFoUG+U9XQEFjhM4yz9EA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 20. 11. 2024 v 21:14 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Tue, Nov 19, 2024 at 08:14:01PM +0100, Pavel Stehule wrote:
> > Hi
> >
> > I wrote POC of VARIABLE(varname) syntax support
>
> Thanks, the results look good. I'm still opposed the idea of having a
> warning, and think it has to be an error -- but it's my subjective
> opinion. Lets see if there are more votes on that topic.
>

The error breaks the possibility to use variables (session variables) like
Oracle's package variables easily. It increases effort for transformation
or porting because you should identify variables inside queries and you
should wrap it to fence. On the other hand, extensions that can read a
query after transformation can easily detect unwrapped variables and they
can raise an error. It can be very easy to implement this check to
plpgsql_check for example or like plpgsql.extra_check.

In my ideal world, the shadowing warning should be enabled by default, and
an unfencing warning disabled by default. But I have not a problem with
activating both warnings by default. I think warnings are enough, because
if there is some risk then a shadowing warning is activated. And my
experience is more positive about warnings, people read it.

Regards

Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-26 06:21:49
Message-ID: CAFj8pRCJ1_XZZAWGuFdPjFGf2WgPSbH8LLoFDOTnO4_9Z9o_Ww@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix after 96a81c1

Regards

Pavel

Attachment Content-Type Size
v20241126-0020-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241126-0021-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 15.5 KB
v20241126-0017-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241126-0019-transactional-variables.patch text/x-patch 39.2 KB
v20241126-0018-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241126-0016-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241126-0014-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241126-0015-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241126-0013-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241126-0012-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241126-0011-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241126-0010-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
v20241126-0009-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241126-0008-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241126-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 13.9 KB
v20241126-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241126-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241126-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241126-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
v20241126-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241126-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-11-27 18:14:12
Message-ID: CAFj8pRA00BYE25sE9DwrLcsDn6OY5E=FXNSRMCOF34Y=AuP6cw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase + doc for variable fence + move variable fence patch after
GUC-session_variables_ambiguity_warning

Regards

Pavel

Attachment Content-Type Size
v20241127-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241127-0020-transactional-variables.patch text/x-patch 39.2 KB
v20241127-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241127-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241127-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241127-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241127-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241127-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241127-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241127-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241127-0011-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
v20241127-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241127-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20241127-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241127-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.3 KB
v20241127-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241127-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
v20241127-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241127-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241127-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241127-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-05 06:51:24
Message-ID: CAFj8pRAGAQf0+0cVVRmUJpwyATtBP1YCRU0SxtVQNg+yT=Ongw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

only rebase

Regards

Pavel

Attachment Content-Type Size
v20241205-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241205-0020-transactional-variables.patch text/x-patch 39.2 KB
v20241205-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241205-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20241205-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.2 KB
v20241205-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241205-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241205-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241205-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241205-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241205-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241205-0011-implementation-of-temporary-session-variables.patch text/x-patch 42.2 KB
v20241205-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20241205-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.3 KB
v20241205-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241205-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.8 KB
v20241205-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241205-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241205-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241205-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.1 KB
v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 129.9 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-07 02:13:26
Message-ID: CACJufxHx3FyO4jkv24W9Q_e5weSSy2Nv1Ue437nWU2MQsgu3RA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Thu, Dec 5, 2024 at 2:52 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> Hi
>
> only rebase

hi.
disclaimer, i *only* applied
v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch.

create variable v2 as text;
alter variable v2 rename to v2;
ERROR: session variable "v2" already exists in schema "public"

the above is coverage tests for report_namespace_conflict:
case VariableRelationId:
Assert(OidIsValid(nspOid));
msgfmt = gettext_noop("session variable \"%s\" already
exists in schema \"%s\"");
break;

create type t1 as (a int, b int);
CREATE VARIABLE var1 AS t1;
alter type t1 drop attribute a;
should "alter type t1 drop attribute a;" not allowed?

GetCommandLogLevel also needs to deal with case T_CreateSessionVarStmt?

there are no regress tests for the change we made in
find_composite_type_dependencies?
It looks like it will be reachable for sure.

CreateVariable, print out error position:
if (get_typtype(typid) == TYPTYPE_PSEUDO)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("session variable cannot be pseudo-type %s",
format_type_be(typid)),
parser_errposition(pstate, stmt->typeName->location)));

Alvaro Herrera told me actually, you don't need the extra parentheses
around errcode.
so you can:
if (get_typtype(typid) == TYPTYPE_PSEUDO)
ereport(ERROR,
errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("session variable cannot be pseudo-type %s",
format_type_be(typid)),
parser_errposition(pstate, stmt->typeName->location))

pg_variable_is_visible seems to have done twice the system cache call.
maybe follow through with the pg_table_is_visible, pg_type_is_visible
code pattern.

IN src/bin/psql/describe.c
+ appendPQExpBufferStr(&buf, "\nWHERE true\n");
this is not needed?
------------------------------------------------
some of the `foreach` can change to foreach_oid, foreach_node
see: https://git.postgresql.org/cgit/postgresql.git/commit/?id=14dd0f27d7cd56ffae9ecdbe324965073d01a9ff
------------------------------------------------
doc/src/sgml/ref/create_variable.sgml
<programlisting>
CREATE VARIABLE var1 AS date;
LET var1 = current_date;
SELECT var1;
</programlisting>

v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch
alone cannot do `LET var1 = current_date;`, `SELECT var1;`
maybe the following patch can do it. but that makes
we cannot commit
v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch
alone.
------------------------------------------------
since CREATE VARIABLE is an extension to standard, so in create_schema.sgml
Compatibility section,
do we need to mention CREATE SCHEMA CREATE VARIABLE is an extension
from standard
?
-----------------------------------------------

/*
* Drop variable by OID, and register the needed session variable
* cleanup.
*/
void
DropVariableById(Oid varid)
i am not sure of the meaning of "register the needed session variable cleanup".


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-08 18:32:40
Message-ID: CAFj8pRByN-He41pSh0nRj4swQEPiRZ1aQ6TcFEqyCV_FZXZukg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

so 7. 12. 2024 v 3:13 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> On Thu, Dec 5, 2024 at 2:52 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> >
> > Hi
> >
> > only rebase
>
> hi.
> disclaimer, i *only* applied
> v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch.
>
> create variable v2 as text;
> alter variable v2 rename to v2;
> ERROR: session variable "v2" already exists in schema "public"
>
> the above is coverage tests for report_namespace_conflict:
> case VariableRelationId:
> Assert(OidIsValid(nspOid));
> msgfmt = gettext_noop("session variable \"%s\" already
> exists in schema \"%s\"");
> break;
>

I don't understand what is an issue?

This is consistent with other database object

(2024-12-07 18:25:29) postgres=# create table foo(a int);
CREATE TABLE
(2024-12-07 18:25:35) postgres=# alter table foo rename
a COLUMN CONSTRAINT TO
(2024-12-07 18:25:35) postgres=# alter table foo rename to foo;
ERROR: relation "foo" already exists

>
> create type t1 as (a int, b int);
> CREATE VARIABLE var1 AS t1;
> alter type t1 drop attribute a;
> should "alter type t1 drop attribute a;" not allowed?
>

you can add a new attribute, or you can drop the attribute. You cannot
change the type of the attribute.

>
> GetCommandLogLevel also needs to deal with case T_CreateSessionVarStmt?
>

yes - it should be there - I fixed this + regress test

>
> there are no regress tests for the change we made in
> find_composite_type_dependencies?
> It looks like it will be reachable for sure.
>

It was tested in patch02, where the correct work with variable's values.

But I wrote few tests, that better describe this functionality and I added
to patch01

+SET log_statement TO ddl;
-- should be ok
CREATE VARIABLE var1 AS int;
-- should fail, pseudotypes are not allowed
@@ -15,6 +16,36 @@ CREATE VARIABLE var1 AS int;
ERROR: session variable "var1" already exists
-- should be ok
DROP VARIABLE IF EXISTS var1;
+-- the variable can use composite types
+CREATE TABLE t1 (a int, b int);
+CREATE VARIABLE var1 AS t1;
+-- should fail
+DROP TABLE t1;
+ERROR: cannot drop table t1 because other objects depend on it
+DETAIL: session variable var1 depends on type t1
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+-- should be ok
+ALTER TABLE t1 ADD COLUMN c int;
+-- should fail
+ALTER TABLE t1 ALTER COLUMN b TYPE numeric;
+ERROR: cannot alter table "t1" because session variable "public.var1"
uses it
+DROP VARIABLE var1;
+DROP TABLE t1;
+CREATE TYPE t1 AS (a int, b int);
+CREATE VARIABLE var1 AS t1;
+-- should fail
+DROP TYPE t1;
+ERROR: cannot drop type t1 because other objects depend on it
+DETAIL: session variable var1 depends on type t1
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+-- should be ok
+ALTER TYPE t1 ADD ATTRIBUTE c int;
+-- should fail
+ALTER TYPE t1 ALTER ATTRIBUTE b TYPE numeric;
+ERROR: cannot alter type "t1" because session variable "public.var1" uses
it
+DROP VARIABLE var1;
+DROP TYPE t1;
+SET log_statement TO default;

>
>
> CreateVariable, print out error position:
> if (get_typtype(typid) == TYPTYPE_PSEUDO)
> ereport(ERROR,
> (errcode(ERRCODE_WRONG_OBJECT_TYPE),
> errmsg("session variable cannot be pseudo-type %s",
> format_type_be(typid)),
> parser_errposition(pstate, stmt->typeName->location)));
>
> Alvaro Herrera told me actually, you don't need the extra parentheses
> around errcode.
> so you can:
> if (get_typtype(typid) == TYPTYPE_PSEUDO)
> ereport(ERROR,
> errcode(ERRCODE_WRONG_OBJECT_TYPE),
> errmsg("session variable cannot be pseudo-type %s",
> format_type_be(typid)),
> parser_errposition(pstate, stmt->typeName->location))
>

yes, it is not necessary, but it is used almost everywhere in Postgres
source code. So I prefer
to be consistent with usual ereport notation. It can be fixed later, but it
is used 7136 times in pg code.
Probably this needs a wide discussion. Without extra parenthesis the code
looks little bit nicer,
but this should be changed by a dedicated patch everywhere.

>
> pg_variable_is_visible seems to have done twice the system cache call.
> maybe follow through with the pg_table_is_visible, pg_type_is_visible
> code pattern.
>
>
done

>
> IN src/bin/psql/describe.c
> + appendPQExpBufferStr(&buf, "\nWHERE true\n");
> this is not needed?
>

Yes, it is a little bit messy, but it is necessary due to the usage of a
ValidateSQLNamePattern - it uses the "AND" operator, and
then there should be some expression before. I think that in this way, the
code is most simple. For objects based on
pg_class table is common usage "\nWHERE prokind = \"x\"\n" with the next
enhancement of filtering. But for variables
There is nothing like filtering inside the table pg_variable, so "WHERE
true\n" is the best analogy. See listConversions()

------------------------------------------------
> some of the `foreach` can change to foreach_oid, foreach_node
> see:
> https://git.postgresql.org/cgit/postgresql.git/commit/?id=14dd0f27d7cd56ffae9ecdbe324965073d01a9ff

done

>
> ------------------------------------------------
> doc/src/sgml/ref/create_variable.sgml
> <programlisting>
> CREATE VARIABLE var1 AS date;
> LET var1 = current_date;
> SELECT var1;
> </programlisting>
>
> v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch
> alone cannot do `LET var1 = current_date;`, `SELECT var1;`
> maybe the following patch can do it. but that makes
> we cannot commit
> v20241205-0001-Enhancing-catalog-for-support-session-variables-and-.patch
> alone.
>

moved.

The patches 01 and 02 should be committed together to carry some valuable
functionality.

> ------------------------------------------------
> since CREATE VARIABLE is an extension to standard, so in create_schema.sgml
> Compatibility section,
> do we need to mention CREATE SCHEMA CREATE VARIABLE is an extension
> from standard
> ?
>

done

> -----------------------------------------------
>
> /*
> * Drop variable by OID, and register the needed session variable
> * cleanup.
> */
> void
> DropVariableById(Oid varid)
> i am not sure of the meaning of "register the needed session variable
> cleanup".
>

Without context it is messy. It is related to functionality introduced in
patch [PATCH 05/21] memory cleaning after DROP VARIABLE

So I moved text ", and register the needed session variable
* cleanup." there

Thank you very much for review

updated patchset attached

Regards

Pavel

Attachment Content-Type Size
v20241208-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241208-0020-transactional-variables.patch text/x-patch 39.1 KB
v20241208-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.1 KB
v20241208-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241208-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241208-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241208-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241208-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241208-0010-PREPARE-LET-support.patch text/x-patch 7.3 KB
v20241208-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241208-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241208-0011-implementation-of-temporary-session-variables.patch text/x-patch 42.1 KB
v20241208-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241208-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20241208-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.3 KB
v20241208-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241208-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241208-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.2 KB
v20241208-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241208-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 132.7 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-09 06:16:04
Message-ID: CACJufxHCZ1pidPKAqB_-wpA+Dqa2_n-LJQMwoCsHRQE-xZ_v2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Mon, Dec 9, 2024 at 2:33 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> Hi
>
again. only applied
v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch.

/* we want SessionVariableCreatePostprocess to see the catalog changes. */
0001 doesn't have SessionVariableCreatePostprocess,
so this comment is wrong in the context of 0001.

typo:
As above, but if the variable isn't found and is_mussing is not NULL
is_mussing should be is_missing.

----------------------------------------------
issue with grant.sgml and revoke.sgml.

* there are no regress tests for WITH GRANT OPTION but it seems to work;
there are no REVOKE CASCADE tests. the following tests show
REVOKE CASCADE works.

create variable v1 as int;
GRANT select on VARIABLE v1 to alice with grant option;
set session authorization alice;
GRANT select on VARIABLE v1 to bob with grant option;
reset session authorization;

select varacl from pg_variable where varname = 'v1';
--output
{jian=rw/jian,alice=r*/jian,bob=r*/alice}
revoke all privileges on variable v1 from alice cascade;
select varacl from pg_variable where varname = 'v1';
--output
{jian=rw/jian}

revoke GRANT OPTION FOR all privileges on variable v1 from alice cascade;
also works.

* in revoke.sgml and grant.sgml.
if you look closely, " | ALL VARIABLES IN SCHEMA schema_name [, ...] }" is wrong
because there is no left-curly-bracket, but there is a right-curly-bracket.

* in revoke.sgml.
<phrase>where <replaceable
class="parameter">role_specification</replaceable> can be:</phrase>
[ GROUP ] <replaceable class="parameter">role_name</replaceable>
| PUBLIC
| CURRENT_ROLE
| CURRENT_USER
| SESSION_USER
should be at the end of the synopsis section?
otherwise it looks weird, maybe we can put the REVOKE VARIABLE code upper.
grant.sgml changes position looks fine to me.

* <para>
The <command>GRANT</command> command has two basic variants: one
that grants privileges on a database object (table, column, view,
foreign table, sequence, database, foreign-data wrapper, foreign server,
function, procedure, procedural language, large object, configuration
parameter, schema, tablespace, or type), and one that grants
membership in a role. These variants are similar in many ways, but
they are different enough to be described separately.
</para>
this <para> in grant.sgml needs to also mention "variable"?

* <para>
Privileges on databases, tablespaces, schemas, languages, and
configuration parameters are
<productname>PostgreSQL</productname> extensions.
</para>
this <para> in grant.sgml needs to also mention "variable"?

----------------------------------------------
*
+ <para>
+ Inside a query or an expression, a session variable can be
+ <quote>shadowed</quote> by a column with the same name. Similarly, the
+ name of a function or procedure argument or a PL/pgSQL variable (see
PL/pgSQL should decorated as <application>PL/pgSQL</application>

* we already support \dV and \dV+ in
v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch
so we should update doc/src/sgml/ref/psql-ref.sgml also.
I briefly searched \dV in
v20241208-0002-Storage-for-session-variables-and-SQL-interface.patch,
no entry.

* in doc/src/sgml/ddl.sgml
<table id="privilege-abbrevs-table"> and <table
id="privileges-summary-table"> need to change for variable?
<varlistentry id="ddl-priv-select">, <varlistentry
id="ddl-priv-update"> need to change for variable?

it's kind of tricky. if we only apply
v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch
we can not SELECT or UPDATE variable.
so how are we going to mention these privileges for variable?

* we can add some tests for EVENT TRIGGER test,
since event trigger support CREATE|DROP variable. atually, I think
there is a bug.

create variable v1 as int;
CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
RETURNS event_trigger
LANGUAGE plpgsql
AS $$
DECLARE r record;
BEGIN
FOR r IN SELECT * from pg_event_trigger_dropped_objects()
LOOP
IF NOT r.normal AND NOT r.original THEN
CONTINUE;
END IF;
RAISE NOTICE 'NORMAL: orig=% normal=% istemp=% type=% identity=% name=% args=%',
r.original, r.normal, r.is_temporary, r.object_type,
r.object_identity, r.address_names, r.address_args;
END LOOP;
END; $$;

CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
WHEN TAG IN ('DROP VARIABLE')
EXECUTE PROCEDURE event_trigger_report_dropped();

--output:
src9=# drop variable v1;
NOTICE: test_event_trigger: ddl_command_start DROP VARIABLE
NOTICE: NORMAL: orig=t normal=f istemp=f type=session variable
identity=public.v1 name={public,$} args={}
DROP VARIABLE

should i expect
NOTICE: NORMAL: orig=t normal=f istemp=f type=session variable
identity=public.v1 name={public,$} args={}
to be
NOTICE: NORMAL: orig=t normal=f istemp=f type=session variable
identity=public.v1 name={public,v1} args={}
?


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-09 16:54:26
Message-ID: CAFj8pRBWqEb8i6WmrF_Xh64=48GtisKijgczMv7HTTpe4GswuA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

st 20. 11. 2024 v 21:14 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
napsal:

> > On Tue, Nov 19, 2024 at 08:14:01PM +0100, Pavel Stehule wrote:
> > Hi
> >
> > I wrote POC of VARIABLE(varname) syntax support
>
> Thanks, the results look good. I'm still opposed the idea of having a
> warning, and think it has to be an error -- but it's my subjective
> opinion. Lets see if there are more votes on that topic.
>

Maybe the warning of usage of unfenced variables can be changed (enhanced)
to some different mechanism that can be more restrictive (and safer), but I
think it can still be user friendly.

My idea is based on assumption so users with knowledge of stored procedures
know variables and related risks (and know tools how to minimize risks),
and for other people the risk is higher and we should force usage of
variable fences. I think we can force usage of variable fences at query
runtime, when query is not executed from the SPI environment. This
behaviour can be enabled by default, but can be optionally disabled.

CREATE VARIABLE s.x AS int; -- allowed when user has create right on schema
s
CREATE VIEW v1 AS SELECT x; -- no problem, the check is dynamic
(execution), not static
CREATE VIEW v2 AS SELECT VARIABLE(x); -- no problem

SELECT x; -- fails on access to unfenced variable
SELECT * FROM v1; -- fails on access to unfenced variable
SELECT * FROM v2; -- ok

but inside pl, this check will not be active, and then with default setting
I can write an code like

LET var = 10; -- fencing is not allowed there, and there is not any
collision
DO $$
BEGIN
RAISE NOTICE 'var=%', var;
RAISE NOTICE 'var=%', (SELECT * FROM v1); --is ok here too
END;
$$;

Outside PL the fencing can be required, inside PL the fencing can be
optional. With this proposal we can limit the possible risk usage of
unfenced variables only in PL context, and the behaviour can be very
similar to PL/SQL or SQL/PSM. This check is only a runtime check, so it has
no impact on any DDL statement. It doesn't change the syntax or behavior,
so it can be implemented subsequently - it is just a safeguard against
unwanted usage of variables in an environment, where users have no
possibility to use variables already. I can imagine that this check
"allow_unfenced_variables" can have three values (everywhere, pl, nowhere)
and the default can be pl. The results of queries don't depend on the
current setting of this check. For all values for all possible queries and
situations, the result is the same (when it is finished). But sometimes,
the check can break the execution - in similar meaning like access rights.
All previous proposed warnings can be unchanged.

Comments, notes?

Regards

Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-09 23:20:38
Message-ID: CAFj8pRD-rAnvDuuD6NYR3Zt5b3r6MEvhq1Qzs2ouTWtg4brwXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

po 9. 12. 2024 v 7:16 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> On Mon, Dec 9, 2024 at 2:33 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> >
> > Hi
> >
> again. only applied
> v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch.
>
> /* we want SessionVariableCreatePostprocess to see the catalog changes. */
> 0001 doesn't have SessionVariableCreatePostprocess,
> so this comment is wrong in the context of 0001.
>

moved to patch 11

>
> typo:
> As above, but if the variable isn't found and is_mussing is not NULL
> is_mussing should be is_missing.
>
>
fixed

> ----------------------------------------------
> issue with grant.sgml and revoke.sgml.
>
> * there are no regress tests for WITH GRANT OPTION but it seems to work;
> there are no REVOKE CASCADE tests. the following tests show
> REVOKE CASCADE works.
>
> create variable v1 as int;
> GRANT select on VARIABLE v1 to alice with grant option;
> set session authorization alice;
> GRANT select on VARIABLE v1 to bob with grant option;
> reset session authorization;
>
> select varacl from pg_variable where varname = 'v1';
> --output
> {jian=rw/jian,alice=r*/jian,bob=r*/alice}
> revoke all privileges on variable v1 from alice cascade;
> select varacl from pg_variable where varname = 'v1';
> --output
> {jian=rw/jian}
>
> revoke GRANT OPTION FOR all privileges on variable v1 from alice cascade;
> also works.
>

these features uses generic code, so I didn't wrote regress test, but I
don't see any
reason why don't use your examples in regress tests.

>
> * in revoke.sgml and grant.sgml.
> if you look closely, " | ALL VARIABLES IN SCHEMA schema_name [, ...] }" is
> wrong
> because there is no left-curly-bracket, but there is a right-curly-bracket.
>

fixed

>
> * in revoke.sgml.
> <phrase>where <replaceable
> class="parameter">role_specification</replaceable> can be:</phrase>
> [ GROUP ] <replaceable class="parameter">role_name</replaceable>
> | PUBLIC
> | CURRENT_ROLE
> | CURRENT_USER
> | SESSION_USER
> should be at the end of the synopsis section?
> otherwise it looks weird, maybe we can put the REVOKE VARIABLE code upper.
> grant.sgml changes position looks fine to me.
>

it was wrong, REVOKE VARIABLE should be moved up

fixed

>
>
> * <para>
> The <command>GRANT</command> command has two basic variants: one
> that grants privileges on a database object (table, column, view,
> foreign table, sequence, database, foreign-data wrapper, foreign server,
> function, procedure, procedural language, large object, configuration
> parameter, schema, tablespace, or type), and one that grants
> membership in a role. These variants are similar in many ways, but
> they are different enough to be described separately.
> </para>
> this <para> in grant.sgml needs to also mention "variable"?
>

done

>
> * <para>
> Privileges on databases, tablespaces, schemas, languages, and
> configuration parameters are
> <productname>PostgreSQL</productname> extensions.
> </para>
> this <para> in grant.sgml needs to also mention "variable"?
>
>
done

> * we already support \dV and \dV+ in
> v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch
> so we should update doc/src/sgml/ref/psql-ref.sgml also.
> I briefly searched \dV in
> v20241208-0002-Storage-for-session-variables-and-SQL-interface.patch,
> no entry.
>

done

----------------------------------------------
> *
> + <para>
> + Inside a query or an expression, a session variable can be
> + <quote>shadowed</quote> by a column with the same name. Similarly,
> the
> + name of a function or procedure argument or a PL/pgSQL variable (see
> PL/pgSQL should decorated as <application>PL/pgSQL</application>
>
>
moved this para to patch02

>
>
> * in doc/src/sgml/ddl.sgml
> <table id="privilege-abbrevs-table"> and <table
> id="privileges-summary-table"> need to change for variable?
> <varlistentry id="ddl-priv-select">, <varlistentry
> id="ddl-priv-update"> need to change for variable?
>
> it's kind of tricky. if we only apply
> v20241208-0001-Enhancing-catalog-for-support-session-variables-and-.patch
> we can not SELECT or UPDATE variable.
> so how are we going to mention these privileges for variable?
>

I did it to 01 patch.

The line between 01 and 02 patch can be fuzzy sometimes little bit

Just note: applying only the 01 patch does not make any sense. These
patches (01 and 02) are separated just for review
and testing, but for any usage both patches should be committed or none.

>
> * we can add some tests for EVENT TRIGGER test,
> since event trigger support CREATE|DROP variable. atually, I think
> there is a bug.
>
> create variable v1 as int;
> CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
> RETURNS event_trigger
> LANGUAGE plpgsql
> AS $$
> DECLARE r record;
> BEGIN
> FOR r IN SELECT * from pg_event_trigger_dropped_objects()
> LOOP
> IF NOT r.normal AND NOT r.original THEN
> CONTINUE;
> END IF;
> RAISE NOTICE 'NORMAL: orig=% normal=% istemp=% type=% identity=% name=%
> args=%',
> r.original, r.normal, r.is_temporary, r.object_type,
> r.object_identity, r.address_names, r.address_args;
> END LOOP;
> END; $$;
>
> CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
> WHEN TAG IN ('DROP VARIABLE')
> EXECUTE PROCEDURE event_trigger_report_dropped();
>
> --output:
> src9=# drop variable v1;
> NOTICE: test_event_trigger: ddl_command_start DROP VARIABLE
> NOTICE: NORMAL: orig=t normal=f istemp=f type=session variable
> identity=public.v1 name={public,$} args={}
> DROP VARIABLE
>
> should i expect
> NOTICE: NORMAL: orig=t normal=f istemp=f type=session variable
> identity=public.v1 name={public,$} args={}
> to be
> NOTICE: NORMAL: orig=t normal=f istemp=f type=session variable
> identity=public.v1 name={public,v1} args={}
> ?
>

fixed - there was missing pstrdup(varname) in the related part in
getObjectIdentityParts

I used your example in regress test

new patchset attached with necessary rebase

Regards

Pavel

Attachment Content-Type Size
v20241210-0020-transactional-variables.patch text/x-patch 39.1 KB
v20241210-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241210-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241210-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.1 KB
v20241210-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241210-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241210-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241210-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241210-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241210-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241210-0011-implementation-of-temporary-session-variables.patch text/x-patch 42.1 KB
v20241210-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241210-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241210-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20241210-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241210-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241210-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241210-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241210-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241210-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 146.0 KB
v20241210-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 139.7 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-10 03:32:37
Message-ID: CACJufxEk-FpbUKPigjexmLOb=x__0OMNZL+4k2E=VL=uynrGFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

GRANT|REVOKE ALL VARIABLES IN SCHEMA schema_name [, ...] }
seems to work.
might be better to add tests.

also src/bin/psql/tab-complete.in.c
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_grantables,
we can also add "ALL VARIABLES IN SCHEMA "

also need change this <para> in grant.sgml:
<para>
There is also an option to grant privileges on all objects of the same
type within one or more schemas. This functionality is currently supported
only for tables, sequences, functions, and procedures. <literal>ALL
TABLES</literal> also affects views and foreign tables, just like the
specific-object <command>GRANT</command> command. <literal>ALL
FUNCTIONS</literal> also affects aggregate and window functions, but not
procedures, again just like the specific-object <command>GRANT</command>
command. Use <literal>ALL ROUTINES</literal> to include procedures.
</para>

revoke.sgml, we should use <replaceable
class="parameter">role_specification</replaceable>?
so it will become like:

REVOKE [ GRANT OPTION FOR ]
{ { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
ON { VARIABLE variable_name [, ...]
| ALL VARIABLES IN SCHEMA schema_name [, ...] }
FROM role_specification [, ...]

maybe also add
[ GRANTED BY role_specification ]
but I didn't test "REVOKE [ GRANTED BY role_specification ]".

Speaking of acl tests,
similar to has_table_privilege I am afraid we need to have a function
like has_variable_privilege for acl tests.
has_table_privilege has 6 function signatures. so there will be more code.
------------------------------------------------------
doc/src/sgml/ref/create_variable.sgml
<synopsis> section:
CREATE VARIABLE [ IF NOT EXISTS ] name [ AS ] data_type ] [ COLLATE collation ]

redundant right square bracket after "data_type".


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-11 20:51:43
Message-ID: CAFj8pRBVQVGMSGOhEcUPVOO_0+v1q0TcH_H+fExYG=EFvWA4sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

út 10. 12. 2024 v 4:32 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> GRANT|REVOKE ALL VARIABLES IN SCHEMA schema_name [, ...] }
> seems to work.
> might be better to add tests.
>

done

>
> also src/bin/psql/tab-complete.in.c
> COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_grantables,
> we can also add "ALL VARIABLES IN SCHEMA "
>

done

>
> also need change this <para> in grant.sgml:
> <para>
> There is also an option to grant privileges on all objects of the same
> type within one or more schemas. This functionality is currently
> supported
> only for tables, sequences, functions, and procedures. <literal>ALL
> TABLES</literal> also affects views and foreign tables, just like the
> specific-object <command>GRANT</command> command. <literal>ALL
> FUNCTIONS</literal> also affects aggregate and window functions, but not
> procedures, again just like the specific-object <command>GRANT</command>
> command. Use <literal>ALL ROUTINES</literal> to include procedures.
> </para>
>

done

>
> revoke.sgml, we should use <replaceable
> class="parameter">role_specification</replaceable>?
> so it will become like:
>
> REVOKE [ GRANT OPTION FOR ]
> { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
> ON { VARIABLE variable_name [, ...]
> | ALL VARIABLES IN SCHEMA schema_name [, ...] }
> FROM role_specification [, ...]
>

done

>
> maybe also add
> [ GRANTED BY role_specification ]
> but I didn't test "REVOKE [ GRANTED BY role_specification ]".
>

It i working, so I enhanced doc and regress tests

>
> Speaking of acl tests,
> similar to has_table_privilege I am afraid we need to have a function
> like has_variable_privilege for acl tests.
> has_table_privilege has 6 function signatures. so there will be more code.
>

ok, I wrote these functions

> ------------------------------------------------------
> doc/src/sgml/ref/create_variable.sgml
> <synopsis> section:
> CREATE VARIABLE [ IF NOT EXISTS ] name [ AS ] data_type ] [ COLLATE
> collation ]
>
> redundant right square bracket after "data_type".
>

fixed

Regards

Pavel

Attachment Content-Type Size
v20241211-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241211-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241211-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241211-0020-transactional-variables.patch text/x-patch 39.1 KB
v20241211-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.1 KB
v20241211-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241211-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241211-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.3 KB
v20241211-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241211-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241211-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241211-0011-implementation-of-temporary-session-variables.patch text/x-patch 42.1 KB
v20241211-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20241211-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241211-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241211-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241211-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241211-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241211-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241211-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.4 KB
v20241211-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 162.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-14 15:40:42
Message-ID: CAFj8pRAry0esQiHcK=6BwwFKDY0zanug6k07CEQzRPBqZ6iW0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 9. 12. 2024 v 17:54 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

> Hi
>
> st 20. 11. 2024 v 21:14 odesílatel Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> napsal:
>
>> > On Tue, Nov 19, 2024 at 08:14:01PM +0100, Pavel Stehule wrote:
>> > Hi
>> >
>> > I wrote POC of VARIABLE(varname) syntax support
>>
>> Thanks, the results look good. I'm still opposed the idea of having a
>> warning, and think it has to be an error -- but it's my subjective
>> opinion. Lets see if there are more votes on that topic.
>>
>
> Maybe the warning of usage of unfenced variables can be changed (enhanced)
> to some different mechanism that can be more restrictive (and safer), but I
> think it can still be user friendly.
>
> My idea is based on assumption so users with knowledge of stored
> procedures know variables and related risks (and know tools how to
> minimize risks), and for other people the risk is higher and we should
> force usage of variable fences. I think we can force usage of variable
> fences at query runtime, when query is not executed from the SPI
> environment. This behaviour can be enabled by default, but can be
> optionally disabled.
>
> CREATE VARIABLE s.x AS int; -- allowed when user has create right on
> schema s
> CREATE VIEW v1 AS SELECT x; -- no problem, the check is dynamic
> (execution), not static
> CREATE VIEW v2 AS SELECT VARIABLE(x); -- no problem
>
> SELECT x; -- fails on access to unfenced variable
> SELECT * FROM v1; -- fails on access to unfenced variable
> SELECT * FROM v2; -- ok
>
> but inside pl, this check will not be active, and then with default
> setting I can write an code like
>
> LET var = 10; -- fencing is not allowed there, and there is not any
> collision
> DO $$
> BEGIN
> RAISE NOTICE 'var=%', var;
> RAISE NOTICE 'var=%', (SELECT * FROM v1); --is ok here too
> END;
> $$;
>
> Outside PL the fencing can be required, inside PL the fencing can be
> optional. With this proposal we can limit the possible risk usage of
> unfenced variables only in PL context, and the behaviour can be very
> similar to PL/SQL or SQL/PSM. This check is only a runtime check, so it has
> no impact on any DDL statement. It doesn't change the syntax or behavior,
> so it can be implemented subsequently - it is just a safeguard against
> unwanted usage of variables in an environment, where users have no
> possibility to use variables already. I can imagine that this check
> "allow_unfenced_variables" can have three values (everywhere, pl, nowhere)
> and the default can be pl. The results of queries don't depend on the
> current setting of this check. For all values for all possible queries and
> situations, the result is the same (when it is finished). But sometimes,
> the check can break the execution - in similar meaning like access rights.
> All previous proposed warnings can be unchanged.
>
>
here is a implementation with dynamic variable fence usage guard (depends
on context)

(2024-12-14 16:34:13) postgres=# set
session_variables_use_fence_context_guard to nospi ;
SET
(2024-12-14 16:34:25) postgres=# create variable xx as int;
CREATE VARIABLE
(2024-12-14 16:34:32) postgres=# select xx;
ERROR: session variable "public.xx" is not used inside variable fence
DETAIL: There is a risk of unwanted usage of session variable.
HINT: Use variable fence "VARIABLE(varname) for access to variable".
(2024-12-14 16:34:38) postgres=# let xx = 20;
LET
(2024-12-14 16:34:42) postgres=# select variable(xx);
┌────┐
│ xx │
╞════╡
│ 20 │
└────┘
(1 row)

(2024-12-14 16:34:48) postgres=# do $$
postgres$# begin
postgres$# raise notice '%', xx;
postgres$# end;
postgres$# $$;
NOTICE: 20
DO

Regards

Pavel

> Comments, notes?
>
> Regards
>
> Pavel
>
>
>
>
>

Attachment Content-Type Size
v20241214-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241214-0021-transactional-variables.patch text/x-patch 39.2 KB
v20241214-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241214-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241214-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.1 KB
v20241214-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241214-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241214-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.8 KB
v20241214-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241214-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241214-0012-implementation-of-temporary-session-variables.patch text/x-patch 42.0 KB
v20241214-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241214-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20241214-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241214-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241214-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241214-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241214-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241214-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241214-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241214-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.4 KB
v20241214-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 162.6 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-18 03:00:01
Message-ID: CACJufxFNjKrmyEi9SLfPCq4c9GUN+5eoOtbZwBPq9eKoO8REUw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

/*
* has_session_variable_privilege variants
* These are all named "has_session_variable_privilege" at the SQL level.
* They take various combinations of variable name, variable OID,
* user name, user OID, or implicit user = current_user.
*
* The result is a boolean value: true if user has the indicated
* privilege, false if not. The variants that take a relation OID
* return NULL if the OID doesn't exist.
*/
/*
* has_session_variable_privilege_name_name
* Check user privileges on a session variable given
* name username, text sessin variable name, and text priv name.
*/
"The variants that take a relation OID return NULL if the OID doesn't exist."
should it be
"The variants that take an OID type return NULL if the OID doesn't exist."
?

typo, "sessin" should be "session".
----------------<<<>>>>-------------------
<sect1 id="ddl-session-variables">
<title>Session Variables</title>
only mentioned that "Session variables themselves are persistent, but their
values are neither persistent nor shared (like the content of temporary tables).
"
I feel like this sentence is not that explicit. we actually want to say
"Once a session exits, the variable value is reset to NULL, one
session cannot see another session variable value."

+ <para>
+ A persistent database object that holds a value in session memory. This
+ value is private to each session and is released when the session ends.
+ Read or write access to session variables is controlled by privileges,
+ similar to other database objects.
+ </para>
i do like this description in glossary.sgml.
maybe we can copy it and put it to ddl.sgml "<sect1 id="ddl-session-variables">
----------------<<<>>>>-------------------
REVOKE [ GRANT OPTION FOR ]
{ { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
ON { VARIABLE <replaceable>variable_name</replaceable> [, ...]
| ALL VARIABLES IN SCHEMA <replaceable
class="parameter">schema_name</replaceable> [, ...] }
FROM { [ GROUP ] <replaceable
class="parameter">role_specification</replaceable> | PUBLIC } [, ...]
[ GRANTED BY <replaceable
class="parameter">role_specification</replaceable> ]
[ CASCADE | RESTRICT ]
revoke, seems still not right.
since with this, we can say:
REVOKE ALL PRIVILEGES ON VARIABLE v1 FROM group group alice CASCADE;

i think the correct one should be:
REVOKE [ GRANT OPTION FOR ]
{ { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
ON { VARIABLE <replaceable>variable_name</replaceable> [, ...]
| ALL VARIABLES IN SCHEMA <replaceable
class="parameter">schema_name</replaceable> [, ...] }
FROM <replaceable class="parameter">role_specification</replaceable> [, ...]
[ GRANTED BY <replaceable
class="parameter">role_specification</replaceable> ]
[ CASCADE | RESTRICT ]

----------------<<<>>>>-------------------
<programlisting>
CREATE VARIABLE public.current_user_id AS integer;
GRANT READ ON VARIABLE public.current_user_id TO PUBLIC;
LET current_user_id = (SELECT id FROM users WHERE usename = session_user);
SELECT current_user_id;
</programlisting>
"GRANT READ" should be "GRANT SELECT".
----------------<<<>>>>-------------------
doc/src/sgml/ref/alter_default_privileges.sgml
GRANT { SELECT | UPDATE | ALL [ PRIVILEGES ] }
ON VARIABLES
TO { [ GROUP ] <replaceable
class="parameter">role_name</replaceable> | PUBLIC } [, ...] [ WITH
GRANT OPTION ]
the above part is wrong?
should be:
GRANT { { SELECT | UPDATE } [,...]
| ALL [ PRIVILEGES ] }
ON VARIABLES
TO { [ GROUP ] <replaceable
class="parameter">role_name</replaceable> | PUBLIC } [, ...] [ WITH
GRANT OPTION ]

since we can:
ALTER DEFAULT PRIVILEGES
FOR ROLE alice
IN SCHEMA svartest
GRANT SELECT, UPDATE ON VARIABLES TO bob;
----------------<<<>>>>-----------------------------
CREATE VARIABLE IF NOT EXISTS v2 AS comp;
grant update on variable v2 to alice;
set role alice;
LET v2.a = 12; --acl permission error
LET v2.b = 12; --acl permission error
LET v2 = (11,12); --ok.

not sure this is the desired behavior, for composite type variables, you are
allowed to change all the values, but you are not allowed to update the field
value of the composite. The following are normal table test update cases.

create type comp as (a int, b int);
create table t2(a comp);
insert into t2 select '(11,12)';
grant update (a ) on t2 to alice;
set role alice;
update t2 set a.a = 13; --ok
update t2 set a.b = 13; --ok
update t2 set a = '(11,13)'; --ok
----------------<<<>>>>-----------------------------
domain seems to have an issue.

CREATE domain d1 AS int;
CREATE VARIABLE var1 AS d1;
let var1 = 3;
--this should fail?.
alter domain d1 add check (value <> 3);
select var1;
ERROR: value for domain d1 violates check constraint "d1_check"
----------------<<<>>>>-----------------------------
doc/src/sgml/ref/alter_variable.sgml
<title>Parameters</title> section, the order should
be: name, new_owner, new_name, new_schema?

I am beginning to look around 0002.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-19 07:25:51
Message-ID: CAFj8pRALQ-j-Dz3R1ivCoXut8LEhN+kSa7U8Gshucdv5zU3AfQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

st 18. 12. 2024 v 4:00 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> /*
> * has_session_variable_privilege variants
> * These are all named "has_session_variable_privilege" at the SQL
> level.
> * They take various combinations of variable name, variable OID,
> * user name, user OID, or implicit user = current_user.
> *
> * The result is a boolean value: true if user has the indicated
> * privilege, false if not. The variants that take a relation OID
> * return NULL if the OID doesn't exist.
> */
> /*
> * has_session_variable_privilege_name_name
> * Check user privileges on a session variable given
> * name username, text sessin variable name, and text priv name.
> */
> "The variants that take a relation OID return NULL if the OID doesn't
> exist."
> should it be
> "The variants that take an OID type return NULL if the OID doesn't exist."
> ?
>

yes, this comment was wrong, and I fixed it

*<><-->The result is a boolean value: true if user has the indicated
*<><-->privilege, false if not, or NULL if session variable doesn't
*<><-->exists.

>
> typo, "sessin" should be "session".
>

fixed

> ----------------<<<>>>>-------------------
> <sect1 id="ddl-session-variables">
> <title>Session Variables</title>
> only mentioned that "Session variables themselves are persistent, but their
> values are neither persistent nor shared (like the content of temporary
> tables).
> "
> I feel like this sentence is not that explicit. we actually want to say
> "Once a session exits, the variable value is reset to NULL, one
> session cannot see another session variable value."
>

This is not fully true. I wrote new paragraph there

<para>
The session variable holds a value in session memory. This value is
private
to each session and is released when the session ends.
</para>

>
> + <para>
> + A persistent database object that holds a value in session memory.
> This
> + value is private to each session and is released when the session
> ends.
> + Read or write access to session variables is controlled by
> privileges,
> + similar to other database objects.
> + </para>
> i do like this description in glossary.sgml.
> maybe we can copy it and put it to ddl.sgml "<sect1
> id="ddl-session-variables">
>

ok - I did it

----------------<<<>>>>-------------------
> REVOKE [ GRANT OPTION FOR ]
> { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
> ON { VARIABLE <replaceable>variable_name</replaceable> [, ...]
> | ALL VARIABLES IN SCHEMA <replaceable
> class="parameter">schema_name</replaceable> [, ...] }
> FROM { [ GROUP ] <replaceable
> class="parameter">role_specification</replaceable> | PUBLIC } [, ...]
> [ GRANTED BY <replaceable
> class="parameter">role_specification</replaceable> ]
> [ CASCADE | RESTRICT ]
> revoke, seems still not right.
> since with this, we can say:
> REVOKE ALL PRIVILEGES ON VARIABLE v1 FROM group group alice CASCADE;
>
> i think the correct one should be:
> REVOKE [ GRANT OPTION FOR ]
> { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
> ON { VARIABLE <replaceable>variable_name</replaceable> [, ...]
> | ALL VARIABLES IN SCHEMA <replaceable
> class="parameter">schema_name</replaceable> [, ...] }
> FROM <replaceable class="parameter">role_specification</replaceable>
> [, ...]
> [ GRANTED BY <replaceable
> class="parameter">role_specification</replaceable> ]
> [ CASCADE | RESTRICT ]
>

fixed

>
> ----------------<<<>>>>-------------------
> <programlisting>
> CREATE VARIABLE public.current_user_id AS integer;
> GRANT READ ON VARIABLE public.current_user_id TO PUBLIC;
> LET current_user_id = (SELECT id FROM users WHERE usename = session_user);
> SELECT current_user_id;
> </programlisting>
> "GRANT READ" should be "GRANT SELECT".
>

fixed - note it is from second patch

> ----------------<<<>>>>-------------------
> doc/src/sgml/ref/alter_default_privileges.sgml
> GRANT { SELECT | UPDATE | ALL [ PRIVILEGES ] }
> ON VARIABLES
> TO { [ GROUP ] <replaceable
> class="parameter">role_name</replaceable> | PUBLIC } [, ...] [ WITH
> GRANT OPTION ]
> the above part is wrong?
> should be:
> GRANT { { SELECT | UPDATE } [,...]
> | ALL [ PRIVILEGES ] }
> ON VARIABLES
> TO { [ GROUP ] <replaceable
> class="parameter">role_name</replaceable> | PUBLIC } [, ...] [ WITH
> GRANT OPTION ]
>
> since we can:
> ALTER DEFAULT PRIVILEGES
> FOR ROLE alice
> IN SCHEMA svartest
> GRANT SELECT, UPDATE ON VARIABLES TO bob;
>

fixed

> ----------------<<<>>>>-----------------------------
> CREATE VARIABLE IF NOT EXISTS v2 AS comp;
> grant update on variable v2 to alice;
> set role alice;
> LET v2.a = 12; --acl permission error
> LET v2.b = 12; --acl permission error
> LET v2 = (11,12); --ok.
>

>
> not sure this is the desired behavior, for composite type variables, you
> are
> allowed to change all the values, but you are not allowed to update the
> field
> value of the composite. The following are normal table test update cases.
>
> create type comp as (a int, b int);
> create table t2(a comp);
> insert into t2 select '(11,12)';
> grant update (a ) on t2 to alice;
> set role alice;
> update t2 set a.a = 13; --ok
> update t2 set a.b = 13; --ok
> update t2 set a = '(11,13)'; --ok
>

I think this is a bug, but I need more time for investigation. For field
update you need to read the content
the variable, but you are missing SELECT right on the variable, and then
the LET fails. Unfortunately
this is done inside the executor, so it is harder to fix it.

> ----------------<<<>>>>-----------------------------
> domain seems to have an issue.
>
> CREATE domain d1 AS int;
> CREATE VARIABLE var1 AS d1;
> let var1 = 3;
> --this should fail?.
> alter domain d1 add check (value <> 3);
> select var1;
> ERROR: value for domain d1 violates check constraint "d1_check"
>

I fixed it

CREATE DOMAIN testvar_domain AS int;
CREATE VARIABLE var1 AS testvar_domain;

(2024-12-18 21:21:15) postgres=# ALTER DOMAIN testvar_domain ADD
CHECK(value <> 100);
ERROR: cannot alter domain "testvar_domain" because session variable
"public.var1" uses it

Unfortunately I cannot force constraint check validation in other sessions,
so the most safe solution for now is
restriction of this ALTER when domain is used by some variable. I wrote
regress tests for this.
Note: looks so validation of domain check constraints doesn't work for
temporary tables (what is expected,
not sure if it is documented).

----------------<<<>>>>-----------------------------
> doc/src/sgml/ref/alter_variable.sgml
> <title>Parameters</title> section, the order should
> be: name, new_owner, new_name, new_schema?
>

changed

>
> I am beginning to look around 0002.
>

Thank you very much

Regards

Pavel

Attachment Content-Type Size
v20241219-0021-transactional-variables.patch text/x-patch 39.2 KB
v20241219-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 14.1 KB
v20241219-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241219-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241219-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241219-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241219-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 13.8 KB
v20241219-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241219-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241219-0012-implementation-of-temporary-session-variables.patch text/x-patch 42.0 KB
v20241219-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241219-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241219-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241219-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20241219-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241219-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241219-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241219-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241219-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241219-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241219-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 145.5 KB
v20241219-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 165.1 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-20 07:57:33
Message-ID: CACJufxG7LvaNbF8ZSCcxOVUbm9W=KGjD=h_Wk+5imMw4s_2QxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.
review is based on
v20241219-0002-Storage-for-session-variables-and-SQL-interface.patch
and
v20241219-0001-Enhancing-catalog-for-support-session-variables-and-.patch.

in doc/src/sgml/catalogs.sgml

<row>
<entry role="catalog_table_entry"><para role="column_definition">
<structfield>defaclobjtype</structfield> <type>char</type>
</para>
<para>
Type of object this entry is for:
<literal>r</literal> = relation (table, view),
<literal>S</literal> = sequence,
<literal>f</literal> = function,
<literal>T</literal> = type,
<literal>n</literal> = schema
</para></entry>
</row>
this need updated for session variable?

psql meta command \ddp
src/bin/psql/describe.c listDefaultACLs
also need to change.
----------------<<>>-------------------------
+-- show variable
+SELECT public.svar;
+SELECT public.svar.c;
+SELECT (public.svar).*;
+
+-- the variable is shadowed, raise error
+SELECT public.svar.c FROM public.svar;
+
+-- can be fixed by alias
+SELECT public.svar.c FROM public.svar x

The above tests are duplicated in session_variables.sql.
----------------<<>>-------------------------
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -49,7 +49,7 @@ typedef struct PlannedStmt

NodeTag type;

- CmdType commandType; /*
select|insert|update|delete|merge|utility */
+ CmdType commandType; /*
select|let|insert|update|delete|merge|utility */

since we don't have CMD_LET CmdType.
so this comment change is not necessary?
----------------<<>>-------------------------
the following are simple tests that triggers makeParamSessionVariable error
messages. we don't have related tests, we can add it on session_variables.sql.

create type t1 as (a int, b int);
CREATE VARIABLE v1 text;
CREATE VARIABLE v2 as t1;
select v1.a;
select v2.c;

also
select v2.c;
ERROR: could not identify column "c" in variable
LINE 1: select v2.c;
^
the error message is no good. i think we want:
ERROR: could not identify column "c" in variable "public.v1"
----------------<<>>-------------------------
+ /*
+ * Check for duplicates. Note that this does not really prevent
+ * duplicates, it's here just to provide nicer error message in common
+ * case. The real protection is the unique key on the catalog.
+ */
+ if (SearchSysCacheExists2(VARIABLENAMENSP,
+ PointerGetDatum(varName),
+ ObjectIdGetDatum(varNamespace)))
+ {
+ }
I am confused by these comments. i think the SearchSysCacheExists2
do actually prevent duplicates.
I noticed that publication_add_relation also has similar comments.
----------------<<>>-------------------------
typedef struct LetStmt
{
NodeTag type;
List *target; /* target variable */
Node *query; /* source expression */
int location;
} LetStmt;
here, location should be a type of ParseLoc.
----------------<<>>-------------------------
in 0001, 0002, function SetSessionVariableWithSecurityCheck
never being used.
----------------<<>>-------------------------
+/*
+ * transformLetStmt -
+ * transform an Let Statement
+ */
+static Query *
+transformLetStmt(ParseState *pstate, LetStmt *stmt)
...
+ /*
+ * Save target session variable ID. This value is used multiple times: by
+ * the query rewriter (for getting related defexpr), by planner (for
+ * acquiring an AccessShareLock on target variable), and by the executor
+ * (we need to know the target variable ID).
+ */
+ query->resultVariable = varid;

"defexpr", do you mean "default expression"?
Generally letsmt is like: "let variable = (SelectStmt)"
is there nothing related to the DEFAULT expression?
"(we need to know the target variable ID)." in ExecuteLetStmt that is true.
but I commented out the following lines, the regress test still
succeeded.

extract_query_dependencies_walker
/* record dependency on the target variable of a LET command */
// if (OidIsValid(query->resultVariable))
// record_plan_variable_dependency(context, query->resultVariable);

ScanQueryForLocks
// /* process session variables */
// if (OidIsValid(parsetree->resultVariable))
// {
// if (acquire)
// LockDatabaseObject(VariableRelationId, parsetree->resultVariable,
// 0, AccessShareLock);
// else
// UnlockDatabaseObject(VariableRelationId, parsetree->resultVariable,
// 0, AccessShareLock);
// }
----------------<<>>-------------------------
in transformLetStmt, we already did ACL privilege check,
we don't need do it again at ExecuteLetStmt?


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: proposal: schema variables
Date: 2024-12-20 12:53:20
Message-ID: CAFj8pRABA6q1crR35qusvcTy3tfrxAJ_9+b+e3DE0CBQSkTZGA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

----------------<<<>>>>-----------------------------
>> CREATE VARIABLE IF NOT EXISTS v2 AS comp;
>> grant update on variable v2 to alice;
>> set role alice;
>> LET v2.a = 12; --acl permission error
>> LET v2.b = 12; --acl permission error
>> LET v2 = (11,12); --ok.
>>
>
>
>
>>
>> not sure this is the desired behavior, for composite type variables, you
>> are
>> allowed to change all the values, but you are not allowed to update the
>> field
>> value of the composite. The following are normal table test update cases.
>>
>> create type comp as (a int, b int);
>> create table t2(a comp);
>> insert into t2 select '(11,12)';
>> grant update (a ) on t2 to alice;
>> set role alice;
>> update t2 set a.a = 13; --ok
>> update t2 set a.b = 13; --ok
>> update t2 set a = '(11,13)'; --ok
>>
>
> I think this is a bug, but I need more time for investigation. For field
> update you need to read the content
> the variable, but you are missing SELECT right on the variable, and then
> the LET fails. Unfortunately
> this is done inside the executor, so it is harder to fix it.
>
>
I fixed this issue - the change is done in Patch 02

Reards

Pavel

>
>

Attachment Content-Type Size
v20241220-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241220-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241220-0021-transactional-variables.patch text/x-patch 39.2 KB
v20241220-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 15.5 KB
v20241220-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241220-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241220-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20241220-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241220-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241220-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241220-0012-implementation-of-temporary-session-variables.patch text/x-patch 42.0 KB
v20241220-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241220-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20241220-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241220-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241220-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241220-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241220-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241220-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241220-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241220-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 151.6 KB
v20241220-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 165.1 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-20 22:00:12
Message-ID: CAFj8pRBY_2awVdER5piyy_JPqsU1Sgr4HLO-v6C1nUS3dJnang@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

pá 20. 12. 2024 v 8:58 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
> review is based on
> v20241219-0002-Storage-for-session-variables-and-SQL-interface.patch
> and
> v20241219-0001-Enhancing-catalog-for-support-session-variables-and-.patch.
>
> in doc/src/sgml/catalogs.sgml
>
> <row>
> <entry role="catalog_table_entry"><para role="column_definition">
> <structfield>defaclobjtype</structfield> <type>char</type>
> </para>
> <para>
> Type of object this entry is for:
> <literal>r</literal> = relation (table, view),
> <literal>S</literal> = sequence,
> <literal>f</literal> = function,
> <literal>T</literal> = type,
> <literal>n</literal> = schema
> </para></entry>
> </row>
> this need updated for session variable?
>

yes, fixed

>
> psql meta command \ddp
> src/bin/psql/describe.c listDefaultACLs
> also need to change.
>

fixed

> ----------------<<>>-------------------------
> +-- show variable
> +SELECT public.svar;
> +SELECT public.svar.c;
> +SELECT (public.svar).*;
> +
> +-- the variable is shadowed, raise error
> +SELECT public.svar.c FROM public.svar;
> +
> +-- can be fixed by alias
> +SELECT public.svar.c FROM public.svar x
>
> The above tests are duplicated in session_variables.sql.
>

It looks like duplicated test, but it isn't - look on session_variables.out

+-- the variable is shadowed, raise error
+SELECT public.svar.c FROM public.svar;
+ERROR: column svar.c does not exist
+LINE 1: SELECT public.svar.c FROM public.svar;
+ ^
+-- can be fixed by alias
+SELECT public.svar.c FROM public.svar x;
+ c..
+-----
+ 300
+(1 row)

> ----------------<<>>-------------------------
> --- a/src/include/nodes/plannodes.h
> +++ b/src/include/nodes/plannodes.h
> @@ -49,7 +49,7 @@ typedef struct PlannedStmt
>
> NodeTag type;
>
> - CmdType commandType; /*
> select|insert|update|delete|merge|utility */
> + CmdType commandType; /*
> select|let|insert|update|delete|merge|utility */
>
> since we don't have CMD_LET CmdType.
> so this comment change is not necessary?
>

true, removed

> ----------------<<>>-------------------------
> the following are simple tests that triggers makeParamSessionVariable error
> messages. we don't have related tests, we can add it on
> session_variables.sql.
>
> create type t1 as (a int, b int);
> CREATE VARIABLE v1 text;
> CREATE VARIABLE v2 as t1;
> select v1.a;
> select v2.c;
>
>
done

> also
> select v2.c;
> ERROR: could not identify column "c" in variable
> LINE 1: select v2.c;
> ^
> the error message is no good. i think we want:
> ERROR: could not identify column "c" in variable "public.v1"
>

done

----------------<<>>-------------------------
> + /*
> + * Check for duplicates. Note that this does not really prevent
> + * duplicates, it's here just to provide nicer error message in common
> + * case. The real protection is the unique key on the catalog.
> + */
> + if (SearchSysCacheExists2(VARIABLENAMENSP,
> + PointerGetDatum(varName),
> + ObjectIdGetDatum(varNamespace)))
> + {
> + }
> I am confused by these comments. i think the SearchSysCacheExists2
> do actually prevent duplicates.
> I noticed that publication_add_relation also has similar comments.
>

RowExclusiveLock doesn't block concurrent inserts. So theoretically, two
sessions can try
to create variables with the same name and same schema. Using syscache
cache cannot
protect against this scenario. The real protection is only a unique index.
It is same like

IF NOT EXISTS(SELECT * FROM foo WHERE id = 10) THEN
INSERT INTO foo(id) VALUES(10)
END IF;

This fragment doesn't protect us against duplicit id in table foo. The real
protection can
be done only by unique index, but when you use this fragment, then you can
reduce
error messages like `unique index violation` and that can benefit in some
scenarios.

I think this comment is correct, but enhancig is welcome.

> ----------------<<>>-------------------------
> typedef struct LetStmt
> {
> NodeTag type;
> List *target; /* target variable */
> Node *query; /* source expression */
> int location;
> } LetStmt;
> here, location should be a type of ParseLoc.
>

changed

> ----------------<<>>-------------------------
> in 0001, 0002, function SetSessionVariableWithSecurityCheck
> never being used.
>

moved to patch 18 plpgsql-implementation-for-LET-statement

> ----------------<<>>-------------------------
> +/*
> + * transformLetStmt -
> + * transform an Let Statement
> + */
> +static Query *
> +transformLetStmt(ParseState *pstate, LetStmt *stmt)
> ...
> + /*
> + * Save target session variable ID. This value is used multiple
> times: by
> + * the query rewriter (for getting related defexpr), by planner (for
> + * acquiring an AccessShareLock on target variable), and by the
> executor
> + * (we need to know the target variable ID).
> + */
> + query->resultVariable = varid;
>
> "defexpr", do you mean "default expression"?
> Generally letsmt is like: "let variable = (SelectStmt)"
> is there nothing related to the DEFAULT expression?
> "(we need to know the target variable ID)." in ExecuteLetStmt that is true.
> but I commented out the following lines, the regress test still
> succeeded.
>

This comment is partially obsolete - early implementations of LET
statements supports syntax LET var = DEFAULT.
I removed this feature, because the implementation was not trivial and the
benefit is not too high.

I changed this comment to

<-->/*
<--> * Save target session variable ID. It is used later for
<--> * acquiring an AccessShareLock on target variable, setting
<--> * plan dependency and finally for creating VariableDestReceiver.
<--> */

>
> extract_query_dependencies_walker
> /* record dependency on the target variable of a LET command */
> // if (OidIsValid(query->resultVariable))
> // record_plan_variable_dependency(context, query->resultVariable);
>

I checked regress tests, and plan invalidation is tested there, but not for
target variable.
I enhanced this test to check the invalidation of plans when dropped
variable is used
as target.

SET plan_cache_mode TO force_generic_plan;

LET var1 = 3.14;
SELECT plpgsqlfx();
LET var1 = 3.14 * 2;
SELECT plpgsqlfx();

SELECT plpgsqlfx2(10.0);
SELECT var2;

DROP VARIABLE var1;
DROP VARIABLE var2;

-- dependency (plan invalidation) should work
CREATE VARIABLE var1 AS numeric;
CREATE VARIABLE var2 AS numeric;

LET var1 = 3.14 * 3;
SELECT plpgsqlfx();
LET var1 = 3.14 * 4;
SELECT plpgsqlfx();

SELECT plpgsqlfx2(10.0);
SELECT var2;

DROP VARIABLE var1;
DROP VARIABLE var2;
DROP FUNCTION plpgsqlfx();
DROP FUNCTION plpgsqlfx2();

SET plan_cache_mode TO DEFAULT;

>
> ScanQueryForLocks
> // /* process session variables */
> // if (OidIsValid(parsetree->resultVariable))
> // {
> // if (acquire)
> // LockDatabaseObject(VariableRelationId,
> parsetree->resultVariable,
> // 0, AccessShareLock);
> // else
> // UnlockDatabaseObject(VariableRelationId,
> parsetree->resultVariable,
> // 0, AccessShareLock);
> // }
>

This is protection against dropping an session variable when it is used. I
think so this is tested by isolation tester
in Patch 05

> ----------------<<>>-------------------------
> in transformLetStmt, we already did ACL privilege check,
> we don't need do it again at ExecuteLetStmt?
>

It is redundant, but surely it should be checked in the executor stage. I
removed this check from transformLetStmt.

Regards

Pavel

Attachment Content-Type Size
v20241220-2-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241220-2-0021-transactional-variables.patch text/x-patch 39.2 KB
v20241220-2-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.1 KB
v20241220-2-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241220-2-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241220-2-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20241220-2-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241220-2-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 35.6 KB
v20241220-2-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 33.6 KB
v20241220-2-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241220-2-0012-implementation-of-temporary-session-variables.patch text/x-patch 42.0 KB
v20241220-2-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241220-2-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241220-2-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20241220-2-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241220-2-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241220-2-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241220-2-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241220-2-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241220-2-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241220-2-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 152.2 KB
v20241220-2-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 166.4 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-27 15:19:29
Message-ID: CACJufxEM=BLEn6YfgGonM7yuXMn7iqQJcH5PnDVbajWKanynfg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

+ if (!OidIsValid(varid))
+ AcceptInvalidationMessages();
+ else if (OidIsValid(varid))
+ LockDatabaseObject(VariableRelationId, varid, 0, AccessShareLock);

we can change it to
+ if (!OidIsValid(varid))
+ AcceptInvalidationMessages();
+ else
+ LockDatabaseObject(VariableRelationId, varid, 0, AccessShareLock);

inval_count didn't explain at all, other places did actually explain it.
Can we add some text explaining inval_count? (i didn't fully understand
this part, that is why i am asking..)

seems IdentifyVariable all these three ereport(ERROR...) don't have
regress tests,
i think we should have it. Am I missing something?

create variable v2 as int;
let v2.a = 1;
ERROR: type "integer" of target session variable "public.v2" is not a
composite type
LINE 1: let v2.a = 1;
^
the error messages look weird.
IMO, it should either be
"type of session variable "public.v2" is not a composite type"
or
"session variable "public.v2" don't have attribute "a"

also, the above can be as a regress test for:
+ if (attrname && !is_rowtype)
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("type \"%s\" of target session variable \"%s.%s\" is not a
composite type",
+ format_type_be(typid),
+ get_namespace_name(get_session_variable_namespace(varid)),
+ get_session_variable_name(varid)),
+ parser_errposition(pstate, stmt->location)));
since we don't have coverage tests for it.

+ if (coerced_expr == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("variable \"%s.%s\" is of type %s,"
+ " but expression is of type %s",
+ get_namespace_name(get_session_variable_namespace(varid)),
+ get_session_variable_name(varid),
+ format_type_be(typid),
+ format_type_be(exprtypid)),
+ errhint("You will need to rewrite or cast the expression."),
+ parser_errposition(pstate, exprLocation((Node *) expr))));

generally, errmsg(...) should put it into one line for better grep-ability
so we can change it to:
+errmsg("variable \"%s.%s\" is of type %s, but expression is of type %s"...)

also no coverage tests?
simple test case for it:
create variable v2 as int;
let v2 = '1'::jsonb;

---------------<<<>>>--------------
+let_target:
+ ColId opt_indirection
+ {
+ $$ = list_make1(makeString($1));
+ if ($2)
+ $$ = list_concat($$,
+ check_indirection($2, yyscanner));
+ }
if you look closely, it seems the indentation level is wrong in
line "$$ = list_concat($$,"?

---------------<<<>>>--------------
i did some refactoring in session_variables.sql for privilege check.
make the tests more neat, please check attached.

Attachment Content-Type Size
session_variable_priv.diff application/x-patch 12.6 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-28 10:34:27
Message-ID: CACJufxHB=xLzuq6Y2OsF_+KzGYg_U=1o4RBCciScn44Y3FMn6g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

src9=# select 'XLogRecPtr'::regtype;
ERROR: type "xlogrecptr" does not exist
LINE 1: select 'XLogRecPtr'::regtype;
^
so
+ <structfield>varcreate_lsn</structfield> <type>XLogRecPtr</type>
should be
<structfield>varcreate_lsn</structfield> <type>pg_lsn</type>
?

also
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>varcreate_lsn</structfield> <type>XLogRecPtr</type>
+ </para>
+ <para>
+ LSN of the transaction where the variable was created.
+ <structfield>varcreate_lsn</structfield> and
+ <structfield>oid</structfield> together form the all-time unique
+ identifier (<structfield>oid</structfield> alone is not enough, since
+ object identifiers can get reused).
+ </para></entry>
+ </row>
+
we have "pg_variable_oid_index" PRIMARY KEY, btree (oid)
for table pg_variable.
so I am confused by saying the column "oid" itself is not enough to
prove unique.

in let.sgml
<term><literal>session_variable</literal></term>
should be
<term><replaceable class="parameter">session_variable</replaceable></term>

<term><literal>sql_expression</literal></term>
should be
<term><replaceable class="parameter">sql_expression</replaceable></term>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-28 15:32:17
Message-ID: CAFj8pRBxA868TpLDe9ofXdpVUNmHY8pzkxrjbZ0obCe0g+YZ-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

pá 27. 12. 2024 v 16:20 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> + if (!OidIsValid(varid))
> + AcceptInvalidationMessages();
> + else if (OidIsValid(varid))
> + LockDatabaseObject(VariableRelationId, varid, 0, AccessShareLock);
>
> we can change it to
> + if (!OidIsValid(varid))
> + AcceptInvalidationMessages();
> + else
> + LockDatabaseObject(VariableRelationId, varid, 0, AccessShareLock);
>

done

>
> inval_count didn't explain at all, other places did actually explain it.
> Can we add some text explaining inval_count? (i didn't fully understand
> this part, that is why i am asking..)
>

done

>
> seems IdentifyVariable all these three ereport(ERROR...) don't have
> regress tests,
> i think we should have it. Am I missing something?
>

done

>
> create variable v2 as int;
> let v2.a = 1;
> ERROR: type "integer" of target session variable "public.v2" is not a
> composite type
> LINE 1: let v2.a = 1;
> ^
> the error messages look weird.
> IMO, it should either be
> "type of session variable "public.v2" is not a composite type"
> or
> "session variable "public.v2" don't have attribute "a"
>

changed

I did inspiration from transformAssignmentIndirection now

(2024-12-28 16:07:57) postgres=# let x.a = 20;
ERROR: cannot assign to field "a" of session variable "public.x" because
its type integer is not a composite type
LINE 1: let x.a = 20;
^

>
> also, the above can be as a regress test for:
> + if (attrname && !is_rowtype)
> + ereport(ERROR,
> + (errcode(ERRCODE_WRONG_OBJECT_TYPE),
> + errmsg("type \"%s\" of target session variable \"%s.%s\" is not a
> composite type",
> + format_type_be(typid),
> + get_namespace_name(get_session_variable_namespace(varid)),
> + get_session_variable_name(varid)),
> + parser_errposition(pstate, stmt->location)));
> since we don't have coverage tests for it.
>
>
done

>
> + if (coerced_expr == NULL)
> + ereport(ERROR,
> + (errcode(ERRCODE_DATATYPE_MISMATCH),
> + errmsg("variable \"%s.%s\" is of type %s,"
> + " but expression is of type %s",
> + get_namespace_name(get_session_variable_namespace(varid)),
> + get_session_variable_name(varid),
> + format_type_be(typid),
> + format_type_be(exprtypid)),
> + errhint("You will need to rewrite or cast the expression."),
> + parser_errposition(pstate, exprLocation((Node *) expr))));
>
> generally, errmsg(...) should put it into one line for better grep-ability
> so we can change it to:
> +errmsg("variable \"%s.%s\" is of type %s, but expression is of type
> %s"...)
>

done

>
> also no coverage tests?
> simple test case for it:
> create variable v2 as int;
> let v2 = '1'::jsonb;
>

done

>
> ---------------<<<>>>--------------
> +let_target:
> + ColId opt_indirection
> + {
> + $$ = list_make1(makeString($1));
> + if ($2)
> + $$ = list_concat($$,
> + check_indirection($2, yyscanner));
> + }
> if you look closely, it seems the indentation level is wrong in
> line "$$ = list_concat($$,"?
>

let_target is not needed as separate rule now, so I removed it and little
bit cleaned (really only little bit)

>
> ---------------<<<>>>--------------
> i did some refactoring in session_variables.sql for privilege check.
> make the tests more neat, please check attached.
>

merged with minor changes in comment's formatting

I'll send the patch set with next mail

Best regards

Pavel


From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-28 16:46:28
Message-ID: CACJufxEb1prZo4G4BhYym1VqKHaPVUv3SoggTR4uCqgCRY7Q-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

+ if (stmt->collClause)
+ collation = LookupCollation(pstate,
+ stmt->collClause->collname,
+ stmt->collClause->location);
+ else
+ collation = typcollation;;

two semi-colon. should be only one.
------------------<<>>>---------------
+ /* locks the variable with an AccessShareLock */
+ varid = IdentifyVariable(names, &attrname, &not_unique, false);
+ if (not_unique)
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_PARAMETER),
+ errmsg("target \"%s\" of LET command is ambiguous",
+ NameListToString(names)),
+ parser_errposition(pstate, stmt->location)));

the following are tests for the above "LET command is ambiguous" error message.

create schema test;
CREATE TYPE test AS (test int);
CREATE variable test.test as test;
set search_path to test;
let test.test = 1;
------------------<<>>>---------------
+ else
+ {
+ /* the last field of list can be star too */
+ Assert(IsA(field2, A_Star));
+
+ /*
+ * In this case, the field1 should be variable name. But
+ * direct unboxing of composite session variables is not
+ * supported now, and then we don't need to try lookup
+ * related variable.
+ *
+ * Unboxing is supported by syntax (var).*
+ */
+ return InvalidOid;
+ }
I don't fully understand the above comments,
add
`elog(INFO, "%s:%d called", __FILE__, __LINE__); ` within the ELSE branch.
Then I found out the ELSE branch doesn't have coverage tests.

------------------<<>>>---------------
+ /*
+ * a.b.c can mean catalog.schema.variable or
+ * schema.variable.field.
....
+ /*
+ * a.b can mean "schema"."variable" or "variable"."field".
+ * Check both variants, and returns InvalidOid with
+ * not_unique flag, when both interpretations are
+ * possible.
+ */
here, we use the word "field", but the function IdentifyVariable above
comment, we use
word "attribute", for consistency's sake, we should use "attribute"
instead of "field"

+/* -----
+ * IdentifyVariable - try to find a variable from a list of identifiers
+ *
+ * Returns the OID of the variable found, or InvalidOid.
+ *
+ * "names" is a list of up to four identifiers; possible meanings are:
+ * - variable (searched on the search_path)
+ * - schema.variable
+ * - variable.attribute (searched on the search_path)
+ * - schema.variable.attribute
+ * - database.schema.variable
+ * - database.schema.variable.attribute

------------------<<>>>---------------


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-28 17:29:26
Message-ID: CAFj8pRBQkR1PY5RPiopA59pv3SaQmqc21mW-eS9=-TH-dP2nQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

so 28. 12. 2024 v 11:35 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> src9=# select 'XLogRecPtr'::regtype;
> ERROR: type "xlogrecptr" does not exist
> LINE 1: select 'XLogRecPtr'::regtype;
> ^
> so
> + <structfield>varcreate_lsn</structfield> <type>XLogRecPtr</type>
> should be
> <structfield>varcreate_lsn</structfield> <type>pg_lsn</type>
> ?
>

done

>
> also
> + <row>
> + <entry role="catalog_table_entry"><para role="column_definition">
> + <structfield>varcreate_lsn</structfield> <type>XLogRecPtr</type>
> + </para>
> + <para>
> + LSN of the transaction where the variable was created.
> + <structfield>varcreate_lsn</structfield> and
> + <structfield>oid</structfield> together form the all-time unique
> + identifier (<structfield>oid</structfield> alone is not enough,
> since
> + object identifiers can get reused).
> + </para></entry>
> + </row>
> +
> we have "pg_variable_oid_index" PRIMARY KEY, btree (oid)
> for table pg_variable.
> so I am confused by saying the column "oid" itself is not enough to
> prove unique.
>

The session variable is stored in memory until the end of the session.
Theoretically, some sessions with used session variables can be opened for
a very long time without any activity - so it is not possible to process
sinval message. Other sessions can drop and create a lot of session
variables (this is very possible with temporary session variables). Oid in
Postgres can overflow, and postgres can reuse used oid of dropped objects
(oid is only 32bit integer). And after some time, the session with the used
variable can be activated, and the session variable can be used. Before
usage the session variable is rechecked against pg_variable, and
theoretically the variable with the same oid can be there (although it is a
different variable with possibly different type). The implementation should
protect against this scenario. The stored value must not be used in this
case - the usage of old value is dangerous - the calculations with the
variable can lose sense or can crash postgres. LSN is forever unique - it
is 64bit integer - so it is our safeguard so we can detect obsolete values
(stored in memory) although there are variables with the same oid.

oid in pg_variable ensures a unique identifier for any session variable in
one moment. Compound key [oid, varcreate_lsn] is a unique identifier for
ever.

> in let.sgml
> <term><literal>session_variable</literal></term>
> should be
> <term><replaceable class="parameter">session_variable</replaceable></term>
>

done

>
> <term><literal>sql_expression</literal></term>
> should be
> <term><replaceable class="parameter">sql_expression</replaceable></term>
>

done


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-28 21:49:59
Message-ID: CAFj8pRDK2heEhQNcwD=tcKpG5YyPu7zOz2jdRW5A5QfoSUEi_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

so 28. 12. 2024 v 17:47 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> + if (stmt->collClause)
> + collation = LookupCollation(pstate,
> + stmt->collClause->collname,
> + stmt->collClause->location);
> + else
> + collation = typcollation;;
>
> two semi-colon. should be only one.
>

removed

> ------------------<<>>>---------------
> + /* locks the variable with an AccessShareLock */
> + varid = IdentifyVariable(names, &attrname, &not_unique, false);
> + if (not_unique)
> + ereport(ERROR,
> + (errcode(ERRCODE_AMBIGUOUS_PARAMETER),
> + errmsg("target \"%s\" of LET command is ambiguous",
> + NameListToString(names)),
> + parser_errposition(pstate, stmt->location)));
>
> the following are tests for the above "LET command is ambiguous" error
> message.
>
> create schema test;
> CREATE TYPE test AS (test int);
> CREATE variable test.test as test;
> set search_path to test;
> let test.test = 1;
>

done

------------------<<>>>---------------
> + else
> + {
> + /* the last field of list can be star too */
> + Assert(IsA(field2, A_Star));
> +
> + /*
> + * In this case, the field1 should be variable name. But
> + * direct unboxing of composite session variables is not
> + * supported now, and then we don't need to try lookup
> + * related variable.
> + *
> + * Unboxing is supported by syntax (var).*
> + */
> + return InvalidOid;
> + }
> I don't fully understand the above comments,
>

The parser allows only two syntaxes - identifier.identifier or
identifier.star. Second
syntax is not supported by session variables, and then I didn't try to
search for the variable.
Some users can be confused by similar syntaxes identifier.* and
(identifier).* Only
second syntax is composite unboxing, and only second syntax is supported for
session variables.

Maybe the note about unboxing is messy there?

add
> `elog(INFO, "%s:%d called", __FILE__, __LINE__); ` within the ELSE branch.
> Then I found out the ELSE branch doesn't have coverage tests.
>

I don't understand this comment? I don't use elog(INFO anywhere

>
> ------------------<<>>>---------------
> + /*
> + * a.b.c can mean catalog.schema.variable or
> + * schema.variable.field.
> ....
> + /*
> + * a.b can mean "schema"."variable" or "variable"."field".
> + * Check both variants, and returns InvalidOid with
> + * not_unique flag, when both interpretations are
> + * possible.
> + */
> here, we use the word "field", but the function IdentifyVariable above
> comment, we use
> word "attribute", for consistency's sake, we should use "attribute"
> instead of "field"
>

done

>
> +/* -----
> + * IdentifyVariable - try to find a variable from a list of identifiers
> + *
> + * Returns the OID of the variable found, or InvalidOid.
> + *
> + * "names" is a list of up to four identifiers; possible meanings are:
> + * - variable (searched on the search_path)
> + * - schema.variable
> + * - variable.attribute (searched on the search_path)
> + * - schema.variable.attribute
> + * - database.schema.variable
> + * - database.schema.variable.attribute
>
> ------------------<<>>>---------------
>

updated patchset assigned

Thank you very much for review

Regards

Pavel

Attachment Content-Type Size
v20241228-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241228-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241228-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241228-0021-transactional-variables.patch text/x-patch 37.3 KB
v20241228-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.1 KB
v20241228-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241228-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20241228-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20241228-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241228-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.0 KB
v20241228-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20241228-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241228-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241228-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20241228-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 14.0 KB
v20241228-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241228-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241228-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241228-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241228-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241228-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 154.3 KB
v20241228-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 167.3 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-29 02:48:51
Message-ID: CACJufxEk16ArmFuTV9VYi6DJaZ+9Jrbt0-u0Zuov7sk-vpg_Dg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Sun, Dec 29, 2024 at 5:50 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> Hi
>
>
>> ------------------<<>>>---------------
>> + else
>> + {
>> + /* the last field of list can be star too */
>> + Assert(IsA(field2, A_Star));
>> +
>> + /*
>> + * In this case, the field1 should be variable name. But
>> + * direct unboxing of composite session variables is not
>> + * supported now, and then we don't need to try lookup
>> + * related variable.
>> + *
>> + * Unboxing is supported by syntax (var).*
>> + */
>> + return InvalidOid;
>> + }
>> I don't fully understand the above comments,
>
>
> The parser allows only two syntaxes - identifier.identifier or identifier.star. Second
> syntax is not supported by session variables, and then I didn't try to search for the variable.
> Some users can be confused by similar syntaxes identifier.* and (identifier).* Only
> second syntax is composite unboxing, and only second syntax is supported for
> session variables.
>
> Maybe the note about unboxing is messy there?
>
>> add
>> `elog(INFO, "%s:%d called", __FILE__, __LINE__); ` within the ELSE branch.
>> Then I found out the ELSE branch doesn't have coverage tests.
>
>
> I don't understand this comment? I don't use elog(INFO anywhere
>
>

sorry for confusion, i mean,
i added " elog(INFO", the regress test is still successful,
therefore it means the above ELSE branch code doesn't have coverage tests.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-29 06:24:55
Message-ID: CAFj8pRD+Y=ZFM+xYpx4kt395h8moR9g-nVbGMMKy7eayXXNw2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

>> + {
>> + /* the last field of list can be star too */
>> + Assert(IsA(field2, A_Star));
>> +
>> + /*
>> + * In this case, the field1 should be variable name. But
>> + * direct unboxing of composite session variables is not
>> + * supported now, and then we don't need to try lookup
>> + * related variable.
>> + *
>> + * Unboxing is supported by syntax (var).*
>> + */
>> + return InvalidOid;
>> + }
>> I don't fully understand the above comments,
>>
>
> The parser allows only two syntaxes - identifier.identifier or
> identifier.star. Second
> syntax is not supported by session variables, and then I didn't try to
> search for the variable.
> Some users can be confused by similar syntaxes identifier.* and
> (identifier).* Only
> second syntax is composite unboxing, and only second syntax is supported
> for
> session variables.
>
>
I changed this comment to

<--><--><--><--><-->/*
<--><--><--><--><--> * The syntax ident.* is used only by table aliases,
<--><--><--><--><--> * and then this identifier cannot be a reference to
<--><--><--><--><--> * session variable.
<--><--><--><--><--> */


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2024-12-29 08:42:11
Message-ID: CAFj8pRAaoPCc=n_TPpWdOvzEdc96xfJZR8W7PphMLxLbGxAq-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 29. 12. 2024 v 3:49 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> On Sun, Dec 29, 2024 at 5:50 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> >
> > Hi
> >
> >
> >> ------------------<<>>>---------------
> >> + else
> >> + {
> >> + /* the last field of list can be star too */
> >> + Assert(IsA(field2, A_Star));
> >> +
> >> + /*
> >> + * In this case, the field1 should be variable name. But
> >> + * direct unboxing of composite session variables is not
> >> + * supported now, and then we don't need to try lookup
> >> + * related variable.
> >> + *
> >> + * Unboxing is supported by syntax (var).*
> >> + */
> >> + return InvalidOid;
> >> + }
> >> I don't fully understand the above comments,
> >
> >
> > The parser allows only two syntaxes - identifier.identifier or
> identifier.star. Second
> > syntax is not supported by session variables, and then I didn't try to
> search for the variable.
> > Some users can be confused by similar syntaxes identifier.* and
> (identifier).* Only
> > second syntax is composite unboxing, and only second syntax is supported
> for
> > session variables.
> >
> > Maybe the note about unboxing is messy there?
> >
> >> add
> >> `elog(INFO, "%s:%d called", __FILE__, __LINE__); ` within the ELSE
> branch.
> >> Then I found out the ELSE branch doesn't have coverage tests.
> >
> >
> > I don't understand this comment? I don't use elog(INFO anywhere
> >
> >
>
> sorry for confusion, i mean,
> i added " elog(INFO", the regress test is still successful,
> therefore it means the above ELSE branch code doesn't have coverage tests.
>

yes, force this case can be little bit tricky

a) the variable should not be shadowed,
or session_variables_ambiguity_warning should be on
b) the transformColumnRef should be executed and the star symbol should be
in the list - it is possible for aggregate functions

SELECT count(v.*) FROM foo

I wrote requested regress tests

Regards

Pavel

Attachment Content-Type Size
v20241229-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20241229-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20241229-0021-transactional-variables.patch text/x-patch 37.3 KB
v20241229-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.1 KB
v20241229-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20241229-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20241229-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20241229-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20241229-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.0 KB
v20241229-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20241229-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20241229-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20241229-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20241229-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20241229-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20241229-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20241229-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20241229-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20241229-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20241229-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20241229-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 155.5 KB
v20241229-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 167.3 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-02 06:46:06
Message-ID: CAFj8pRAzFCbTwqjaEvkvB0VBa9ofSEYxnv8wM3pHZTGtrRK0yQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fresh rebase + update year in copyright lines

Regards

Pavel

Attachment Content-Type Size
v20250102-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250102-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250102-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250102-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250102-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250102-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20250102-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250102-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250102-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250102-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250102-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250102-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250102-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250102-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250102-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20250102-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250102-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250102-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250102-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250102-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20250102-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 155.6 KB
v20250102-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 167.5 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-03 07:18:22
Message-ID: CACJufxFwxAvJL944UQKwxV1YuM3GQNTbPRQ6LwtioSKBfpMN2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

in the function svariableStartupReceiver all these "ereport(ERROR"
cannot happen,
since transformLetStmt already did all the heavy work.
base on https://www.postgresql.org/docs/current/error-message-reporting.html
all these "ereport(ERROR," in the svariableStartupReceiver can be
simplified as "elog(ERROR,"
or Assert.

After standard_ExecutorStart->InitPlan, queryDesc.tupDesc will not
include attr->attisdropped is true scarenio.
In standard_ExecutorStart, I added the following code then ran the
regress test again to prove my point.

standard_ExecutorStart
/*
* Initialize the plan state tree
*/
InitPlan(queryDesc, eflags);
for (int i = 0; i < queryDesc->tupDesc->natts; i++)
{
Form_pg_attribute attr = TupleDescAttr(queryDesc->tupDesc, i);
if (attr->attisdropped)
{
elog(INFO, "some attribute is dropped queryDesc->operation
is %d", queryDesc->operation);
}
}
MemoryContextSwitchTo(oldcontext);
-------------------------
svariableStartupReceiver parameter typeinfo is from queryDesc->tupDesc
So I think svariableStartupReceiver, typeinfo->natts will always equal one.
therefore SVariableState.slot_offset is not necessary.

overall, i think svariableStartupReceiver can be simplified as the following:

static void
svariableStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
{
SVariableState *myState = (SVariableState *) self;
int natts = typeinfo->natts;
Form_pg_attribute attr;
LOCKTAG locktag PG_USED_FOR_ASSERTS_ONLY;
Assert(myState->pub.mydest == DestVariable);
Assert(OidIsValid(myState->varid));
Assert(SearchSysCacheExists1(VARIABLEOID, myState->varid));
#ifdef USE_ASSERT_CHECKING
SET_LOCKTAG_OBJECT(locktag,
MyDatabaseId,
VariableRelationId,
myState->varid,
0);
Assert(LockHeldByMe(&locktag, AccessShareLock, false));
#endif
Assert(natts == 1);
attr = TupleDescAttr(typeinfo, 0);
myState->need_detoast = attr->attlen == -1;
myState->rows = 0;
}

I've attached the file containing the changes I mentioned earlier.

-------------------------<<>>>-------------------------------
Overall, 0001 and 0002 the doc looks good to me now.
The following are only some minor issues I came up with.

In Table 5.1. ACL Privilege Abbreviations
<table id="privilege-abbrevs-table">
<title><acronym>ACL</acronym> Privilege Abbreviations</title>

<literal>VARIABLE</literal> (occurred 3 times)
should be
<literal>SESSION VARIABLE</literal>
?

doc/src/sgml/glossary.sgml
I want to do minor tweak. from
<para>
A persistent database object that holds a value in session memory. This
value is private to each session and is released when the session ends.
Read or write access to session variables is controlled by privileges,
similar to other database objects.
</para>
to
<para>
A persistent database object that holds a value in session memory. This
value is private to each session and is reset to default value
(null) when the session ends.
Read or write access to session variables is controlled by access
privileges,
similar to other database objects.
</para>

in let.sgml.
<para>
Example:
<programlisting>
CREATE VARIABLE myvar AS integer;
LET myvar = 10;
LET myvar = (SELECT sum(val) FROM tab);
</programlisting>
</para>

it should be
<refsect1>
<title>Examples</title>
...your example code
</refsect1>

Attachment Content-Type Size
v1-0001-refactoring-svariableStartupReceiver.no-cfbot application/octet-stream 3.8 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-03 22:59:30
Message-ID: CAFj8pRAVoWzkx8Y3or-frYwszyLSjxzs9jYTm3rx00qN+21ZHg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

pá 3. 1. 2025 v 8:18 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> in the function svariableStartupReceiver all these "ereport(ERROR"
> cannot happen,
> since transformLetStmt already did all the heavy work.
> base on
> https://www.postgresql.org/docs/current/error-message-reporting.html
> all these "ereport(ERROR," in the svariableStartupReceiver can be
> simplified as "elog(ERROR,"
> or Assert.
>
>
> After standard_ExecutorStart->InitPlan, queryDesc.tupDesc will not
> include attr->attisdropped is true scarenio.
> In standard_ExecutorStart, I added the following code then ran the
> regress test again to prove my point.
>
> standard_ExecutorStart
> /*
> * Initialize the plan state tree
> */
> InitPlan(queryDesc, eflags);
> for (int i = 0; i < queryDesc->tupDesc->natts; i++)
> {
> Form_pg_attribute attr = TupleDescAttr(queryDesc->tupDesc, i);
> if (attr->attisdropped)
> {
> elog(INFO, "some attribute is dropped queryDesc->operation
> is %d", queryDesc->operation);
> }
> }
> MemoryContextSwitchTo(oldcontext);
> -------------------------
> svariableStartupReceiver parameter typeinfo is from queryDesc->tupDesc
> So I think svariableStartupReceiver, typeinfo->natts will always equal one.
> therefore SVariableState.slot_offset is not necessary.
>

It is true. The syntax allows just `expression` or `(subquery)`, and all
dirty work does execution of subquery

>
> overall, i think svariableStartupReceiver can be simplified as the
> following:
>
> static void
> svariableStartupReceiver(DestReceiver *self, int operation, TupleDesc
> typeinfo)
> {
> SVariableState *myState = (SVariableState *) self;
> int natts = typeinfo->natts;
> Form_pg_attribute attr;
> LOCKTAG locktag PG_USED_FOR_ASSERTS_ONLY;
> Assert(myState->pub.mydest == DestVariable);
> Assert(OidIsValid(myState->varid));
> Assert(SearchSysCacheExists1(VARIABLEOID, myState->varid));
> #ifdef USE_ASSERT_CHECKING
> SET_LOCKTAG_OBJECT(locktag,
> MyDatabaseId,
> VariableRelationId,
> myState->varid,
> 0);
> Assert(LockHeldByMe(&locktag, AccessShareLock, false));
> #endif
> Assert(natts == 1);
> attr = TupleDescAttr(typeinfo, 0);
> myState->need_detoast = attr->attlen == -1;
> myState->rows = 0;
> }
>

done + regress tests

>
> I've attached the file containing the changes I mentioned earlier.
>
> -------------------------<<>>>-------------------------------
> Overall, 0001 and 0002 the doc looks good to me now.
> The following are only some minor issues I came up with.
>
> In Table 5.1. ACL Privilege Abbreviations
> <table id="privilege-abbrevs-table">
> <title><acronym>ACL</acronym> Privilege Abbreviations</title>
>
> <literal>VARIABLE</literal> (occurred 3 times)
> should be
> <literal>SESSION VARIABLE</literal>
> ?
>

changed

>
> doc/src/sgml/glossary.sgml
> I want to do minor tweak. from
> <para>
> A persistent database object that holds a value in session memory.
> This
> value is private to each session and is released when the session
> ends.
> Read or write access to session variables is controlled by privileges,
> similar to other database objects.
> </para>
> to
> <para>
> A persistent database object that holds a value in session memory.
> This
> value is private to each session and is reset to default value
> (null) when the session ends.
> Read or write access to session variables is controlled by access
> privileges,
> similar to other database objects.
> </para>
>

I think the sentence "and is reset to default value (null) when the
session ends" is a little bit misguided. The memory is
really released. I changed it to

A persistent database object that holds a value in session memory.
This
value is private to each session and is released when the session ends.
The default value of the session variable is null. Read or write
access
to session variables is controlled by privileges, similar to other
database
objects.

> in let.sgml.
> <para>
> Example:
> <programlisting>
> CREATE VARIABLE myvar AS integer;
> LET myvar = 10;
> LET myvar = (SELECT sum(val) FROM tab);
> </programlisting>
> </para>
>
> it should be
> <refsect1>
> <title>Examples</title>
> ...your example code
> </refsect1>
>

done

Regards

Pavel

Attachment Content-Type Size
v20250103-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250103-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250103-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250103-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250103-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250103-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20250103-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250103-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250103-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250103-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250103-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250103-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250103-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250103-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20250103-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250103-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250103-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250103-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20250103-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250103-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250103-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 158.5 KB
v20250103-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 167.5 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-04 05:36:56
Message-ID: CAFj8pRDhpDwWrV7DbwoGz=-i3yesEU1oooYyMErQfjMXKw=pOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix typo

Regards

Pavel

Attachment Content-Type Size
v20250104-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250104-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250104-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250104-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250104-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250104-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 11.9 KB
v20250104-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250104-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250104-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250104-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250104-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250104-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250104-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250104-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20250104-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250104-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250104-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250104-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250104-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20250104-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250104-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 158.5 KB
v20250104-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 167.5 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-05 04:52:15
Message-ID: CACJufxGdRAF=e57W3yd1cTrspB2bucnsr6ZfYY=bs+bfJWdRPw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index 9c2957eb546..624858db301 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -361,6 +361,9 @@ typedef struct Const
* of the `paramid' field contain the SubLink's subLinkId, and
* the low-order 16 bits contain the column number. (This type
* of Param is also converted to PARAM_EXEC during planning.)
+ *
+ * PARAM_VARIABLE: The parameter is a reference to a session variable
+ * (paramid holds the variable's OID).
*/
typedef enum ParamKind
{
@@ -368,6 +371,7 @@ typedef enum ParamKind
PARAM_EXEC,
PARAM_SUBLINK,
PARAM_MULTIEXPR,
+ PARAM_VARIABLE,
} ParamKind;

typedef struct Param
@@ -380,6 +384,10 @@ typedef struct Param
int32 paramtypmod pg_node_attr(query_jumble_ignore);
/* OID of collation, or InvalidOid if none */
Oid paramcollid pg_node_attr(query_jumble_ignore);
+ /* OID of session variable if it is used */
+ Oid paramvarid;
+ /* true when param is used like base node of assignment indirection */
+ bool parambasenode;
/* token location, or -1 if unknown */
ParseLoc location;
} Param;

comment should be "(paramvarid holds the variable's OID)"
also
+ /* true when param is used like base node of assignment indirection */
is kind of hard to understand.
param->parambasenode = true;
only happens in transformLetStmt so we can change it to
+ /* true when param is used in part of the LET statement.*/

--- a/src/include/executor/execdesc.h
+++ b/src/include/executor/execdesc.h
@@ -51,6 +51,10 @@ typedef struct QueryDesc
/* This field is set by ExecutePlan */
bool already_executed; /* true if previously executed */

+ /* reference to session variables buffer */
+ int num_session_variables;
+ SessionVariableValue *session_variables;
+
/* This is always set NULL by the core system, but plugins can change it */
struct Instrumentation *totaltime; /* total time spent in ExecutorRun */
} QueryDesc;
QueryDesc->num_session_variables and
QueryDesc->session_variables are never used in 0001 and 0002.
it may be used in later patches,
but at least 0001 and 0002, we don't need to change
struct QueryDesc?

contrib/postgres_fdw/deparse.c
There are some cases of "case T_Param:"
do we need to do something on it?
also on src/backend/nodes/queryjumblefuncs.c, one
appearance of "case T_Param:". (but it seems no need change here)

CREATE VARIABLE v1 AS int;
CREATE VARIABLE v2 AS int;
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
select count(*) from tenk1 where unique1 = v1;
select count(*) from tenk1 where unique1 = v2;

should the last two queries be normalized as one query in pg_stat_statements?
if so, then maybe in typedef struct Param
we need change to:
Oid paramvarid pg_node_attr(query_jumble_ignore);
but then
let v1 = v1+1;
let v1 = v2+1;
will be normalized as one query.


From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-05 16:10:37
Message-ID: CACJufxG6tFo1uOtTPoUw0ntzHddahd7EmR37DhsxMXxUixPaeQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

+ /*
+ * The arguments of EXECUTE are evaluated by a direct expression
+ * executor call. This mode doesn't support session variables yet.
+ * It will be enabled later.
+ */
+ if (pstate->p_hasSessionVariables)
+ elog(ERROR, "session variable cannot be used as an argument");

it should be:
/*
* The arguments of CALL statement are evaluated by a direct expression
* executor call. This path is unsupported yet, so block it.
*/
if (pstate->p_hasSessionVariables)
ereport(ERROR,
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("session variable cannot be used as an argument"));

similarly, EvaluateParams we can change it to
/*
* The arguments of EXECUTE are evaluated by a direct expression
* executor call. This mode doesn't support session variables yet.
* It will be enabled later.
*/
if (pstate->p_hasSessionVariables)
ereport(ERROR,
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("session variable cannot be used as an argument"));

in src/backend/executor/execExpr.c
we don't need
+#include "catalog/pg_variable.h"
?


From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-06 07:58:36
Message-ID: CACJufxG7Mc2PK2B7+vkdDxvrsJNN3r+cpzvAFTZZXKnWZOcG6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

comment out the changes in
src/backend/utils/cache/plancache.c

// /* process session variables */
// if (OidIsValid(parsetree->resultVariable))
// {
// if (acquire)
// LockDatabaseObject(VariableRelationId, parsetree->resultVariable,
// 0, AccessShareLock);
// else
// UnlockDatabaseObject(VariableRelationId,
parsetree->resultVariable,
// 0, AccessShareLock);
// }

// else if (IsA(node, Param))
// {
// Param *p = (Param *) node;
// if (p->paramkind == PARAM_VARIABLE)
// {
// if (acquire)
// LockDatabaseObject(VariableRelationId, p->paramvarid,
// 0, AccessShareLock);
// else
// UnlockDatabaseObject(VariableRelationId, p->paramvarid,
// 0, AccessShareLock);
// }
// }
the regress tests are still successful, that means these code changes
don't have related tests.

SetSessionVariable(Oid varid, Datum value, bool isNull)
{
create_sessionvars_hashtables();
svar = (SVariable) hash_search(sessionvars, &varid, HASH_ENTER, &found);
if (!found)
setup_session_variable(svar, varid);
/* if this fails, it won't change the stored value */
set_session_variable(svar, value, isNull);
}
after set_session_variable,
we want to make sure that svar->is_valid is true,
svar->value = value and svar->isnull= isNull.
Based on this, I've simplified the function set_session_variable,
refer v1-0001-minor-refactoring-set_session_variable.no-cfbot

we use PlannerGlobal
{
Oid basenodeSessionVarid;
Bitmapset *checkSelectPermVarids;
}
to solve the self-assigned corner case SELECT privilege.
(let v1.a =v1.a; in this case, we need have SELECT priv for v1.a
but let v1.a = 1, we don't need SELECT priv for v1.a).

i found out these two field value(information) most case is the same
as PlannerGlobal.sessionVariables;
I came up with another solution, introduce a bool (Query.is_Variable_assigned),
and get rid of PlannerGlobal.basenodeSessionVarid,
PlannerGlobal.checkSelectPermVarids.
not sure it make sense to you, refer
v1-0002-refactoring-LET-statement-self-assign-privileg.no-cfbot

Attachment Content-Type Size
v1-0001-minor-refactoring-set_session_variable.no-cfbot application/octet-stream 2.1 KB
v1-0002-refactoring-LET-statement-self-assign-privileg.no-cfbot application/octet-stream 4.5 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-06 08:39:39
Message-ID: CAFj8pRC4ec6mZPR-Wn8mAtVPURm0SWHtCbLGu=9av3JmwqvgOg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

ne 5. 1. 2025 v 5:52 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
> index 9c2957eb546..624858db301 100644
> --- a/src/include/nodes/primnodes.h
> +++ b/src/include/nodes/primnodes.h
> @@ -361,6 +361,9 @@ typedef struct Const
> * of the `paramid' field contain the SubLink's subLinkId, and
> * the low-order 16 bits contain the column number. (This type
> * of Param is also converted to PARAM_EXEC during planning.)
> + *
> + * PARAM_VARIABLE: The parameter is a reference to a session variable
> + * (paramid holds the variable's OID).
> */
> typedef enum ParamKind
> {
> @@ -368,6 +371,7 @@ typedef enum ParamKind
> PARAM_EXEC,
> PARAM_SUBLINK,
> PARAM_MULTIEXPR,
> + PARAM_VARIABLE,
> } ParamKind;
>
> typedef struct Param
> @@ -380,6 +384,10 @@ typedef struct Param
> int32 paramtypmod pg_node_attr(query_jumble_ignore);
> /* OID of collation, or InvalidOid if none */
> Oid paramcollid pg_node_attr(query_jumble_ignore);
> + /* OID of session variable if it is used */
> + Oid paramvarid;
> + /* true when param is used like base node of assignment indirection */
> + bool parambasenode;
> /* token location, or -1 if unknown */
> ParseLoc location;
> } Param;
>
> comment should be "(paramvarid holds the variable's OID)"
> also
> + /* true when param is used like base node of assignment indirection */
> is kind of hard to understand.
> param->parambasenode = true;
> only happens in transformLetStmt so we can change it to
> + /* true when param is used in part of the LET statement.*/
>

I don't think the proposed change of comment is better, but the text
can be extended.

<-->/*
<--> * true if param is used as base node of assignment indirection
<--> * (when target of LET statement is an array field or an record field).
<--> * For this param we do not check SELECT access right, because this
<--> * param is used just for execution of UPDATE operation.
<--> */

>
>
> --- a/src/include/executor/execdesc.h
> +++ b/src/include/executor/execdesc.h
> @@ -51,6 +51,10 @@ typedef struct QueryDesc
> /* This field is set by ExecutePlan */
> bool already_executed; /* true if previously executed */
>
> + /* reference to session variables buffer */
> + int num_session_variables;
> + SessionVariableValue *session_variables;
> +
> /* This is always set NULL by the core system, but plugins can change it
> */
> struct Instrumentation *totaltime; /* total time spent in ExecutorRun */
> } QueryDesc;
> QueryDesc->num_session_variables and
> QueryDesc->session_variables are never used in 0001 and 0002.
> it may be used in later patches,
> but at least 0001 and 0002, we don't need to change
> struct QueryDesc?
>
>
moved to patch 17

> contrib/postgres_fdw/deparse.c
> There are some cases of "case T_Param:"
> do we need to do something on it?
>

I think so session variables cannot be executed remotely, and then do
nothing there it is correct.

> also on src/backend/nodes/queryjumblefuncs.c, one
> appearance of "case T_Param:". (but it seems no need change here)
>

CREATE VARIABLE v1 AS int;
> CREATE VARIABLE v2 AS int;
> SELECT pg_stat_statements_reset() IS NOT NULL AS t;
> select count(*) from tenk1 where unique1 = v1;
> select count(*) from tenk1 where unique1 = v2;
>
> should the last two queries be normalized as one query in
> pg_stat_statements?
> if so, then maybe in typedef struct Param
> we need change to:
> Oid paramvarid pg_node_attr(query_jumble_ignore);
>

changed

In this case for this moment we can try to be consistent with plpgsql
variables. So I did it

but then
> let v1 = v1+1;
> let v1 = v2+1;
> will be normalized as one query.
>

yes, but this case is not too important, because at the end (I hope), this
statement inside plpgsql will be executed as
simple expression, and then it will not be processed by pg_stat_statements


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-06 10:01:17
Message-ID: CAFj8pRBFpVZ7ZpB9G5MkePVFGHFRuq6b_iRufTg2HibX5hnzRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

ne 5. 1. 2025 v 17:11 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> + /*
> + * The arguments of EXECUTE are evaluated by a direct expression
> + * executor call. This mode doesn't support session variables yet.
> + * It will be enabled later.
> + */
> + if (pstate->p_hasSessionVariables)
> + elog(ERROR, "session variable cannot be used as an argument");
>
> it should be:
> /*
> * The arguments of CALL statement are evaluated by a direct expression
> * executor call. This path is unsupported yet, so block it.
> */
> if (pstate->p_hasSessionVariables)
> ereport(ERROR,
> errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> errmsg("session variable cannot be used as an argument"));
>
> done

>
> similarly, EvaluateParams we can change it to
> /*
> * The arguments of EXECUTE are evaluated by a direct expression
> * executor call. This mode doesn't support session variables yet.
> * It will be enabled later.
> */
> if (pstate->p_hasSessionVariables)
> ereport(ERROR,
> errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> errmsg("session variable cannot be used as an argument"));
>

done

>
> in src/backend/executor/execExpr.c
> we don't need
> +#include "catalog/pg_variable.h"
> ?
>

moved to patch 16


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-06 12:21:09
Message-ID: CAFj8pRAF8W6Sn91UH9gPtOV4ss99D0et+yvnQf=v0n=85KhWXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 6. 1. 2025 v 8:59 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> comment out the changes in
> src/backend/utils/cache/plancache.c
>
> // /* process session variables */
> // if (OidIsValid(parsetree->resultVariable))
> // {
> // if (acquire)
> // LockDatabaseObject(VariableRelationId,
> parsetree->resultVariable,
> // 0, AccessShareLock);
> // else
> // UnlockDatabaseObject(VariableRelationId,
> parsetree->resultVariable,
> // 0, AccessShareLock);
> // }
>
> // else if (IsA(node, Param))
> // {
> // Param *p = (Param *) node;
> // if (p->paramkind == PARAM_VARIABLE)
> // {
> // if (acquire)
> // LockDatabaseObject(VariableRelationId, p->paramvarid,
> // 0, AccessShareLock);
> // else
> // UnlockDatabaseObject(VariableRelationId, p->paramvarid,
> // 0, AccessShareLock);
> // }
> // }
> the regress tests are still successful, that means these code changes
> don't have related tests.
>

the locking is tested by isolation test in patch05

>
>
> SetSessionVariable(Oid varid, Datum value, bool isNull)
> {
> create_sessionvars_hashtables();
> svar = (SVariable) hash_search(sessionvars, &varid, HASH_ENTER,
> &found);
> if (!found)
> setup_session_variable(svar, varid);
> /* if this fails, it won't change the stored value */
> set_session_variable(svar, value, isNull);
> }
> after set_session_variable,
> we want to make sure that svar->is_valid is true,
> svar->value = value and svar->isnull= isNull.
> Based on this, I've simplified the function set_session_variable,
> refer v1-0001-minor-refactoring-set_session_variable.no-cfbot
>

Unfortunately, I don't think it is possible. See comments

/*
* Assign a new value to the session variable. It is copied to
* SVariableMemoryContext if necessary.
*
* **** If any error happens, the existing value won't be modified. ****
*/

So the variable cannot be released before memory for new content is
allocated

The current code is a little bit more complex, but significantly reduces
the risk so the variable will hold unexpected value.

The current code ensures stability of LET command - when it is successful,
then value is changed, or when it is not successful, then variable is not
changed.

Proposed code breaks it. There is risk of palloc exception, and that means,
after unsuccessful LET the variable can be initialized. So there are three
ending states, not just two.

pfree theoretically can raise an exception, but in this case it should be
code our design error (using wrong allocator)

>
> we use PlannerGlobal
> {
> Oid basenodeSessionVarid;
> Bitmapset *checkSelectPermVarids;
> }
> to solve the self-assigned corner case SELECT privilege.
> (let v1.a =v1.a; in this case, we need have SELECT priv for v1.a
> but let v1.a = 1, we don't need SELECT priv for v1.a).
>
> i found out these two field value(information) most case is the same
> as PlannerGlobal.sessionVariables;
> I came up with another solution, introduce a bool
> (Query.is_Variable_assigned),
> and get rid of PlannerGlobal.basenodeSessionVarid,
> PlannerGlobal.checkSelectPermVarids.
> not sure it make sense to you, refer
> v1-0002-refactoring-LET-statement-self-assign-privileg.no-cfbot
>

It is true, so bitmapset checkSelectPermVarids contains almost all the same
data like sessionVariables.
But checkSelectPermVarids allows fast checking if a variable is used
already, and sessionVariables list ensures necessary order.

My implementation needs more memory (one bitmapset), but I think it is very
simple and less error prone (doesn't depend on iteration order).

In this case and this moment I prefer my bitmapset based solution. It can
be optimized maybe later - I thought about a dedicated item in
sessionVariables for the basenode parameter.
This should be a clear winner for value passed types, but for varlena types
(for long varlena types), it can force passing content of some session
variable twice.

Regards

Pavel

Attachment Content-Type Size
v20250106-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250106-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250106-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250106-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250106-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250106-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 13.1 KB
v20250106-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.9 KB
v20250106-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250106-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250106-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250106-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250106-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250106-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250106-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20250106-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250106-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250106-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250106-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20250106-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250106-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250106-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 157.4 KB
v20250106-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 167.5 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-06 19:10:12
Message-ID: CAFj8pRD67R73TcbN9sShbKLdtoLGRsM8GJVC_OqY=EWe3sJ1xw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

>
>>
>> we use PlannerGlobal
>> {
>> Oid basenodeSessionVarid;
>> Bitmapset *checkSelectPermVarids;
>> }
>> to solve the self-assigned corner case SELECT privilege.
>> (let v1.a =v1.a; in this case, we need have SELECT priv for v1.a
>> but let v1.a = 1, we don't need SELECT priv for v1.a).
>>
>> i found out these two field value(information) most case is the same
>> as PlannerGlobal.sessionVariables;
>> I came up with another solution, introduce a bool
>> (Query.is_Variable_assigned),
>> and get rid of PlannerGlobal.basenodeSessionVarid,
>> PlannerGlobal.checkSelectPermVarids.
>> not sure it make sense to you, refer
>> v1-0002-refactoring-LET-statement-self-assign-privileg.no-cfbot
>>
>
> It is true, so bitmapset checkSelectPermVarids contains almost all the
> same data like sessionVariables.
> But checkSelectPermVarids allows fast checking if a variable is used
> already, and sessionVariables list ensures necessary order.
>
> My implementation needs more memory (one bitmapset), but I think it is
> very simple and less error prone (doesn't depend on iteration order).
>
> In this case and this moment I prefer my bitmapset based solution. It can
> be optimized maybe later - I thought about a dedicated item in
> sessionVariables for the basenode parameter.
> This should be a clear winner for value passed types, but for varlena
> types (for long varlena types), it can force passing content of some
> session variable twice.
>

I found so storing oid to bitmapset can have big memory overhead. Bitmapset
with one oid value like 16000 has about 2kB. So instead storing varid, I
try to store paramid. paramid starts by zero.
See patch 03. Now the overhead of the usage of bitmapset for calculation of
the variable excluded from SELECT acl check has tens bytes overhead.

Regards

Pavel

>
> Regards
>
> Pavel
>
>
>
>
>
>

Attachment Content-Type Size
v20250106-0023-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250106-0022-transactional-variables.patch text/x-patch 37.3 KB
v20250106-0021-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250106-0020-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250106-0019-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250106-0018-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 13.1 KB
v20250106-0017-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.9 KB
v20250106-0015-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250106-0016-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250106-0014-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250106-0012-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250106-0013-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250106-0011-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250106-0009-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250106-0010-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.2 KB
v20250106-0008-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250106-0007-plpgsql-tests.patch text/x-patch 16.9 KB
v20250106-0006-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20250106-0004-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250106-0005-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250106-0003-use-bitmapset-of-parid-instead-of-varid-for-calculat.patch text/x-patch 5.4 KB
v20250106-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 157.4 KB
v20250106-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 167.5 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-07 09:07:22
Message-ID: CACJufxHvmagrYNO8rjAd85c8aHzs3cZpiPBiyBjNDUK8GaA6Zg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

some minor issues.
'transformMergeStmt also needs
"qry->hasSessionVariables = pstate->p_hasSessionVariables;"
?

<function>acldefault</function> in doc/src/sgml/func.sgml
Need an update for SESSION VARIABLE?

Table 9.70. Access Privilege Inquiry Functions
sorting order: has_session_variable_privilege should after has_server_privilege?

Similar to src/test/regress/sql/event_trigger.sql,
we can use the following query to test four functions in
Table 9.79. Object Information and Addressing Functions
(9.27.5. Object Information and Addressing Functions)
for session variables.

SELECT
e.varname,
pg_describe_object('pg_variable'::regclass, e.oid, 0) as descr,
b.type, b.object_names, b.object_args,
pg_identify_object(a.classid, a.objid, a.objsubid) as ident
FROM pg_variable as e,
LATERAL pg_identify_object_as_address('pg_variable'::regclass, e.oid, 0) as b,
LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a;

in function transformColumnRef
if (expr_kind_allows_session_variables(pstate->p_expr_kind))
{
}
can change to
if (!node &&
!(relname && crerr == CRERR_NO_COLUMN) &&
expr_kind_allows_session_variables(pstate->p_expr_kind))
{
}
can reduce the function call of expr_kind_allows_session_variables,
also not lose readability.

typedef struct SVariableData says:
/*
* Stored value and type description can be outdated when we receive a
* sinval message. We then have to check if the stored data are still
* trustworthy.
*/
bool is_valid;

CREATE VARIABLE var3 AS int;
LET var3 = 10;
GRANT SELECT ON VARIABLE var3 TO regress_noowner;
I don't understand why the last statement GRANT SELECT needs to call
pg_variable_cache_callback?
and it will invalidate the original var3.

+/*
+ * Returns a copy of the value of the session variable (in the current memory
+ * context). The caller is responsible for permission checks.
+ */
+Datum
+GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
+{
+ SVariable svar;
+
+ svar = get_session_variable(varid);
+
+ /*
+ * Although "svar" is freshly validated in this point, svar->is_valid can
+ * be false, if an invalidation message ws processed during the domain check.
+ * But the variable and all its dependencies are locked now, so we don't need
+ * to repeat the validation.
+ */
+ Assert(svar);
+
+ *typid = svar->typid;
+
+ return copy_session_variable_value(svar, isNull);
+}
typo, "ws processed" should be "was processed".
also the Assert is not helpful? since svar is NULL,
get_session_variable would have segfault.
also SVariable svar; is not initialized to NULL, so generally it will
not be NULL by default.
also the comments seem to imply that before
copy_session_variable_value, svar->is_valid can be false.
if svar->is_valid is false, then why do copy_session_variable_value.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-07 21:21:38
Message-ID: CAFj8pRDtxmQ62FfRBxdTkLwFiGJeRcgSNaRFc+whRbBG3gHb3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

út 7. 1. 2025 v 10:07 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> some minor issues.
> 'transformMergeStmt also needs
> "qry->hasSessionVariables = pstate->p_hasSessionVariables;"
> ?
>
>
yes, done

>
> <function>acldefault</function> in doc/src/sgml/func.sgml
> Need an update for SESSION VARIABLE?
>
> Table 9.70. Access Privilege Inquiry Functions
> sorting order: has_session_variable_privilege should after
> has_server_privilege?
>
>
swapped

>
> Similar to src/test/regress/sql/event_trigger.sql,
> we can use the following query to test four functions in
> Table 9.79. Object Information and Addressing Functions
> (9.27.5. Object Information and Addressing Functions)
> for session variables.
>
> SELECT
> e.varname,
> pg_describe_object('pg_variable'::regclass, e.oid, 0) as descr,
> b.type, b.object_names, b.object_args,
> pg_identify_object(a.classid, a.objid, a.objsubid) as ident
> FROM pg_variable as e,
> LATERAL pg_identify_object_as_address('pg_variable'::regclass, e.oid, 0)
> as b,
> LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a;
>
>
done

>
> in function transformColumnRef
> if (expr_kind_allows_session_variables(pstate->p_expr_kind))
> {
> }
> can change to
> if (!node &&
> !(relname && crerr == CRERR_NO_COLUMN) &&
> expr_kind_allows_session_variables(pstate->p_expr_kind))
> {
> }
> can reduce the function call of expr_kind_allows_session_variables,
> also not lose readability.
>

In this case, I prefer current code. It is more accented so the code is
related to places where variables are allowed.
+ following patches like GUC-session_variables_ambiguity_warning or
variable-fence-syntax~upport-and-variable-fence-usa
are less invasive and much more readable.

My opinion about it is not extra strong, and surely it can be subjective. I
think the current form is quite well readable
and the proposed change is not significantly better.

>
>
> typedef struct SVariableData says:
> /*
> * Stored value and type description can be outdated when we receive a
> * sinval message. We then have to check if the stored data are still
> * trustworthy.
> */
> bool is_valid;
>
> CREATE VARIABLE var3 AS int;
> LET var3 = 10;
> GRANT SELECT ON VARIABLE var3 TO regress_noowner;
> I don't understand why the last statement GRANT SELECT needs to call
> pg_variable_cache_callback?
> and it will invalidate the original var3.
>

Reason is simple - you did the change of pg_variable. Unfortunately, the
system of system cache invalidation is sometimes too simple and too
aggressive.
Inside pg_variable_cache_callback I cannot identify if a related row in
pg_variable was removed (by another session) or just updated.
Theoretically I can miss the information of what row was touched too.
Important note - invalidation in this case doesn't means so variable or the
value of variable should be thrown. It just means, so before any usage of
the current variable's value, we should recheck our cached data against
fresh syscache. Cache invalidation is relative common in Postgres, but
validation is very quick - just the check of varcreate_lsn

> +/*
> + * Returns a copy of the value of the session variable (in the current
> memory
> + * context). The caller is responsible for permission checks.
> + */
> +Datum
> +GetSessionVariable(Oid varid, bool *isNull, Oid *typid)
> +{
> + SVariable svar;
> +
> + svar = get_session_variable(varid);
> +
> + /*
> + * Although "svar" is freshly validated in this point, svar->is_valid can
> + * be false, if an invalidation message ws processed during the domain
> check.
> + * But the variable and all its dependencies are locked now, so we don't
> need
> + * to repeat the validation.
> + */
> + Assert(svar);
> +
> + *typid = svar->typid;
> +
> + return copy_session_variable_value(svar, isNull);
> +}
> typo, "ws processed" should be "was processed".
>

fixed

> also the Assert is not helpful? since svar is NULL,
> get_session_variable would have segfault.
> also SVariable svar; is not initialized to NULL, so generally it will
> not be NULL by default.
>

assert removed

> also the comments seem to imply that before
> copy_session_variable_value, svar->is_valid can be false.
> if svar->is_valid is false, then why do copy_session_variable_value.
>

When the flag is_valid is true, then we are sure, so the stored value is
valid. When this flag is false, then we are not sure, so this value is
valid. But inside one statement,
and if the variable was locked, then we don't need to repeat validation (if
we did it immediately before), because we are sure, so the related system
catalog should be valid, because it is locked, and then we can safely
return the value. The flag is_valid can be changed any time when we are
using catalog cache - in this case when we do domain check. So although it
can look
weird after execution get_session_variable we can return the correct value,
but the flag is_valid can be false. It doesn't mean, so the current value
is wrong. It means, so the next command
should repeat validation.

In the attached version I rewrote the check if we can or cannot to ACL
SELECT check for variable used as base node of assignment indirection. I
significantly simplified the code - it is based on fact so we know varid of
the base node variable. It should be the same session variable like
resultVariable. Then I don't need to use bitmapset of used session
variables. Just I can check if this variable is used by param that is not
basenode param.

Regards

Pavel

Attachment Content-Type Size
v20250107-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250107-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250107-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250107-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250107-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250107-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 13.1 KB
v20250107-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.9 KB
v20250107-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250107-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250107-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250107-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250107-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250107-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250107-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250107-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250107-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.2 KB
v20250107-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250107-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 21.0 KB
v20250107-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250107-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250107-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 158.1 KB
v20250107-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.7 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-08 09:31:11
Message-ID: CACJufxGgOjRcAGw83grK=EcBbjHGOxUYEKKzquz8bWjKJ0aBwQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

you forgot change
<function>acldefault</function>
should add
'V' for <literal>SESSION VARIABLE</literal>

in doc/src/sgml/ddl.sgml
<sect1 id="ddl-session-variables">
maybe some examples (<programlisting>) of session variables being
shadowed would be great.

because doc/src/sgml/ref/create_variable.sgml said
<note>
<para>
Session variables can be <quote>shadowed</quote> by other identifiers.
For details, see <xref linkend="ddl-session-variables"/>.
</para>
</note>
If I click the link, then in ddl.sgml, there is also a bunch of text
saying that variable will be shadowed
in some situations, but there are no simple examples to demonstrate that.

"Create an date session variable <literal>var1</literal>:"
maybe it should be rephrased as
"Create a session variable <literal>var1</literal> as date data type?"
(i am not native english speaker)

-----------------------------------------------------------------------
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -379,7 +379,8 @@ typedef struct Param
Expr xpr;
ParamKind paramkind; /* kind of parameter.
See above */
int paramid; /* numeric ID
for parameter */
- Oid paramtype; /* pg_type OID
of parameter's datatype */
+ /* pg_type OID of parameter's datatype */
+ Oid paramtype
pg_node_attr(query_jumble_ignore);

I think we need the above to make
select v2;
select v1;
normalized as one query.
-----------------------------------------------------------------------
when we create a new table, we do something like this:
DefineRelation
heap_create_with_catalog
GetNewRelFileNumber
GetNewOidWithIndex

relation Oid uniqueness and variable uniqueness is the same thing.
If variable oid uniqueness problem ever reached,
at that moment, we should care more about relation oid uniqueness problem?

and in GetNewRelFileNumber, we have comments:
""
* As with GetNewOidWithIndex(), there is some theoretical risk of a race
* condition, but it doesn't seem worth worrying about.
"""
also comments in GetNewOidWithIndex
"""
* Note that we are effectively assuming that the table has a relatively small
* number of entries (much less than 2^32) and there aren't very long runs of
* consecutive existing OIDs. This is a mostly reasonable assumption for
* system catalogs.
"""
that means pg_catalog.pg_variable.varcreate_lsn is not really necessary?
-----------------------------------------------------------------------
I think the latest patch for LET self assign ACL SELECT is not correct,
previously I also tried the same idea.

test demo.
CREATE TYPE vartest_t1 AS (a int, b int);
CREATE VARIABLE var1 AS vartest_t1;
CREATE ROLE regress_var_test_role;
GRANT UPDATE ON VARIABLE var1 TO regress_var_test_role;
GRANT select ON table tenk1 TO regress_var_test_role;
SET ROLE TO regress_var_test_role;

--both should fail
LET var1.a = var1.a + 10;
LET var1.a = (select * from (select count(*) from tenk1 where unique1
= var1.a + 10));
--------------------------------------------------------


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-08 16:33:31
Message-ID: CAFj8pRBf4DO5yaWe8Md5v+PtOE3ZB=6yjO16eRt7Nn4uXJ56gQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

st 8. 1. 2025 v 10:31 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> you forgot change
> <function>acldefault</function>
> should add
> 'V' for <literal>SESSION VARIABLE</literal>
>

done

>
>
> in doc/src/sgml/ddl.sgml
> <sect1 id="ddl-session-variables">
> maybe some examples (<programlisting>) of session variables being
> shadowed would be great.
>
> because doc/src/sgml/ref/create_variable.sgml said
> <note>
> <para>
> Session variables can be <quote>shadowed</quote> by other identifiers.
> For details, see <xref linkend="ddl-session-variables"/>.
> </para>
> </note>
> If I click the link, then in ddl.sgml, there is also a bunch of text
> saying that variable will be shadowed
> in some situations, but there are no simple examples to demonstrate that.
>

done

>
>
> "Create an date session variable <literal>var1</literal>:"
> maybe it should be rephrased as
> "Create a session variable <literal>var1</literal> as date data type?"
> (i am not native english speaker)
>

changed to

Create a session variable <literal>var1</literal> of data type date

>
> -----------------------------------------------------------------------
> --- a/src/include/nodes/primnodes.h
> +++ b/src/include/nodes/primnodes.h
> @@ -379,7 +379,8 @@ typedef struct Param
> Expr xpr;
> ParamKind paramkind; /* kind of parameter.
> See above */
> int paramid; /* numeric ID
> for parameter */
> - Oid paramtype; /* pg_type OID
> of parameter's datatype */
> + /* pg_type OID of parameter's datatype */
> + Oid paramtype
> pg_node_attr(query_jumble_ignore);
>
> I think we need the above to make
> select v2;
> select v1;
> normalized as one query.
>

Why do you think so? paramtype is PARAM_VARIABLE every time for all session
variables.

If we will ignore paramtype, then we cannot to decide SELECT v1 and SELECT
$1

-----------------------------------------------------------------------
> when we create a new table, we do something like this:
> DefineRelation
> heap_create_with_catalog
> GetNewRelFileNumber
> GetNewOidWithIndex
>
> relation Oid uniqueness and variable uniqueness is the same thing.
> If variable oid uniqueness problem ever reached,
> at that moment, we should care more about relation oid uniqueness problem?
>
> and in GetNewRelFileNumber, we have comments:
> ""
> * As with GetNewOidWithIndex(), there is some theoretical risk of a race
> * condition, but it doesn't seem worth worrying about.
> """
> also comments in GetNewOidWithIndex
> """
> * Note that we are effectively assuming that the table has a relatively
> small
> * number of entries (much less than 2^32) and there aren't very long runs
> of
> * consecutive existing OIDs. This is a mostly reasonable assumption for
> * system catalogs.
> """
> that means pg_catalog.pg_variable.varcreate_lsn is not really necessary?
>

I don't think so. This is a different problem, and different use case (I
think)

oids will always be unique. Any system table has a unique index on the oid
column. It is true for session variables too.

The values of session variables are always in memory. The values of other
database objects are primary in files. Postgres routines never hold
database objects in memory longer than one command or one transaction. And
in this time, the consistency of memory is protected by locks. When the
system drops some database objects, then it drops related files too.
Nothing similar is for session variables. It is a database object that is
forever only in memory, I cannot verify the content against some file.
varcreate_lsn is used instead.

You can imagine scenario:

session A:

CREATE VARIABLE v1 AS int;
-- variable v1 with oid 1 is created

session B:
LET v1 = 100;
PREPARE p AS SELECT v1;

session A:

repeat bin n times:
DROP VARIABLE v1;
CREATE VARIABLE v1 AS numeric;

session b:
there is possibility so there will be variable with varid 1

EXECUTE p --> CRASH

The plan of p will be replaced (due dependency), but without possibility to
check against varcreate_lsn we will use wrong value - possibly with wrong
type, surely with wrong content because related variables were dropped a
long time ago. With varcreate_lsn I can detect that the stored value is
obsolete (although it has the same id).

-----------------------------------------------------------------------
> I think the latest patch for LET self assign ACL SELECT is not correct,
> previously I also tried the same idea.
>
> test demo.
> CREATE TYPE vartest_t1 AS (a int, b int);
> CREATE VARIABLE var1 AS vartest_t1;
> CREATE ROLE regress_var_test_role;
> GRANT UPDATE ON VARIABLE var1 TO regress_var_test_role;
> GRANT select ON table tenk1 TO regress_var_test_role;
> SET ROLE TO regress_var_test_role;
>
> --both should fail
> LET var1.a = var1.a + 10;
> LET var1.a = (select * from (select count(*) from tenk1 where unique1
> = var1.a + 10));
>

fixed + regress test

> --------------------------------------------------------
>

In today's version I changed GetSessionVariable API little bit. Now it
returns only value and *isnull. GetSessionVariableWithTypeCheck is
completely removed. Instead I add
GetSessionVariableWithTypeid, but it is introduced in patch
allow-parallel-execution-queries-with-session-variab.patch. It is not
necessary before. I removed the field varid from structure
SessionVariableValue (execnodes.h) because it was not used everywhere.

Regards

Pavel

Attachment Content-Type Size
v20250108-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250108-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250108-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250108-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20250108-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.1 KB
v20250108-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250108-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250108-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250108-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.0 KB
v20250108-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250108-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250108-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250108-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250108-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250108-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250108-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250108-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250108-0004-DISCARD-VARIABLES.patch text/x-patch 9.5 KB
v20250108-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250108-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250108-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.7 KB
v20250108-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-08 19:00:28
Message-ID: CAFj8pRDTacMXb+UpQSCjwROoQWb0vaujCnXhtOvbx_2hTXgLbA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix after 7b27f5fd36cb3270e8ac25aefd73b552663d1392

Regards

Pavel

Attachment Content-Type Size
v20250108-2-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250108-2-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250108-2-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20250108-2-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250108-2-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250108-2-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250108-2-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250108-2-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250108-2-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.0 KB
v20250108-2-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250108-2-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250108-2-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250108-2-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250108-2-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250108-2-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250108-2-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250108-2-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250108-2-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250108-2-0004-DISCARD-VARIABLES.patch text/x-patch 9.5 KB
v20250108-2-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250108-2-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.7 KB
v20250108-2-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-09 05:57:11
Message-ID: CAFj8pRChgOLa2i0PVu-Zoss4q8k1ojPu_Ax-CksTkOWDTye9pQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

minor change - remove one unwanted whitechar

Regards

Pavel

Attachment Content-Type Size
v20250109-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250109-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250109-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250109-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20250109-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250109-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250109-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250109-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250109-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.0 KB
v20250109-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250109-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250109-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250109-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250109-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250109-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250109-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250109-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250109-0004-DISCARD-VARIABLES.patch text/x-patch 9.5 KB
v20250109-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250109-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250109-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250109-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-15 07:28:13
Message-ID: CAFj8pRCpAV5N9q5q+JenC=MWup2gVCWi7ZkOM4F2mbUT=Bp4UQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

necessary rebase

Regards

Pavel

Attachment Content-Type Size
v20250115-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250115-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20250115-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250115-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250115-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250115-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250115-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.0 KB
v20250115-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250115-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250115-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250115-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250115-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250115-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250115-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250115-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250115-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250115-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250115-0004-DISCARD-VARIABLES.patch text/x-patch 9.5 KB
v20250115-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250115-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250115-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250115-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-17 07:18:20
Message-ID: CAFj8pRCwddC_o1FMyp_mMCyzzuvU7a0f+1X3tHRKmaFhK2K7jw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix oid collision

Regards

Pavel

Attachment Content-Type Size
v20250117-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.1 KB
v20250117-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250117-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250117-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250117-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.2 KB
v20250117-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250117-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250117-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250117-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.0 KB
v20250117-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250117-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250117-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250117-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250117-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250117-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.4 KB
v20250117-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250117-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250117-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250117-0004-DISCARD-VARIABLES.patch text/x-patch 9.5 KB
v20250117-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250117-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250117-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.6 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-17 13:41:51
Message-ID: Z4peH6wnmE9QdGYk@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, Jan 17, 2025 at 08:18:20AM +0100, Pavel Stehule wrote:
> Hi
>
> fix oid collision

What is the purpose of continually posting this patch to the email
lists?

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Do not let urgent matters crowd out time for investment in the future.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-17 13:48:29
Message-ID: CAFj8pRDncxFC+CPy5xoun00uzAOaiyKAkvfby94LfqQuVa4EFA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

pá 17. 1. 2025 v 14:41 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:

> On Fri, Jan 17, 2025 at 08:18:20AM +0100, Pavel Stehule wrote:
> > Hi
> >
> > fix oid collision
>
> What is the purpose of continually posting this patch to the email
> lists?
>

The people still do a review, so I am fixing this patch. I am fixing it
immediately, when I detect an issue.

I can reduce the frequency once per week.

Regards

Pavel

> --
> Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
> EDB https://enterprisedb.com
>
> Do not let urgent matters crowd out time for investment in the future.
>
>
>


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-17 14:16:08
Message-ID: Z4pmKI2yodbDn5vw@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, Jan 17, 2025 at 02:48:29PM +0100, Pavel Stehule wrote:
> Hi
>
> pá 17. 1. 2025 v 14:41 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:
>
> On Fri, Jan 17, 2025 at 08:18:20AM +0100, Pavel Stehule wrote:
> > Hi
> >
> > fix oid collision
>
> What is the purpose of continually posting this patch to the email
> lists?
>
>
> The people still do a review, so I am fixing this patch. I am fixing it
> immediately, when I detect an issue.
>
> I can reduce the frequency once per week.

Is this really something we are considering applying, since it has been
around for years? I am unclear on that and we had better know if we are
going to continue reviewing this.

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Do not let urgent matters crowd out time for investment in the future.


From: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-17 14:47:28
Message-ID: 202501171447.ujcoco7hy4oh@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On 2025-Jan-17, Bruce Momjian wrote:

> Is this really something we are considering applying, since it has been
> around for years? I am unclear on that and we had better know if we are
> going to continue reviewing this.

The fact that the patch has been around for years doesn't automatically
mean it's a bad idea.

I have proposed that we discuss this patch at fosdem developer's meeting
next month, precisely to seek consensus on whether this patch is
something we want or not. My view is that this is a feature that has
been requested by users for years, so IMO we want this or something
similar.

I wonder if the reason that committers stay away from it is that
reviewing it fully (and thus taking responsibility for it) seems such a
daunting task. I might be wrong, but I think this may be the largest
patch since FTS.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Tom: There seems to be something broken here.
Teodor: I'm in sackcloth and ashes... Fixed.
http://postgr.es/m/482D1632.8010507@sigaev.ru


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Fwd: Re: proposal: schema variables
Date: 2025-01-17 15:32:07
Message-ID: CAFj8pRAki6SGw2Dw-73ubQoDY9yPvfUQBjqr_LN35T7YBcsxmQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

pá 17. 1. 2025 v 15:39 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:

> On Fri, Jan 17, 2025 at 03:28:55PM +0100, Pavel Stehule wrote:
> > Dne pá 17. 1. 2025 15:16 uživatel Bruce Momjian <bruce(at)momjian(dot)us>
> napsal:
> > Is this really something we are considering applying, since it has
> been
> > around for years? I am unclear on that and we had better know if we
> are
> > going to continue reviewing this.
> >
> > I hope so it is possible, minimally in some basic form. And i think so
> there
> > was real good progres of quality in last three months.
>
> I am not asking if it is improving. I am asking if it is a desired
> feature; see:
>
> https://wiki.postgresql.org/wiki/Todo#Development_Process
> Desirability -> Design -> Implement -> Test -> Review -> Commit
>
> I am asking if we have had the Desirability discussion, and its outcome,
> because if we can't agree on its Desirability, the other stages are
> useless.
>

This discussion was around 2017 when I wrote a proposal and I hadn't a
feeling so we don't write this feature.
Big discussion was related to whether variables should be transactional or
not. Next the patch was stalled from
two reasons: a) there was not necessary infrastructure for utility
commands, b) I searched for ways to ensure
the validity of the content of variables. I found a good solution at the
end of 2022. It is true, so time has changed
from this time, and Postgres and people are different. In this time the
migration from Oracle was stronger
topic.

If you read all the discussion, you can find more times the sentence so
this can be a good feature (not from me).
Surely the session variables can be implemented differently - minimally
there are four different implementations
mssql, db2, mysql and oracle, and there can be unfinished discussion about
which way is better or if the session
variables are necessary. Yes, we can live without it - we are living
without it, but emulation by GUC is not secure,
so some scenarios are not possible, and others are breakneck with
emulation.

I understand the question if we need it is open still and every time. This
feature is interesting for people who
a) use stored procedures
b) use RLS

Both these groups are not the majority of users. But these people are here.

Btw - EDB supports Oracle way, and Postgres Pro uses extension for
emulation. So there is a real request
for this feature. Common solution for Postgres is using GUC. But there is
no possibility to set access
rights so the workaround cannot be secured.

There is one stronger argument for session variables - we are missing
global temporary tables. It is a real
limit and more times I found users with bloated pg_class, pg_attributes due
using temp tables. I don't believe
so we can have a global temp table - it is a significantly more difficult
task than session variables. At the end
session variables are trivial against global temp tables, and can replace
global temp tables in some use cases.
And the solution can be nicer, cleaner, safer than with a workaround based
on GUC.

Regards

Pavel

>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
> EDB https://enterprisedb.com
>
> Do not let urgent matters crowd out time for investment in the future.
>
>
>


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 15:35:48
Message-ID: Z4p41KpSENxS0ASL@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, Jan 17, 2025 at 04:32:07PM +0100, Pavel Stehule wrote:
> This discussion was around 2017 when I wrote a proposal and I hadn't a feeling

2017 is seven years ago so it would be good to get current feedback on
the desirability of this feature.

> There is one stronger argument for session variables - we are missing global
> temporary tables. It is a real
> limit and more times I found users with bloated pg_class, pg_attributes due
> using temp tables. I don't believe
> so we can have a global temp table - it is a significantly more difficult task
> than session variables. At the end
> session variables are trivial against global temp tables, and can replace
> global temp tables in some use cases.
> And the solution can be nicer, cleaner, safer than with a workaround based on
> GUC.

So this feature would be like global GUC variables, with permission
control?

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Do not let urgent matters crowd out time for investment in the future.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 15:55:07
Message-ID: CAFj8pRCJFQ0UQzZoJRdxv51Vst_emnXMbZtWNv0HTWzeZ0j9Eg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

pá 17. 1. 2025 v 16:35 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:

> On Fri, Jan 17, 2025 at 04:32:07PM +0100, Pavel Stehule wrote:
> > This discussion was around 2017 when I wrote a proposal and I hadn't a
> feeling
>
> 2017 is seven years ago so it would be good to get current feedback on
> the desirability of this feature.
>
> > There is one stronger argument for session variables - we are missing
> global
> > temporary tables. It is a real
> > limit and more times I found users with bloated pg_class, pg_attributes
> due
> > using temp tables. I don't believe
> > so we can have a global temp table - it is a significantly more
> difficult task
> > than session variables. At the end
> > session variables are trivial against global temp tables, and can replace
> > global temp tables in some use cases.
> > And the solution can be nicer, cleaner, safer than with a workaround
> based on
> > GUC.
>
> So this feature would be like global GUC variables, with permission
> control?
>

+ types and domain type check - holds data in binary form - there are not
conversions binary, text
+ it is declared - so less space for misuse is there. Custom GUC are
absolutely tolerant
+ it is a fully database object, only owner can alter it, and event
triggers are supported, sinval
+ possibility to set mutability, default value

Regards

Pavel

>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
> EDB https://enterprisedb.com
>
> Do not let urgent matters crowd out time for investment in the future.
>
>
>


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 16:01:41
Message-ID: Z4p-5R34LHYGO90V@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, Jan 17, 2025 at 04:55:07PM +0100, Pavel Stehule wrote:
> pá 17. 1. 2025 v 16:35 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:
>
> So this feature would be like global GUC variables, with permission
> control?
>
> + types and domain type check - holds data in binary form - there are not
> conversions binary, text
> + it is declared - so less space for misuse is there. Custom GUC are absolutely
> tolerant
> + it is a fully database object, only owner can alter it,  and event triggers
> are supported, sinval
> + possibility to set mutability, default value

Okay, good summary. Now, can people give feedback that they would want
this committed to PostgreSQL?

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Do not let urgent matters crowd out time for investment in the future.


From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 16:10:47
Message-ID: Z4qBB2alzlV8CZFF@jrouhaud
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, Jan 17, 2025 at 11:01:41AM -0500, Bruce Momjian wrote:
> On Fri, Jan 17, 2025 at 04:55:07PM +0100, Pavel Stehule wrote:
> > pá 17. 1. 2025 v 16:35 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:
> >
> > So this feature would be like global GUC variables, with permission
> > control?
> >
> > + types and domain type check - holds data in binary form - there are not
> > conversions binary, text
> > + it is declared - so less space for misuse is there. Custom GUC are absolutely
> > tolerant
> > + it is a fully database object, only owner can alter it,  and event triggers
> > are supported, sinval
> > + possibility to set mutability, default value
>
> Okay, good summary. Now, can people give feedback that they would want
> this committed to PostgreSQL?

I unsurprisingly would really like to see it committed, for all the reasons
Pavel mentioned. It would have helped me on various projects many times.


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 16:43:13
Message-ID: 42cf4ffed1779895cd80be940e638751d4847482.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, 2025-01-17 at 11:01 -0500, Bruce Momjian wrote:
> On Fri, Jan 17, 2025 at 04:55:07PM +0100, Pavel Stehule wrote:
> > pá 17. 1. 2025 v 16:35 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:
> >
> > So this feature would be like global GUC variables, with permission
> > control?
> >
> > + types and domain type check - holds data in binary form - there are not
> > conversions binary, text
> > + it is declared - so less space for misuse is there. Custom GUC are absolutely
> > tolerant
> > + it is a fully database object, only owner can alter it,  and event triggers
> > are supported, sinval
> > + possibility to set mutability, default value
>
> Okay, good summary. Now, can people give feedback that they would want
> this committed to PostgreSQL?

I would like to see this committed too, or at least relevant parts of it.

It addresses the perennial problem of people putting state into placeholder
GUCs to pass information between the application and the database
(SET myapp.application_id = 'user_laurenz').

Also, it cann pass information between the code in DO statements and
the surrounding SQL code.

Yours,
Laurenz Albe


From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 17:47:52
Message-ID: l254xqf2rvnpa7znemlajchutp7zc56czus34onsmutblylaum@7u652q7bxjye
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

> On Fri, Jan 17, 2025 at 11:01:41AM GMT, Bruce Momjian wrote:
> On Fri, Jan 17, 2025 at 04:55:07PM +0100, Pavel Stehule wrote:
> > pá 17. 1. 2025 v 16:35 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:
> >
> > So this feature would be like global GUC variables, with permission
> > control?
> >
> > + types and domain type check - holds data in binary form - there are not
> > conversions binary, text
> > + it is declared - so less space for misuse is there. Custom GUC are absolutely
> > tolerant
> > + it is a fully database object, only owner can alter it,  and event triggers
> > are supported, sinval
> > + possibility to set mutability, default value
>
> Okay, good summary. Now, can people give feedback that they would want
> this committed to PostgreSQL?

+1 into the bucket "want committed" from me as well. Throughout the
review process I've stumbled upon a few cases in my own projects, where
it would be useful.


From: Wolfgang Walther <walther(at)technowledgy(dot)de>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 20:20:03
Message-ID: a21f6375-c60b-4db9-847c-9f170b44d3c5@technowledgy.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Bruce Momjian:
> Now, can people give feedback that they would want
> this committed to PostgreSQL?

From a user's perspective: Yes!

I've been waiting for this for a long time and I really hope this can go
through, eventually.

Best,

Wolfgang


From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 21:30:40
Message-ID: CAB-JLwZG6rPK6dft0Pv1EXp2_C2JSWm4jz4WDeMf-_s6n5F32A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

>
> > pá 17. 1. 2025 v 16:35 odesílatel Bruce Momjian <bruce(at)momjian(dot)us>
> napsal:
>
> Okay, good summary. Now, can people give feedback that they would want
> this committed to PostgreSQL?
>

I would love to have this functionality as soon as possible.
I already mentioned to Pavel that he did something very big, and
consequently difficult for anyone to commit, because these patches change a
lot of things in a lot of places.
Of course we want as much as possible, but who knows if a first, leaner
version was committed, with just session variables, so nothing related to
schemas, catalogs, grants, dumps, etc, just a variable in memory, only
that. It would be really cool, and certainly easier for a committer to
agree with the code. And if the first commit occurs, others can follow.

Remember that some people don't use PSQL, so they don't have \set
Even \set variables are not typed, so CREATE VARIABLE T AS
DOMAIN_NUMBER_BETWEEN_1_AND_5 is really cool.

regards
Marcos


From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-17 21:54:17
Message-ID: CAB-JLwb5f-uta=N=dwx2NdrEy272RWjGNi996jEgjgtMyQQT6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Em sex., 17 de jan. de 2025 às 13:01, Bruce Momjian <bruce(at)momjian(dot)us>
escreveu:

> Okay, good summary. Now, can people give feedback that they would want
> this committed to PostgreSQL?

I would love to have this functionality as soon as possible.
I already mentioned to Pavel that he did something very big, and
consequently difficult for anyone to commit, because these patches change a
lot of things in a lot of places.
Of course we want as much as possible, but who knows if a first, leaner
version was committed, with just session variables, so nothing related to
schemas, catalogs, grants, dumps, etc, just a variable in memory, only
that. It would be really cool, and certainly easier for a committer to
agree with the code. And if the first commit occurs, others can follow.

Remember that some people don't use PSQL, so they don't have \set
Even \set variables are not typed, so CREATE VARIABLE T AS
DOMAIN_NUMBER_BETWEEN_1_AND_5 is really cool.

regards
Marcos


From: Gilles Darold <gilles(at)darold(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: Re: proposal: schema variables
Date: 2025-01-18 07:24:04
Message-ID: 82636335-245d-4de0-9c21-a94dbf9ff5d0@darold.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Le 17/01/2025 à 19:01, Bruce Momjian a écrit :
> On Fri, Jan 17, 2025 at 04:55:07PM +0100, Pavel Stehule wrote:
>> pá 17. 1. 2025 v 16:35 odesílatel Bruce Momjian <bruce(at)momjian(dot)us> napsal:
>>
>> So this feature would be like global GUC variables, with permission
>> control?
>>
>> + types and domain type check - holds data in binary form - there are not
>> conversions binary, text
>> + it is declared - so less space for misuse is there. Custom GUC are absolutely
>> tolerant
>> + it is a fully database object, only owner can alter it,  and event triggers
>> are supported, sinval
>> + possibility to set mutability, default value
> Okay, good summary. Now, can people give feedback that they would want
> this committed to PostgreSQL?
>

For me, this is a must have. Not only because of the huge amount of time
that we will save in migration to PostgreSQL (i know that this is not an
argument) but because the only way we have to emulate such feature is to
use custom configuration directives or a PL language that allows global
variable. I have question almost every week on how to do that and the
only answer I have is do this ugly pl/pgsql coding. It will be nice to
have a feature to do that. Thanks Pavel and all involved in this
implementation.

--
Gilles Darold
http://www.darold.net/


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-20 08:26:11
Message-ID: CAFj8pRDDizf70=U6H+=O22mqQcVXB40vzvb-bsw4qsegzYdSXg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 20. 1. 2025 v 8:56 odesílatel Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
napsal:

> On 2025-Jan-17, Bruce Momjian wrote:
>
> > Is this really something we are considering applying, since it has been
> > around for years? I am unclear on that and we had better know if we are
> > going to continue reviewing this.
>
> The fact that the patch has been around for years doesn't automatically
> mean it's a bad idea.
>
> I have proposed that we discuss this patch at fosdem developer's meeting
> next month, precisely to seek consensus on whether this patch is
> something we want or not. My view is that this is a feature that has
> been requested by users for years, so IMO we want this or something
> similar.
>
> I wonder if the reason that committers stay away from it is that
> reviewing it fully (and thus taking responsibility for it) seems such a
> daunting task. I might be wrong, but I think this may be the largest
> patch since FTS.
>

This patch is huge, but I think it is not comparable with parallel
processing support or with replication support.

It doesn't introduce new processes or new data structures or does important
changes in planner, and I think so almost all code is very simple.

In early versions of this patch, there was a complex part to ensure
validity of content in memory. But it was fully removed and replaced
just by comparing with create_lsn.

Regards

Pavel

> --
> Álvaro Herrera 48°01'N 7°57'E —
> https://www.EnterpriseDB.com/
> Tom: There seems to be something broken here.
> Teodor: I'm in sackcloth and ashes... Fixed.
>
> http://postgr.es/m/482D1632.8010507@sigaev.ru
>


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-20 20:15:43
Message-ID: Z46u79BCvRKgAWLk@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, Jan 17, 2025 at 03:47:28PM +0100, Álvaro Herrera wrote:
> On 2025-Jan-17, Bruce Momjian wrote:
>
> > Is this really something we are considering applying, since it has been
> > around for years? I am unclear on that and we had better know if we are
> > going to continue reviewing this.
>
> The fact that the patch has been around for years doesn't automatically
> mean it's a bad idea.

Yes, I think we passed the Desirability criteria with the feedback on
this thread, but it is now a question of whether the code complexity
justifies the feature. I saw a few people saying they want _some_ parts
of the patch, which opens the suggestion that even people who want the
patch are seeing parts of the patch that are too much. I have seen this
patch circling around, and I think it needs a step a back for analysis.

> I have proposed that we discuss this patch at fosdem developer's meeting
> next month, precisely to seek consensus on whether this patch is
> something we want or not. My view is that this is a feature that has
> been requested by users for years, so IMO we want this or something
> similar.

Yes, the meeting review is a very good idea.

> I wonder if the reason that committers stay away from it is that
> reviewing it fully (and thus taking responsibility for it) seems such a
> daunting task. I might be wrong, but I think this may be the largest
> patch since FTS.

I think we have to identify a committer who is willing to consider
application of this patch before the patch can move forward.

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Do not let urgent matters crowd out time for investment in the future.


From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-20 20:40:34
Message-ID: 4d2e713c026632e11afeb679088112339ea74e65.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Mon, 2025-01-20 at 15:15 -0500, Bruce Momjian wrote:
> Yes, I think we passed the Desirability criteria with the feedback on
> this thread, but it is now a question of whether the code complexity
> justifies the feature.  I saw a few people saying they want _some_ parts
> of the patch, which opens the suggestion that even people who want the
> patch are seeing parts of the patch that are too much.  I have seen this
> patch circling around, and I think it needs a step a back for analysis.

I'd say that patches 1 to 6 from the patch set are essential.

Yours,
Laurenz Albe


From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-06 14:49:00
Message-ID: CACJufxH2M-tAXTqpttS=f96xfAqj3jVO1BxworB+jyrujR=PPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

hi.

git diff --check
shows there is some white space there.

Adding hack mailing list discussion links in each patch would be great.
Others said that the first 6 patches are essential, maybe we can only
post the first 6 patches.
so the test CI result would be more reliable. also people would not
feel intimidated by
the bigger patchset.

create domain dnn as int not null;
CREATE VARIABLE var3 AS dnn;
alter domain dnn drop not null;
alter domain dnn set not null;
ERROR: cannot alter domain "dnn" because session variable "public.var3" uses it

This is not great.
we allow a constraint, then we drop it, now we cannot re add it again.
0001 and 0002 are simple, but the size is still large.
maybe we can not support the domain in the first 2 patches.

also
CREATE VARIABLE var3 AS dnn;
let var3 = 11;
create view v1 as select var3;
select * from v1;
you can see reconnect to session then
ERROR: domain dnn does not allow null values
this is not ok?

also
create table t(var3 int);
CREATE POLICY p1r ON t AS RESTRICTIVE TO alice USING (var3 <> var3);
create table t1(a int);
CREATE POLICY p2 ON t1 AS RESTRICTIVE TO alice USING (a <> var3);
p1r is so confusing. there is no way to understand the intention.
p2 should also not be allowed, since var3 value is volatile,
session reconnection will change the value.

src/bin/pg_dump/pg_dump.h
/*
* The VariableInfo struct is used to represent session variables
*/
typedef struct _VariableInfo
{
DumpableObject dobj;
DumpableAcl dacl;
Oid vartype;
char *vartypname;
char *varacl;
char *rvaracl;
char *initvaracl;
char *initrvaracl;
Oid varcollation;
const char *rolname; /* name of owner, or empty string */
} VariableInfo;
these fields (varacl, rvaracl, initvaracl, initrvaracl) were never being used.
we can remove them.

CollInfo *coll;
coll = findCollationByOid(varcollation);
if (coll)
appendPQExpBuffer(query, " COLLATE %s",
fmtQualifiedDumpable(coll));
here, it should be
```CollInfo *coll = NULL;```?

I don't understand the changes made in getAdditionalACLs.
I thought pg_init_privs had nothing to do with the session variable.

minor issue in getVariables.
query = createPQExpBuffer();
resetPQExpBuffer(query);
no need to use resetPQExpBuffer here.

create type ab as (a int, b text);
create type abc as (a ab, c text);
create type abcd as (a abc, d text);
CREATE VARIABLE var2 AS abcd;

select var2.a.c;
ERROR: cross-database references are not implemented: var2.a.c

Is this error what we expected? I am not 100% sure.
--------------------another contrived corner case.-----------------------
create type pg_variable as (
oid oid, vartype oid, varcreate_lsn pg_lsn,
varname name, varnamespace oid, varowner oid,
vartypmod int, varcollation oid, varacl aclitem[]);
create variable pg_variable as pg_variable;
let pg_variable = row (18041, 10116, '0/25137B0','pg_variable', 2200,
10,-1,0, NULL)::pg_variable;

select pg_variable.oid from pg_variable where pg_variable.oid = pg_variable.oid;
this query, the WHERE clause, it's really hard to distinguish session
variable or column reference.
I am not sure if this is fine or not.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-07 07:24:55
Message-ID: CAFj8pRBFxSj0Byt+zGqnHsarQHuYSmxOLX3OhD2DKYkc2odOxg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

čt 6. 2. 2025 v 15:49 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> hi.
>
> git diff --check
> shows there is some white space there.
>

yes, it was few times in documentation

fixed

>
> Adding hack mailing list discussion links in each patch would be great.
>

Unfortunately, it is not separated. The organization of patches is not
mapped to discussion, because originally there was one big patch that was
divided
and reorganized. So there was no separate discussion about catalog or
syntax. It was a pelmel and bikeshedding (lot of bikeshedding).

> Others said that the first 6 patches are essential, maybe we can only
> post the first 6 patches.
> so the test CI result would be more reliable. also people would not
> feel intimidated by
> the bigger patchset.
>
>
I understand, but I am not sure if it is a good idea. I would not repeat a
lot of bikeshedding like variables should be immutable, transactional, ...
etc..

Maybe I can repeat some higher level description of this patchset

Really essential are just patches 01-02. Just with these patches the user
gets almost all necessary and required functionality - possibility to work
with declared variables with access rights.
I don't think these patches can be reduced - maybe access rights can be
separated, but if you check source code, the part related to access rights
is few lines (and access rights cannot be supported in next steps due
possible compatibility issues). These patches are almost very simple -
mainly 01 - it is mechanical work related to maintaining a new database
class - some code, and a lot of tests.

Patches 03-05 are related to memory cleaning when variables are dropped. It
is important from a technical quality perspective, but until temporary
variables are supported the variables are not usually dropped frequently,
and then real impact for usage is not extra big. DISCARD VARIABLES can be
important for applications that use connection pooling, but this patch is
very simple again.
Patch05 is not long but does difficult work - sinval processing, cache
invalidation, contains isolation tests. It is probably the most difficult
part of this patchset. If we accept a small memory leak after the dropped
variable, then we can live without this patch (not forever - but I can
imagine passing this patch to the next major release). This is a necessary
prerequisite for temporary variables.

Patch 06 contains just plpgsql regress tests - nothing special or difficult.

Patches 07-09 can be important from user friendly usage perspective -
detection of shaded variables can help with unwanted shadowing, variable
fences can strongly reduce any potential risks of introduction of session
variables. I think variable fences can be an interesting safety tool,
concept - these patches are not small (+/- 20kB), but the code is a minimal
part of these patches. I think it can be very practical and pragmatic to
support variable fences from the start by requiring it outside SPI by
default. From my perspective, it is more important than variable shadowing
detection.

Patches 10-11 EXPLAIN, PREPARE support for LET statements are interesting
for consistency with other statements. Nothing special, nothing difficult,
nothing extra important, but interesting for consistent behaviour of all
PostgreSQL commands.

Patches 12-15 - temp variables, immutable variables, default values
support, reset at transaction end introduces a very interesting feature
that allows to do some special work with session variables and increases a
comfort for work with session variables. These patches can be postponed or
applied independently. There is not fully agreement on the syntax RESET AT
TRANSACTION END, but this is just one patch from this set, and other
patches don't depend on this patch.

Patches 16-19 are important from performance perspective and significantly
increases the performance of queries that contain session variables or the
performance of LET statements for some special cases (like simple
expressions from PLpgSQL, or parallel query execution). These patches have
zero impact on functionality, but significant impact on performance. These
patches are separated because of some deeper changes, and can be postponed,
so they are removed from patch 02. These patches are independent of others
- and can be applied later .. it is typical for PLpgSQL so the performance
was enhanced step by step from relatively bad to really good now.

Patch 20 enhances error messages to support variables - nothing special,
nothing important - these messages are not fully correct now against
plpgsql variables, and nobody protests.

Patch 21 supports transactional behaviour to session variables (the content
can be transactional). It is an unusual feature, other databases don't have
similar functionality, but for some cases can be nice, and can introduce
mutable transactional storage on read only replicas.

Patch 22 introduces the pg_dump option - short simple patch just for
consistency with already supported options of pg_dump. Nothing important,
nothing complex.

So really essential are patches 01, 02, 04. These patch holds almost all
valuable functionality that the people want
03, 05 are important for technical consistency - developers doesn't like
memory leaks after dropped objects (but I think real impact will be small
or +/- nothing)
08, 09 can be interesting for the possibility to force some good (safe)
style of usage from the beginning.

Others are interesting, important, but can be postponed or applied
independently. Some one can prefer functionality, someone can prefer
performance. For performance testing patches 16-19 can be interesting,
important (the performance in plpgsql is very significantly different if
the query is executed by SPI or directly - on second hand, plpgsql is not
used by majority users now). But they are separated because it is about 25%
of (01+02), and the code there is not trivial like in 01 and 02.

For domain behaviour check and other issues I need little bit more time

Regards

Pavel

>
> create domain dnn as int not null;
> CREATE VARIABLE var3 AS dnn;
> alter domain dnn drop not null;
> alter domain dnn set not null;
> ERROR: cannot alter domain "dnn" because session variable "public.var3"
> uses it
>
> This is not great.
> we allow a constraint, then we drop it, now we cannot re add it again.
> 0001 and 0002 are simple, but the size is still large.
> maybe we can not support the domain in the first 2 patches.
>
> also
> CREATE VARIABLE var3 AS dnn;
> let var3 = 11;
> create view v1 as select var3;
> select * from v1;
> you can see reconnect to session then
> ERROR: domain dnn does not allow null values
> this is not ok?
>
>
> also
> create table t(var3 int);
> CREATE POLICY p1r ON t AS RESTRICTIVE TO alice USING (var3 <> var3);
> create table t1(a int);
> CREATE POLICY p2 ON t1 AS RESTRICTIVE TO alice USING (a <> var3);
> p1r is so confusing. there is no way to understand the intention.
> p2 should also not be allowed, since var3 value is volatile,
> session reconnection will change the value.
>
>
> src/bin/pg_dump/pg_dump.h
> /*
> * The VariableInfo struct is used to represent session variables
> */
> typedef struct _VariableInfo
> {
> DumpableObject dobj;
> DumpableAcl dacl;
> Oid vartype;
> char *vartypname;
> char *varacl;
> char *rvaracl;
> char *initvaracl;
> char *initrvaracl;
> Oid varcollation;
> const char *rolname; /* name of owner, or empty string */
> } VariableInfo;
> these fields (varacl, rvaracl, initvaracl, initrvaracl) were never being
> used.
> we can remove them.
>
> CollInfo *coll;
> coll = findCollationByOid(varcollation);
> if (coll)
> appendPQExpBuffer(query, " COLLATE %s",
> fmtQualifiedDumpable(coll));
> here, it should be
> ```CollInfo *coll = NULL;```?
>
>
> I don't understand the changes made in getAdditionalACLs.
> I thought pg_init_privs had nothing to do with the session variable.
>
>
> minor issue in getVariables.
> query = createPQExpBuffer();
> resetPQExpBuffer(query);
> no need to use resetPQExpBuffer here.
>
>
> create type ab as (a int, b text);
> create type abc as (a ab, c text);
> create type abcd as (a abc, d text);
> CREATE VARIABLE var2 AS abcd;
>
> select var2.a.c;
> ERROR: cross-database references are not implemented: var2.a.c
>
> Is this error what we expected? I am not 100% sure.
> --------------------another contrived corner case.-----------------------
> create type pg_variable as (
> oid oid, vartype oid, varcreate_lsn pg_lsn,
> varname name, varnamespace oid, varowner oid,
> vartypmod int, varcollation oid, varacl aclitem[]);
> create variable pg_variable as pg_variable;
> let pg_variable = row (18041, 10116, '0/25137B0','pg_variable', 2200,
> 10,-1,0, NULL)::pg_variable;
>
> select pg_variable.oid from pg_variable where pg_variable.oid =
> pg_variable.oid;
> this query, the WHERE clause, it's really hard to distinguish session
> variable or column reference.
> I am not sure if this is fine or not.
>

Attachment Content-Type Size
v20250207-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250207-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250207-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250207-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250207-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.3 KB
v20250207-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250207-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250207-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250207-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250207-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250207-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250207-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250207-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250207-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250207-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250207-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250207-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250207-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250207-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250207-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250207-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.7 KB
v20250207-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.7 KB

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-07 13:14:09
Message-ID: CACJufxEwd5V82CpGykhKD3Pb9LfS_rgw3-dPrxdT0rwqnkvzQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

On Fri, Feb 7, 2025 at 3:25 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>

Hi
The following review is based on v20250117.

pg_dump order seems not right.
CREATE FUNCTION public.test11(text) RETURNS text
LANGUAGE sql
AS $$select v4 $$;
CREATE VARIABLE public.v4 AS text;

first dump function then variable. restore would fail.
we should first dump variables then function.
probably placed it right after CREATE DOMAIN/CREATE TYPE

drop table if exists t3;
create variable v4 as text;
let v4 = 'hello';
CREATE TABLE t3 (a timestamp, v4 text);
INSERT INTO t3 SELECT i FROM generate_series('2020-01-01'::timestamp,
'2020-12-31'::timestamp,
'10 minute'::interval) s(i);
ANALYZE t3;
create or replace function test11(text) returns text as $$select v4 $$
language sql;
CREATE STATISTICS s4 (ndistinct) ON test11(v4), test11(v4 || 'h') FROM t3;
this "CREATE STATISTICS s4..." should error out?

any objects built on top of functions that use variables should be
marked as volatile.
and we should also consider the implications of it.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-09 20:56:54
Message-ID: CAFj8pRDqK4XMpsmKMx+ERPBMnsCfQ9x+Q=NAeiaGVXVRSx1rcQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

> create domain dnn as int not null;
> CREATE VARIABLE var3 AS dnn;
> alter domain dnn drop not null;
> alter domain dnn set not null;
> ERROR: cannot alter domain "dnn" because session variable "public.var3"
> uses it
>

> This is not great.
> we allow a constraint, then we drop it, now we cannot re add it again.
>

I think this is correct. And I am afraid so we need to choose from two bad
things. There is not possible any other way

The data of session variables are not shared, so we cannot recheck if data
are valid against new constraints or not.

Then there was two possibilities (and not any other)
a) disallow add new constraints
b) ignore possible inconsistency

I implemented @a (can be easily removed), for example temp tables uses @b

you can try - in one session do modification of domain
and in second session do just

create temp table t (a dnn);
-- after drop not null
insert into t values(null);
-- you can successfully set not null to dnn
insert into t values(null); -- now fails
but select * from t -- and the t has null in a

So unfortunately there is no good solution - you can prefer consistency
(and stop altering) or you can allow altering (and stop consistency).

Usage of variables disallow type altering already - so disallowing altering
domain looks more correct - but I am open to any discussion. I can change
the behaviour the same way like temp tables.
In this case I don't see any reason be extra dogmatic - after any update or
reset, the value will be corrected for new constraints, and what is
important - although the value will not be fully consistent for domain
type, it is still fully consistent for base type, so there is not risk of
crashes - and after disconnect of all sessions, the all inconsistent values
will be lost equally like data of temp tables. Now, a more restrictive
variant is implemented - so it is safe, and future change should not have
compatibility issues.

> 0001 and 0002 are simple, but the size is still large.
> maybe we can not support the domain in the first 2 patches.
>

Removing domain support decrease the size about few kilobytes

> also
> CREATE VARIABLE var3 AS dnn;
> let var3 = 11;
> create view v1 as select var3;
> select * from v1;
> you can see reconnect to session then
> ERROR: domain dnn does not allow null values
> this is not ok?
>

this is ok

the content of session variables is not shared. The variable in the second
session is initialized to null, and the null is disallowed.

The variable is initialized when it is used for the first time in the
session. And it is initialized to default value - without default value,
it is initialized to NULL (possibility to set default does different
patch). So when you use a view for the first time, then the variable is
initialized
and it fails.

It is consistent with plpgsql

(2025-02-09 20:23:14) postgres=#
do $$
declare x dnn;
begin
end
$$;
ERROR: domain dnn does not allow null values
CONTEXT: PL/pgSQL function inline_code_block line 2 during statement block
local variable initialization

There is no raised syntax error or some compilation error. The raised error
is just runtime initialization error like session variables

>
>
> also
> create table t(var3 int);
> CREATE POLICY p1r ON t AS RESTRICTIVE TO alice USING (var3 <> var3);
> create table t1(a int);
> CREATE POLICY p2 ON t1 AS RESTRICTIVE TO alice USING (a <> var3);
> p1r is so confusing. there is no way to understand the intention.
> p2 should also not be allowed, since var3 value is volatile,
> session reconnection will change the value.
>

One of the main targets of session variables is using RLS.

Postgres allows to

`CREATE POLICY p2 ON t1 AS RESTRICTIVE TO pavel USING (a <>
current_user::regrole::int)`

and I don't need reconnect - just I can use `set role to ...` or I can use
security definer function

Inside the queries, the session variables are stable, because the values
are passed as copy when the query is started.

This can be changed by wrapping a volatile function, but on the top level,
the variables are stable (we talked about implementation of really volatile
variables), but it is not implemented.

create variable v int;

CREATE OR REPLACE FUNCTION public.fx()
RETURNS integer
LANGUAGE plpgsql
AS $function$
begin
let v = v + 1;
return v;
end;
$function$

(2025-02-09 20:41:34) postgres=# select v, fx() from generate_series(1,10);
┌───┬────┐
│ v │ fx │
╞═══╪════╡
│ 5 │ 6 │
│ 5 │ 7 │
│ 5 │ 8 │
│ 5 │ 9 │
│ 5 │ 10 │
│ 5 │ 11 │
│ 5 │ 12 │
│ 5 │ 13 │
│ 5 │ 14 │
│ 5 │ 15 │
└───┴────┘
(10 rows)

The current behave is similar to usage plpgsql variables in queries - the
values are copied and are stable for the query

(2025-02-09 20:49:15) postgres=# do $$
declare
r record;
v int default 0;
begin
for r in select v, i from generate_series(1,3) g(i)
loop
v := v + 1;
raise notice '%', r;
end loop;
end$$;
NOTICE: (0,1)
NOTICE: (0,2)
NOTICE: (0,3)
DO

>
>
> src/bin/pg_dump/pg_dump.h
> /*
> * The VariableInfo struct is used to represent session variables
> */
> typedef struct _VariableInfo
> {
> DumpableObject dobj;
> DumpableAcl dacl;
> Oid vartype;
> char *vartypname;
> char *varacl;
> char *rvaracl;
> char *initvaracl;
> char *initrvaracl;
> Oid varcollation;
> const char *rolname; /* name of owner, or empty string */
> } VariableInfo;
> these fields (varacl, rvaracl, initvaracl, initrvaracl) were never being
> used.
> we can remove them.
>

removed

>
> CollInfo *coll;
> coll = findCollationByOid(varcollation);
> if (coll)
> appendPQExpBuffer(query, " COLLATE %s",
> fmtQualifiedDumpable(coll));
> here, it should be
> ```CollInfo *coll = NULL;```?
>

No, why? The coll value is set by findCollationByOid every time, so
initialization is useless.

>
> I don't understand the changes made in getAdditionalACLs.
> I thought pg_init_privs had nothing to do with the session variable.
>

yes, it is useless

removed

>
>
> minor issue in getVariables.
> query = createPQExpBuffer();
> resetPQExpBuffer(query);
> no need to use resetPQExpBuffer here.
>

fixed

>
>
> create type ab as (a int, b text);
> create type abc as (a ab, c text);
> create type abcd as (a abc, d text);
> CREATE VARIABLE var2 AS abcd;
>
> select var2.a.c;
> ERROR: cross-database references are not implemented: var2.a.c
>
> Is this error what we expected? I am not 100% sure.
>

Unfortunately, it is expected. Postgres parser doesn't support direct
access to nested composite types. It can be designed differently, but it is
implemented
to be consistent with current postgres behavior.

create type ab as (a int, b text);
create type abc as (a ab, c text);
create type abcd as (a abc, d text);
create table foo(a abc);

(2025-02-09 06:53:36) postgres=# select foo.a.a from foo;
ERROR: cross-database references are not implemented: foo.a.a

you should to use parenthesis

(2025-02-09 06:53:42) postgres=# select (foo.a).a from foo;
┌───┐
│ a │
╞═══╡
└───┘
(0 rows)

--------------------another contrived corner case.-----------------------
> create type pg_variable as (
> oid oid, vartype oid, varcreate_lsn pg_lsn,
> varname name, varnamespace oid, varowner oid,
> vartypmod int, varcollation oid, varacl aclitem[]);
> create variable pg_variable as pg_variable;
> let pg_variable = row (18041, 10116, '0/25137B0','pg_variable', 2200,
> 10,-1,0, NULL)::pg_variable;
>
> select pg_variable.oid from pg_variable where pg_variable.oid =
> pg_variable.oid;
> this query, the WHERE clause, it's really hard to distinguish session
> variable or column reference.
> I am not sure if this is fine or not.
>

Yes, the basic rule is - don't name the variable exactly like the table or
like the column. Better use a dedicated schema that should not be on the
search path.

There are some prepared tools already

create variable pg_variable as pg_variable;

* patch 07

set session_variables_ambiguity_warning to on;

(2025-02-09 21:09:22) postgres=# select pg_variable.oid from pg_variable
where pg_variable.oid = pg_variable.oid;
WARNING: session variable "pg_variable.oid" is shadowed
LINE 1: select pg_variable.oid from pg_variable where pg_variable.oi...
^
DETAIL: Session variables can be shadowed by columns, routine's variables
and routine's arguments with the same name.
WARNING: session variable "pg_variable.oid" is shadowed
LINE 1: select pg_variable.oid from pg_variable where pg_variable.oi...
^
DETAIL: Session variables can be shadowed by columns, routine's variables
and routine's arguments with the same name.
WARNING: session variable "pg_variable.oid" is shadowed
LINE 1: ...able.oid from pg_variable where pg_variable.oid = pg_variabl...
^
DETAIL: Session variables can be shadowed by columns, routine's variables
and routine's arguments with the same name.
┌───────┐
│ oid │
╞═══════╡
│ 16389 │
└───────┘
(1 row)

* patch 08 - variable fencing - it helps with forcing of usage of some
identifier like the variable

(2025-02-09 21:11:58) postgres=# set session_variables_ambiguity_warning to
off;
SET
(2025-02-09 21:12:05) postgres=# let pg_variable.oid = 16389;
LET
(2025-02-09 21:12:07) postgres=# select pg_variable.oid from pg_variable
where pg_variable.oid = variable(pg_variable).oid;
┌───────┐
│ oid │
╞═══════╡
│ 16389 │
└───────┘
(1 row)

(2025-02-09 21:12:10) postgres=# select pg_variable.oid from pg_variable
where pg_variable.oid = variable(pg_variable.oid);
┌───────┐
│ oid │
╞═══════╡
│ 16389 │
└───────┘
(1 row)

* patch 09 - possibility to force usage of variable fencing in some
contexts - it can raise an error when the session variable was used,
but without fencing (in some contexts). Now the contextes are "none, all,
nonspi", but probably better (and more intuitive) will be (and +/- equal)
"none, all, nested".
patch 09 implements some protection against unwanted usage of the session
variable.

I think these tools are enough for safe working with session variables. But
(similarly to PL/pgSQL or PL/SQL) the basic rule is usage of names that are
not in possible collisions.

I don't want to force dedicated schema or dedicated syntax - because it can
be a problem for porting from other databases. But common style for
plpgsql or plsql is using some form of hungarian notation or using prefixes
like _ for local variable and __ for global variable - or using schema name
like package name
schema_name.varname

regards

Pavel

Attachment Content-Type Size
v20250209-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250209-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250209-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250209-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250209-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.3 KB
v20250209-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250209-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.5 KB
v20250209-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250209-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250209-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.6 KB
v20250209-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250209-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250209-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250209-0009-dynamic-check-of-usage-of-session-variable-fences.patch text/x-patch 16.3 KB
v20250209-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250209-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250209-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250209-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250209-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250209-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250209-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.7 KB
v20250209-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-11 07:11:29
Message-ID: CAFj8pRBJJATS3bOr37g2jzFsMBEbQODVLNM-HJQHLK5guoeq3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

pá 7. 2. 2025 v 14:14 odesílatel jian he <jian(dot)universality(at)gmail(dot)com>
napsal:

> On Fri, Feb 7, 2025 at 3:25 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> >
>
> Hi
> The following review is based on v20250117.
>
> pg_dump order seems not right.
> CREATE FUNCTION public.test11(text) RETURNS text
> LANGUAGE sql
> AS $$select v4 $$;
> CREATE VARIABLE public.v4 AS text;
>
> first dump function then variable. restore would fail.
> we should first dump variables then function.
> probably placed it right after CREATE DOMAIN/CREATE TYPE
>

I cannot repeat this issue. The import should to work, because dump
contains `SET check_function_bodies = false;`
The order is designed to support default values, and the default value can
be a function, so the variables should be
dumped after functions.

I tested the new syntax too. And you can see, the order for new syntax is
changed due dependencies

SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: fx1(); Type: FUNCTION; Schema: public; Owner: pavel
--

CREATE FUNCTION public.fx1() RETURNS integer
LANGUAGE sql
AS $$ select v1 $$;

ALTER FUNCTION public.fx1() OWNER TO pavel;

--
-- Name: v1; Type: VARIABLE; Schema: public; Owner: pavel
--

CREATE VARIABLE public.v1 AS integer;

ALTER VARIABLE public.v1 OWNER TO pavel;

--
-- Name: fx3(); Type: FUNCTION; Schema: public; Owner: pavel
--

CREATE FUNCTION public.fx3() RETURNS integer
LANGUAGE sql
RETURN public.v1;

ALTER FUNCTION public.fx3() OWNER TO pavel;

>
>
> drop table if exists t3;
> create variable v4 as text;
> let v4 = 'hello';
> CREATE TABLE t3 (a timestamp, v4 text);
> INSERT INTO t3 SELECT i FROM generate_series('2020-01-01'::timestamp,
> '2020-12-31'::timestamp,
> '10 minute'::interval) s(i);
> ANALYZE t3;
> create or replace function test11(text) returns text as $$select v4 $$
> language sql;
> CREATE STATISTICS s4 (ndistinct) ON test11(v4), test11(v4 || 'h') FROM t3;
> this "CREATE STATISTICS s4..." should error out?
>
>
> any objects built on top of functions that use variables should be
> marked as volatile.
> and we should also consider the implications of it.
>

There is not any request so expression of statistics should be immutable,
although it makes sense (for me).

(2025-02-11 07:48:28) postgres=# create table t4(a int, b int);
CREATE TABLE
(2025-02-11 07:52:32) postgres=# create statistics s5 (ndistinct) on a, (b
* (random()*10)::int) from t4;
CREATE STATISTICS

The access to variables in the query is stable (when it is not wrapped by
volatile functions - because variables
are passed as query parameters to the queries.

I think it is working correctly

(2025-02-11 07:54:58) postgres=# create or replace function fx20() returns
int as $$ let x = x + 1; select x $$ language sql;
CREATE FUNCTION
(2025-02-11 07:55:49) postgres=# let x = 0;
LET
(2025-02-11 07:55:57) postgres=# select x, fx20(), i from
generate_series(1,3) g(i);
┌───┬──────┬───┐
│ x │ fx20 │ i │
╞═══╪══════╪═══╡
│ 0 │ 1 │ 1 │
│ 0 │ 2 │ 2 │
│ 0 │ 3 │ 3 │
└───┴──────┴───┘
(3 rows)

I rewrote the patch 09 - the forsing usage of variable fences
(VARIABLE(varname)). There are two possible concepts:

1. controlling visibility of session variables - the variables without
fencing are visible somewhere, inside fencing are visible everywhere
2. forcing usage of variable fence syntax and raising an error when the
variable is used without fence.

Originally I implemented @2, but the disadvantage can be a lot of errors (a
lot of warnings related to shadowed variables), so this is not a good
default due to the possibility of a lot of writes to log. On the other
hand, there are mystic hidden variable issues. Concept @1 can be more
simple for gentle introducing of variables. And I can believe it can be a
good safe default - the variables are implicitly visible only inside stored
procedures, outside stored procedures, the variable fencing should be used,
and without variable fence - just the variable is not accessible (so there
is not an issue with shadowing warning). The code change between @1 and @2
concepts are just the change of two lines of code. The concept @1 is a
little bit similar to search path (where using variable fencing is like
using a qualified name). So I think it is closer to current postgres
concepts.

Regards

Pavel

Attachment Content-Type Size
v20250211-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250211-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.9 KB
v20250211-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 17.3 KB
v20250211-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250211-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250211-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250211-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.1 KB
v20250211-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250211-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250211-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250211-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.7 KB
v20250211-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250211-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250211-0009-possibility-to-control-implicit-visibility-of-sessio.patch text/x-patch 14.9 KB
v20250211-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250211-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250211-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250211-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250211-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250211-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250211-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250211-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-12 04:43:24
Message-ID: CAFj8pRBLparfcd2_hvAe0Evut-oO63UA2P6MrF3b+3NBLuMvwA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

rebase after a654af21ae522cc8e867e052defd16f76ffaef2e

Regards

Pavel

Attachment Content-Type Size
v20250212-0020-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.9 KB
v20250212-0022-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250212-0021-transactional-variables.patch text/x-patch 37.3 KB
v20250212-0019-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250212-0018-plpgsql-implementation-for-LET-statement.patch text/x-patch 16.8 KB
v20250212-0017-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250212-0016-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.1 KB
v20250212-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250212-0014-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250212-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250212-0012-implementation-of-temporary-session-variables.patch text/x-patch 40.7 KB
v20250212-0011-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250212-0010-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250212-0009-possibility-to-control-implicit-visibility-of-sessio.patch text/x-patch 14.9 KB
v20250212-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250212-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250212-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250212-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250212-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250212-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250212-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250212-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-16 09:13:38
Message-ID: CAFj8pRBpmcV3kdoORvz1iB52otW6FRVP7CBK_bLMsGiONDMM3Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I removed a patch 09 - possibility to set implicit visibility of session
variables. This patch was a replacement of patch - possibility to check the
usage of variable fences.

This specific feature can be implemented in many ways, and at this moment
is useless to try to implement it.

Regards

Pavel

Attachment Content-Type Size
v20250216-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250216-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250216-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250216-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250216-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250216-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250216-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250216-0009-EXPLAIN-LET-support.patch text/x-patch 8.3 KB
v20250216-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250216-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250216-0011-implementation-of-temporary-session-variables.patch text/x-patch 40.7 KB
v20250216-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.1 KB
v20250216-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250216-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250216-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250216-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250216-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250216-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 16.8 KB
v20250216-0020-transactional-variables.patch text/x-patch 37.3 KB
v20250216-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250216-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.2 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-02-20 20:22:15
Message-ID: CAFj8pRC9WKvJm22wfPExiSfQkn4r7mbHntPk11Ohh-50Avw9Bg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

forced rebase

Regards

Pavel

Attachment Content-Type Size
v20250220-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250220-0020-transactional-variables.patch text/x-patch 37.3 KB
v20250220-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 16.8 KB
v20250220-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250220-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250220-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250220-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.1 KB
v20250220-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250220-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250220-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250220-0011-implementation-of-temporary-session-variables.patch text/x-patch 40.7 KB
v20250220-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250220-0009-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250220-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250220-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250220-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250220-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250220-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250220-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250220-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.3 KB
v20250220-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-03-01 07:23:24
Message-ID: CAFj8pRDw=WVEdAnrLsFGstDaGtY4wNQdz59rpZEpZsVF3p0nfA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

fix regress tests after 95dbd827f2edc4d10bebd7e840a0bd6782cf69b7

Regards

Pavel

Attachment Content-Type Size
v20250301-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250301-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.3 KB
v20250301-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250301-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250301-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250301-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250301-0010-PREPARE-LET-support.patch text/x-patch 7.4 KB
v20250301-0009-EXPLAIN-LET-support.patch text/x-patch 8.2 KB
v20250301-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250301-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250301-0013-Implementation-of-DEFAULT-clause-default-expressions.patch text/x-patch 32.1 KB
v20250301-0012-Implementation-ON-TRANSACTION-END-RESET-clause.patch text/x-patch 14.6 KB
v20250301-0014-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch text/x-patch 33.9 KB
v20250301-0011-implementation-of-temporary-session-variables.patch text/x-patch 40.7 KB
v20250301-0015-allow-read-an-value-of-session-variable-directly-fro.patch text/x-patch 15.1 KB
v20250301-0016-allow-parallel-execution-queries-with-session-variab.patch text/x-patch 15.8 KB
v20250301-0017-plpgsql-implementation-for-LET-statement.patch text/x-patch 16.8 KB
v20250301-0018-expression-with-session-variables-can-be-inlined.patch text/x-patch 4.2 KB
v20250301-0021-pg_restore-A-variable.patch text/x-patch 2.8 KB
v20250301-0019-this-patch-changes-error-message-column-doesn-t-exis.patch text/x-patch 29.2 KB
v20250301-0020-transactional-variables.patch text/x-patch 37.3 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-03-17 18:32:59
Message-ID: CAFj8pRC_2tHski1K4hUMZm0+T4y7na4d8hwgMMF7Y0MXhfUhbg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

I was asked for sending a reduced patchset

Regards

Pavel

Attachment Content-Type Size
v20250317-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.3 KB
v20250317-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250317-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250317-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250317-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250317-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.3 KB
v20250317-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250317-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-03-17 20:52:38
Message-ID: CAB-JLwaOdMQN838Fy2r2qZLTExfJp0zcjQjmOFVRXhW_-uDNVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Em seg., 17 de mar. de 2025 às 15:33, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
escreveu:

> I was asked for sending a reduced patchset
>

Would be good to explain what this reduced patchset is.
Complete patch contains this and that
Reduced patch contains only this.

Regards
Marcos


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-03-18 05:46:09
Message-ID: CAFj8pRArtw+Qqzk+Zf2NxjgO=paCBdc54eEma+MsVwtx3j7Atg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

po 17. 3. 2025 v 21:53 odesílatel Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
napsal:

> Em seg., 17 de mar. de 2025 às 15:33, Pavel Stehule <
> pavel(dot)stehule(at)gmail(dot)com> escreveu:
>
>> I was asked for sending a reduced patchset
>>
>
> Would be good to explain what this reduced patchset is.
> Complete patch contains this and that
> Reduced patch contains only this.
>

Reduced patch contains:

* possibility to create and drop session variables (support for catalog
pg_variable and related operations)
* possibility to set the session variable (command LET) and possibility to
use session variable in the query
* access right support
* support for DISCARD command
* memory cleaning at transaction end when the variable is dropped
* warning when variable is shadowed by column
* introduction of variable's fences - syntax VARIABLE(varname)

Complete patch contains plus

* LET can be described by EXPLAIN
* LET can be prepared statement
* temporary session variables
* RESET at transaction end
* implementation of DEFAULT value for the variable
* implementation IMMUTABLE and NOT NULL clauses for the variable
* variable can be used as an argument of CALL statement (and doesn't block
simple evaluation in plpgsql)
* used variable doesn't block with parallel execution
* LET from plpgsql can use simple expression evaluation (performance
optimization for PL/pgSQL)
* variables doesn't block inlining SQL functions
* fix message "column doesn't exist" to "column or variable doesn't exist"
* support for transactional variables (content can be transactional)
* possibility to specify the name of restored variable for pg_restore

Regards

Pavel

>
> Regards
> Marcos
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-04-02 06:46:48
Message-ID: CAFj8pRAK_8ym1J=SAdin-vtL0PAachXgjWgU3QrhzinRdBX2sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

necessary rebase

Regards

Pavel

Attachment Content-Type Size
v20250402-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250402-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250402-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250402-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250402-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250402-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.4 KB
v20250402-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250402-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.3 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-04-05 10:33:21
Message-ID: CAFj8pRAx-Gb9Ux825cxGNm38qQUOrij1GY6erPRaQ=cpqfiX7g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-performance

Hi

only rebase

Regards

Pavel

Attachment Content-Type Size
v20250405-0008-variable-fence-syntax-support-and-variable-fence-usa.patch text/x-patch 19.5 KB
v20250405-0006-plpgsql-tests.patch text/x-patch 16.9 KB
v20250405-0007-GUC-session_variables_ambiguity_warning.patch text/x-patch 15.1 KB
v20250405-0005-memory-cleaning-after-DROP-VARIABLE.patch text/x-patch 20.9 KB
v20250405-0004-DISCARD-VARIABLES.patch text/x-patch 9.6 KB
v20250405-0003-function-pg_session_variables-for-cleaning-tests.patch text/x-patch 4.4 KB
v20250405-0002-Storage-for-session-variables-and-SQL-interface.patch text/x-patch 159.6 KB
v20250405-0001-Enhancing-catalog-for-support-session-variables-and-.patch text/x-patch 169.5 KB