Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tNkJl-001tQE-RK for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Dec 2024 03:01:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tNkIm-009Pid-HY for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Dec 2024 03:00:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tNkIm-009Phd-3F for pgsql-hackers@lists.postgresql.org; Wed, 18 Dec 2024 03:00:43 +0000 Received: from mail-vs1-xe2b.google.com ([2607:f8b0:4864:20::e2b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tNkIh-000Kko-J3 for pgsql-hackers@lists.postgresql.org; Wed, 18 Dec 2024 03:00:41 +0000 Received: by mail-vs1-xe2b.google.com with SMTP id ada2fe7eead31-4afe1009960so1492995137.0 for ; Tue, 17 Dec 2024 19:00:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734490838; x=1735095638; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jn7JCVRhpyeUiTc1PZPkWQCHaGVH9+a+D21CL1vz/XE=; b=YMDbrd/t0Hb1L3rkqSxtPyecyz8YOQpnAdwOFEkZbUgiGw3EE4ifZ68G6/IwAnMD1G x6rwYahh2UsXN9pvfAhDWiJOED5OzsYsv8SoblBSoHke8rK5wdhyz/ceXXRuDIe1MtSD JvWellzKQqdGsopVoVaWKNFZKu/9HJwh9HKohJhhT3FyP5DFnN5UcWrl9g4VQxYblUQS HGi/X4ia9+0NJ36LuxaILA9bTWdHnIgr3GOqne5WVN48AFlyUvF5aJ3aFQgMxEPXajTg EMHlBuc5LFzJ38T3O2pbNtZf1xpwJVPTjMILlMG12qbyFnJzZU+kyURonbtvNh0PPxYH fCgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734490838; x=1735095638; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jn7JCVRhpyeUiTc1PZPkWQCHaGVH9+a+D21CL1vz/XE=; b=fK5geweMizKs6hCXf+PHG4cdhy0zgi/hsYz0y2LM4yIybSR/xBBKcEhkdWC56a/HY5 3ZXmdf0soSHoEDJpH7TOlqkR1yymvXk+pgEdo/DpHdMKjzfZD9BIwGdUzZymoDBbKI1D hY58rMbDgJsMy1QKaXgozcy9SATQWS6Rq0E8VSQRwn79qGyiLfE+fBiR4aycvqd8rIUM YCh5mXEQVmxVFE3CJWUyeuDAkQ9cwmSocBxfNO6KHKpXapTtKXAgMmwLhOtTQS6fpRcH E+OkZa0LYpiRe0P6IcsCBxoZQDKD534uIN0utbC1w1ZU78RGDslpSOIP4zKtMlw6Hetx PtFw== X-Forwarded-Encrypted: i=1; AJvYcCVnHLKeRcDHeqff2C1CXgaN47DwQgPUhDpHFtj+NaKKbW2Xz6lbw9zyP09wAgKmWufZuM9GIVFD7e+cCVi6@lists.postgresql.org X-Gm-Message-State: AOJu0Yx0/6K0PTZrjMX3vMsMx2i72P72ATfYeAWQH9AgILEb6neic3uZ RHJ4GPKs8UsP0kTkRXfpw5PSZytOpaeM9784JYKmSQbj2Jm0kV8Wyhcz6iIIeaB5trFOcE8d77P QJBpqpGKM3IkcDticuoE4986yrF0= X-Gm-Gg: ASbGnctF9/Zib5fuNN9d7Y7zsFWu9mWChTHYmQSPMTU00ArcZUukh32vCdDgvDO+Xrv xEQ1InoguqLuJluoGXpzxPKk+5ZTWEebdcLWkaoM= X-Google-Smtp-Source: AGHT+IG4jcKJoi8RqoZJVZOU70m+yTVkTjgM9Ub/+AzRO3Qjr9SaoVXuf71vDYZaTMoT3s9gIXNh3mxYvtoSMbFtghI= X-Received: by 2002:a05:6102:3caa:b0:4b2:4836:cd63 with SMTP id ada2fe7eead31-4b2ae8a718dmr1287756137.26.1734490837802; Tue, 17 Dec 2024 19:00:37 -0800 (PST) MIME-Version: 1.0 References: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> <20241120201313.t4wbhld4ktgielaf@erthalion.local> In-Reply-To: From: jian he Date: Wed, 18 Dec 2024 11:00:01 +0800 Message-ID: Subject: Re: proposal: schema variables To: Pavel Stehule Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Laurenz Albe , Erik Rijkers , Michael Paquier , Amit Kapila , DUVAL REMI , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk hi. /* * has_session_variable_privilege variants * These are all named "has_session_variable_privilege" at the SQL level. * They take various combinations of variable name, variable OID, * user name, user OID, or implicit user = current_user. * * The result is a boolean value: true if user has the indicated * privilege, false if not. The variants that take a relation OID * return NULL if the OID doesn't exist. */ /* * has_session_variable_privilege_name_name * Check user privileges on a session variable given * name username, text sessin variable name, and text priv name. */ "The variants that take a relation OID return NULL if the OID doesn't exist." should it be "The variants that take an OID type return NULL if the OID doesn't exist." ? typo, "sessin" should be "session". ----------------<<<>>>>------------------- Session Variables only mentioned that "Session variables themselves are persistent, but their values are neither persistent nor shared (like the content of temporary tables). " I feel like this sentence is not that explicit. we actually want to say "Once a session exits, the variable value is reset to NULL, one session cannot see another session variable value." + + A persistent database object that holds a value in session memory. This + value is private to each session and is released when the session ends. + Read or write access to session variables is controlled by privileges, + similar to other database objects. + i do like this description in glossary.sgml. maybe we can copy it and put it to ddl.sgml " ----------------<<<>>>>------------------- REVOKE [ GRANT OPTION FOR ] { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] } ON { VARIABLE variable_name [, ...] | ALL VARIABLES IN SCHEMA schema_name [, ...] } FROM { [ GROUP ] role_specification | PUBLIC } [, ...] [ GRANTED BY role_specification ] [ CASCADE | RESTRICT ] revoke, seems still not right. since with this, we can say: REVOKE ALL PRIVILEGES ON VARIABLE v1 FROM group group alice CASCADE; i think the correct one should be: REVOKE [ GRANT OPTION FOR ] { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] } ON { VARIABLE variable_name [, ...] | ALL VARIABLES IN SCHEMA schema_name [, ...] } FROM role_specification [, ...] [ GRANTED BY role_specification ] [ CASCADE | RESTRICT ] ----------------<<<>>>>------------------- CREATE VARIABLE public.current_user_id AS integer; GRANT READ ON VARIABLE public.current_user_id TO PUBLIC; LET current_user_id = (SELECT id FROM users WHERE usename = session_user); SELECT current_user_id; "GRANT READ" should be "GRANT SELECT". ----------------<<<>>>>------------------- doc/src/sgml/ref/alter_default_privileges.sgml GRANT { SELECT | UPDATE | ALL [ PRIVILEGES ] } ON VARIABLES TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] the above part is wrong? should be: GRANT { { SELECT | UPDATE } [,...] | ALL [ PRIVILEGES ] } ON VARIABLES TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] since we can: ALTER DEFAULT PRIVILEGES FOR ROLE alice IN SCHEMA svartest GRANT SELECT, UPDATE ON VARIABLES TO bob; ----------------<<<>>>>----------------------------- CREATE VARIABLE IF NOT EXISTS v2 AS comp; grant update on variable v2 to alice; set role alice; LET v2.a = 12; --acl permission error LET v2.b = 12; --acl permission error LET v2 = (11,12); --ok. not sure this is the desired behavior, for composite type variables, you are allowed to change all the values, but you are not allowed to update the field value of the composite. The following are normal table test update cases. create type comp as (a int, b int); create table t2(a comp); insert into t2 select '(11,12)'; grant update (a ) on t2 to alice; set role alice; update t2 set a.a = 13; --ok update t2 set a.b = 13; --ok update t2 set a = '(11,13)'; --ok ----------------<<<>>>>----------------------------- domain seems to have an issue. CREATE domain d1 AS int; CREATE VARIABLE var1 AS d1; let var1 = 3; --this should fail?. alter domain d1 add check (value <> 3); select var1; ERROR: value for domain d1 violates check constraint "d1_check" ----------------<<<>>>>----------------------------- doc/src/sgml/ref/alter_variable.sgml Parameters section, the order should be: name, new_owner, new_name, new_schema? I am beginning to look around 0002.