Re: Schema variables - new implementation for Postgres 15 - Mailing list pgsql-hackers

From Dmitry Dolgov
Subject Re: Schema variables - new implementation for Postgres 15
Date
Msg-id 20231117191732.eub35jdoec6vql7t@ddolgov.remote.csb
Whole thread Raw
In response to Re: Schema variables - new implementation for Postgres 15  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Schema variables - new implementation for Postgres 15  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
> On Wed, Aug 23, 2023 at 04:02:44PM +0200, Pavel Stehule wrote:
> NameListToString is already buildin function. Do you think NamesFromList?
>
> This is my oversight - there is just `+extern List *NamesFromList(List
> *names); ` line, but sure - it should be in 0002 patch
>
> fixed now

Right, thanks for fixing.

I think there is a wrinkle with pg_session_variables function. It
returns nothing if sessionvars hash table is empty, which has two
consequences:

* One might get confused about whether a variable is created,
  based on the information from the function. An expected behaviour, but
  could be considered a bad UX.

    =# CREATE VARIABLE var1 AS varchar;

    -- empty, is expected
    =# SELECT name, typname, can_select, can_update FROM pg_session_variables();
     name | typname | can_select | can_update
     ------+---------+------------+------------
     (0 rows)

    -- but one can't create a variable
    =# CREATE VARIABLE var1 AS varchar;
    ERROR:  42710: session variable "var1" already exists
    LOCATION:  create_variable, pg_variable.c:102

    -- yet, suddenly after a select...
    =# SELECT var2;
     var2
     ------
      NULL
      (1 row)

    -- ... it's not empty
    =# SELECT name, typname, can_select, can_update FROM pg_sessio
    n_variables();
     name |      typname      | can_select | can_update
     ------+-------------------+------------+------------
      var2 | character varying | t          | t
      (1 row)

* Running a parallel query will end up returning an empty result even
  after accessing the variable.

    -- debug_parallel_query = 1 all the time
    =# CREATE VARIABLE var2 AS varchar;

    -- empty, is expected
    =# SELECT name, typname, can_select, can_update FROM pg_session_variables();
     name | typname | can_select | can_update
     ------+---------+------------+------------
     (0 rows)

    -- but this time an access...
    SELECT var2;
     var2
     ------
      NULL
      (1 row)

    -- or set...
    =# LET var2 = 'test';

    -- doesn't change the result, it's still empty
    =# SELECT name, typname, can_select, can_update FROM pg_session_variables();
     name | typname | can_select | can_update
     ------+---------+------------+------------
     (0 rows)

Would it be a problem to make pg_session_variables inspect the catalog
or something similar if needed?



pgsql-hackers by date:

Previous
From: Jeff Davis
Date:
Subject: Change GUC hashtable to use simplehash?
Next
From: Jeff Davis
Date:
Subject: Re: Why do indexes and sorts use the database collation?