Re: Re: proposal: schema variables
Pavel Stehule <pavel.stehule@gmail.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Move WAL sequence code into its own file
- a87987cafca6 19 (unreleased) cited
-
Add ExplainState argument to pg_plan_query() and planner().
- c83ac02ec730 19 (unreleased) cited
-
Don't include access/htup_details.h in executor/tuptable.h
- 1a8b5b11e48a 19 (unreleased) cited
-
Refactor to avoid code duplication in transformPLAssignStmt.
- b0fb2c6aa5a4 19 (unreleased) cited
-
Avoid including commands/dbcommands.h in so many places
- 325fc0ab14d1 19 (unreleased) cited
-
Restrict psql meta-commands in plain-text dumps.
- 71ea0d679543 19 (unreleased) cited
-
Split func.sgml into more manageable pieces
- 4e23c9ef65ac 19 (unreleased) cited
-
Fix squashing algorithm for query texts
- 0f65f3eec478 18.0 cited
-
EXPLAIN: Always use two fractional digits for row counts.
- 95dbd827f2ed 18.0 cited
-
Preliminary refactoring of plpgsql expression construction.
- a654af21ae52 18.0 cited
-
plpgsql: pure parser and reentrant scanner
- 7b27f5fd36cb 18.0 cited
-
Add some sanity checks in executor for query ID reporting
- 24f520594809 18.0 cited
-
Fix misleading error message context
- 4af123ad45bd 18.0 cited
-
Add macros for looping through a List without a ListCell.
- 14dd0f27d7cd 17.0 cited
Attachments
- v20250108-0022-pg_restore-A-variable.patch (text/x-patch) patch v20250108-0022
- v20250108-0021-transactional-variables.patch (text/x-patch) patch v20250108-0021
- v20250108-0019-expression-with-session-variables-can-be-inlined.patch (text/x-patch) patch v20250108-0019
- v20250108-0020-this-patch-changes-error-message-column-doesn-t-exis.patch (text/x-patch) patch v20250108-0020
- v20250108-0018-plpgsql-implementation-for-LET-statement.patch (text/x-patch) patch v20250108-0018
- v20250108-0017-allow-parallel-execution-queries-with-session-variab.patch (text/x-patch) patch v20250108-0017
- v20250108-0016-allow-read-an-value-of-session-variable-directly-fro.patch (text/x-patch) patch v20250108-0016
- v20250108-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch (text/x-patch) patch v20250108-0015
- v20250108-0014-Implementation-of-DEFAULT-clause-default-expressions.patch (text/x-patch) patch v20250108-0014
- v20250108-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch (text/x-patch) patch v20250108-0013
- v20250108-0012-implementation-of-temporary-session-variables.patch (text/x-patch) patch v20250108-0012
- v20250108-0010-EXPLAIN-LET-support.patch (text/x-patch) patch v20250108-0010
- v20250108-0011-PREPARE-LET-support.patch (text/x-patch) patch v20250108-0011
- v20250108-0008-variable-fence-syntax-support-and-variable-fence-usa.patch (text/x-patch) patch v20250108-0008
- v20250108-0009-dynamic-check-of-usage-of-session-variable-fences.patch (text/x-patch) patch v20250108-0009
- v20250108-0006-plpgsql-tests.patch (text/x-patch) patch v20250108-0006
- v20250108-0007-GUC-session_variables_ambiguity_warning.patch (text/x-patch) patch v20250108-0007
- v20250108-0004-DISCARD-VARIABLES.patch (text/x-patch) patch v20250108-0004
- v20250108-0003-function-pg_session_variables-for-cleaning-tests.patch (text/x-patch) patch v20250108-0003
- v20250108-0005-memory-cleaning-after-DROP-VARIABLE.patch (text/x-patch) patch v20250108-0005
- v20250108-0002-Storage-for-session-variables-and-SQL-interface.patch (text/x-patch) patch v20250108-0002
- v20250108-0001-Enhancing-catalog-for-support-session-variables-and-.patch (text/x-patch) patch v20250108-0001
Hi st 8. 1. 2025 v 10:31 odesílatel jian he <jian.universality@gmail.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