Re: Schema variables - new implementation for Postgres 15
Pavel Stehule <pavel.stehule@gmail.com>
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>,
Sergey Shinderuk <s.shinderuk@postgrespro.ru>, Tomas Vondra <tomas.vondra@enterprisedb.com>,
Julien Rouhaud <rjuju123@gmail.com>, dean.a.rasheed@gmail.com, er@xs4all.nl, joel@compiler.org, pgsql-hackers@lists.postgresql.org
Date: 2023-03-26T06:53:49Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Allow underscores in integer and numeric constants.
- faff8f8e47f1 16.0 cited
-
Remove special outfuncs/readfuncs handling of RangeVar.catalogname.
- 3cece34be842 16.0 cited
-
Remove extra space from dumped ALTER DEFAULT PRIVILEGES.
- 2af33369e794 16.0 cited
-
Create FKs properly when attaching table as partition
- b0284bfb1db5 16.0 cited
-
psql: improve tab-complete's handling of variant SQL names.
- 02b8048ba5dc 15.0 cited
Attachments
- v20230326-1-0010-documentation.patch (text/x-patch) patch v20230326-0010
- v20230326-1-0006-enhancing-psql-for-session-variables.patch (text/x-patch) patch v20230326-0006
- v20230326-1-0009-this-patch-changes-error-message-column-doesn-t-exis.patch (text/x-patch) patch v20230326-0009
- v20230326-1-0007-possibility-to-dump-session-variables-by-pg_dump.patch (text/x-patch) patch v20230326-0007
- v20230326-1-0008-regress-tests-for-session-variables.patch (text/x-patch) patch v20230326-0008
- v20230326-1-0005-DISCARD-VARIABLES-command.patch (text/x-patch) patch v20230326-0005
- v20230326-1-0003-LET-command.patch (text/x-patch) patch v20230326-0003
- v20230326-1-0004-support-of-LET-command-in-PLpgSQL.patch (text/x-patch) patch v20230326-0004
- v20230326-1-0001-catalog-support-for-session-variables.patch (text/x-patch) patch v20230326-0001
- v20230326-1-0002-session-variables.patch (text/x-patch) patch v20230326-0002
út 21. 3. 2023 v 17:18 odesílatel Peter Eisentraut < peter.eisentraut@enterprisedb.com> napsal: > On 17.03.23 21:50, Pavel Stehule wrote: > > rebase + fix-update pg_dump tests > > I have a few comments on the code: > > 0001 > > ExecGrant_Variable() could probably use ExecGrant_common(). > done > The additions to syscache.c should be formatted to the new style. > done > > in pg_variable.h: > > > - create_lsn ought to have a "var" prefix. > changed > > - typo: "typmode for variable's type" > fixed > > - What is the purpose of struct Variable? It seems very similar to > FormData_pg_variable. At least a comment would be useful. > I wrote comment there: /* * The Variable struct is based on FormData_pg_variable struct. Against * FormData_pg_variable it can hold node of deserialized expression used * for calculation of default value. */ > > > Preserve the trailing comma in ParseExprKind. > done > > > 0002 > > expr_kind_allows_session_variables() should have some explanation > about criteria for determining which expression kinds should allow > variables. > I wrote comment there: /* * Returns true, when expression of kind allows using of * session variables. + * + * The session's variables can be used everywhere where + * can be used external parameters. Session variables + * are not allowed in DDL. Session's variables cannot be + * used in constraints. + * + * The identifier can be parsed as an session variable + * only in expression's kinds where session's variables + * are allowed. This is the primary usage of this function. + * + * Second usage of this function is for decision if + * an error message "column does not exist" or "column + * or variable does not exist" should be printed. When + * we are in expression, where session variables cannot + * be used, we raise the first form or error message. */ > Usually, we handle EXPR_KIND_* switches without default case, so we > get notified what needs to be changed if a new enum symbol is added. > done > > > 0010 > > The material from the tutorial (advanced.sgml) might be better in > ddl.sgml. > moved > > In catalogs.sgml, the columns don't match the ones actually defined in > pg_variable.h in patch 0001 (e.g., create_lsn is missing and the order > doesn't match). > fixed > > (The order of columns in pg_variable.h didn't immediately make sense to > me either, so maybe there is a middle ground to be found.) > reordered. Still varcreate_lsn should be before varname column, because sanity check: -- -- When ALIGNOF_DOUBLE==4 (e.g. AIX), the C ABI may impose 8-byte alignment on -- some of the C types that correspond to TYPALIGN_DOUBLE SQL types. To ensure -- catalog C struct layout matches catalog tuple layout, arrange for the tuple -- offset of each fixed-width, attalign='d' catalog column to be divisible by 8 -- unconditionally. Keep such columns before the first NameData column of the -- catalog, since packagers can override NAMEDATALEN to an odd number. > > session_variables_ambiguity_warning: There needs to be more > information about this. The current explanation is basically just, > "warn if your query is confusing". Why do I want that? Why would I > not want that? What is the alternative? What are some examples? > Shouldn't there be a standard behavior without a need to configure > anything? > I enhanced this entry: + <para> + The session variables can be shadowed by column references in a query. This + is an expected feature. The existing queries should not be broken by creating + any session variable, because session variables are shadowed always if the + identifier is ambiguous. The variables should be named without possibility + to collision with identifiers of other database objects (column names or + record field names). The warnings enabled by setting <varname>session_variables_ambiguity_warning</varname> + should help with finding identifier's collisions. +<programlisting> +CREATE TABLE foo(a int); +INSERT INTO foo VALUES(10); +CREATE VARIABLE a int; +LET a = 100; +SELECT a FROM foo; +</programlisting> + +<screen> + a +---- + 10 +(1 row) +</screen> + +<programlisting> +SET session_variables_ambiguity_warning TO on; +SELECT a FROM foo; +</programlisting> + +<screen> +WARNING: session variable "a" is shadowed +LINE 1: SELECT a FROM foo; + ^ +DETAIL: Session variables can be shadowed by columns, routine's variables and routine's arguments with the same name. + a +---- + 10 +(1 row) +</screen> + </para> + <para> + This feature can significantly increase size of logs, and then it is + disabled by default, but for testing or development environments it + should be enabled. > > In allfiles.sgml, dropVariable should be before dropView. > fixed Regards Pavel