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
- v20250211-0019-expression-with-session-variables-can-be-inlined.patch (text/x-patch) patch v20250211-0019
- v20250211-0020-this-patch-changes-error-message-column-doesn-t-exis.patch (text/x-patch) patch v20250211-0020
- v20250211-0018-plpgsql-implementation-for-LET-statement.patch (text/x-patch) patch v20250211-0018
- v20250211-0022-pg_restore-A-variable.patch (text/x-patch) patch v20250211-0022
- v20250211-0021-transactional-variables.patch (text/x-patch) patch v20250211-0021
- v20250211-0017-allow-parallel-execution-queries-with-session-variab.patch (text/x-patch) patch v20250211-0017
- v20250211-0016-allow-read-an-value-of-session-variable-directly-fro.patch (text/x-patch) patch v20250211-0016
- v20250211-0015-Implementation-of-NOT-NULL-and-IMMUTABLE-clauses.patch (text/x-patch) patch v20250211-0015
- v20250211-0013-Implementation-ON-TRANSACTION-END-RESET-clause.patch (text/x-patch) patch v20250211-0013
- v20250211-0014-Implementation-of-DEFAULT-clause-default-expressions.patch (text/x-patch) patch v20250211-0014
- v20250211-0012-implementation-of-temporary-session-variables.patch (text/x-patch) patch v20250211-0012
- v20250211-0011-PREPARE-LET-support.patch (text/x-patch) patch v20250211-0011
- v20250211-0010-EXPLAIN-LET-support.patch (text/x-patch) patch v20250211-0010
- v20250211-0009-possibility-to-control-implicit-visibility-of-sessio.patch (text/x-patch) patch v20250211-0009
- v20250211-0008-variable-fence-syntax-support-and-variable-fence-usa.patch (text/x-patch) patch v20250211-0008
- v20250211-0007-GUC-session_variables_ambiguity_warning.patch (text/x-patch) patch v20250211-0007
- v20250211-0006-plpgsql-tests.patch (text/x-patch) patch v20250211-0006
- v20250211-0004-DISCARD-VARIABLES.patch (text/x-patch) patch v20250211-0004
- v20250211-0005-memory-cleaning-after-DROP-VARIABLE.patch (text/x-patch) patch v20250211-0005
- v20250211-0003-function-pg_session_variables-for-cleaning-tests.patch (text/x-patch) patch v20250211-0003
- v20250211-0002-Storage-for-session-variables-and-SQL-interface.patch (text/x-patch) patch v20250211-0002
- v20250211-0001-Enhancing-catalog-for-support-session-variables-and-.patch (text/x-patch) patch v20250211-0001
Hi
pá 7. 2. 2025 v 14:14 odesílatel jian he <jian.universality@gmail.com>
napsal:
> On Fri, Feb 7, 2025 at 3:25 PM Pavel Stehule <pavel.stehule@gmail.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