Re: proposal: schema variables

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
Thread:
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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2024-07-30 21:07:01 Re: Popcount optimization using AVX512
Previous Message Heikki Linnakangas 2024-07-30 20:01:00 Re: [17+] check after second call to pg_strnxfrm is too strict, relax it

Browse pgsql-performance by date

  From Date Subject
Next Message James Pang 2024-07-31 02:17:41 logical replication out of memory
Previous Message Laurenz Albe 2024-07-30 19:46:46 Re: proposal: schema variables