Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDgA8-0001bE-KY for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Jan 2022 05:20:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nDg9a-0004N0-Bn for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Jan 2022 05:20:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDg9a-0004Mj-1Q for pgsql-hackers@lists.postgresql.org; Sat, 29 Jan 2022 05:20:02 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nDg9T-0002hi-2N for pgsql-hackers@lists.postgresql.org; Sat, 29 Jan 2022 05:20:01 +0000 Received: by mail-pf1-x429.google.com with SMTP id v74so8074741pfc.1 for ; Fri, 28 Jan 2022 21:19:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=5R1O03i4xiN6C3VsRNLRmiWwYpSsOK9OpE/WAvN/2Cw=; b=SLrKiY1S53Do6rfcjwbWn/+bRfJRRMnVAPKWyO3wbECgQNMZ5n9Xx/WgZoNiDwUhMh yCbAZxA+vXMvNJJMyCJPfibc36l1zschz6OwRyjdsWL/vuzTvXMWOxSRNjuF8QiiDvXh 838FbEihAGAgEw6hzJi/0HBvvio5h53JsCwU3k+XbioLWHBKTwcykIMEBgfrRF7/j05d tnE/4k7PpDARpQjH8qv7cd+hjWUeTlRakcjkoEi7I5QM+abYLrC9178QzxByJ7XODeSX YrAewelr/HrhT/BaAZvVJgwGkKWfScUcbMH/kx4KaciYaEvzkwXJ3EeowMsMwhr1Gxm7 jwAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=5R1O03i4xiN6C3VsRNLRmiWwYpSsOK9OpE/WAvN/2Cw=; b=4soVjIIp1LjuLuGAEo1HcTW38PyIIuB3eoZYLEtQYW69xerHwMW67YaJ5BzHzSAHkL 4v8YqRnbdmZMCRGOh6e4NR2gvVIZpa0obME00hsHzH1SmyPpMTyNuIyThNlZ52ue7gYt z76RiBGun37jpWsXawBDI8LZ1ELZEt+Nt6FgCgEEHWCpHkUDWwodBwQqTBove3lEvh6f XKlQTOJmXipFOzNI5kJTyv19I2BjbchFcY7RjMDKhY/oB/EtLJ4YGMh63OPyVcUcK9YL C+iWbnGLnrwrMYP5tJ/msQEG0ZEdMbhICiuzhJwjZk3WiJbzqWWHdkki++P8uoHcOVht JVCw== X-Gm-Message-State: AOAM5305G3E2fErWHWAJ2ocpZV6tmXQD3rlJ5f+tQS0GF1Ljl3QxgPzI hNC/jKj4hKd8LAk0fSJJnxw= X-Google-Smtp-Source: ABdhPJxxnCIjNHLvr5OruVjEJw85uDsPVE6sMmx57NuZb2uW9hvhbAG/98f3sTbf/aUP/1wKXQBpEg== X-Received: by 2002:a63:49:: with SMTP id 70mr8861368pga.387.1643433592983; Fri, 28 Jan 2022 21:19:52 -0800 (PST) Received: from jrouhaud (2001-b011-1005-557a-942d-0024-7821-6548.dynamic-ip6.hinet.net. [2001:b011:1005:557a:942d:24:7821:6548]) by smtp.gmail.com with ESMTPSA id k21sm11137457pff.33.2022.01.28.21.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 21:19:52 -0800 (PST) Date: Sat, 29 Jan 2022 13:19:46 +0800 From: Julien Rouhaud To: Pavel Stehule Cc: Dean Rasheed , Joel Jacobson , PostgreSQL Hackers Subject: Re: Schema variables - new implementation for Postgres 15 Message-ID: <20220129051946.outrihp7phagjeey@jrouhaud> References: <20220123081034.tcg7tob6fu3pmlpr@jrouhaud> <20220123085245.ojgzvfdc6zet5wbp@jrouhaud> <20220125051845.xiqkj6hmwvsfpwhw@jrouhaud> <20220126072306.xxkfqma6rwfdkxff@jrouhaud> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Fri, Jan 28, 2022 at 07:51:08AM +0100, Pavel Stehule wrote: > st 26. 1. 2022 v 8:23 odesílatel Julien Rouhaud napsal: > > > + The ON TRANSACTION END RESET > > + clause causes the session variable to be reset to its default value > > when > > + the transaction is committed or rolled back. > > > > As far as I can see this clauses doesn't play well with IMMUTABLE > > VARIABLE, as > > you can reassign a value once the transaction ends. Same for DISCARD [ > > ALL | > > VARIABLES ], or LET var = NULL (or DEFAULT if no default value). Is that > > intended? > > > > I think so it is expected. The life scope of assigned (immutable) value is > limited to transaction (when ON TRANSACTION END RESET). > DISCARD is used for reset of session, and after it, you can write the value > first time. > > I enhanced doc in IMMUTABLE clause I think it's still somewhat unclear: - done, no other change will be allowed in the session lifetime. + done, no other change will be allowed in the session variable content's + lifetime. The lifetime of content of session variable can be + controlled by ON TRANSACTION END RESET clause. + The "session variable content lifetime" is quite peculiar, as the ON TRANSACTION END RESET is adding transactional behavior to something that's not supposed to be transactional, so more documentation about it seems appropriate. Also DISCARD can be used any time so that's a totally different aspect of the immutable variable content lifetime that's not described here. NULL handling also seems inconsistent. An explicit default NULL value makes it truly immutable, but manually assigning NULL is a different codepath that has a different user behavior: # create immutable variable var_immu int default null; CREATE VARIABLE # let var_immu = 1; ERROR: 22005: session variable "var_immu" is declared IMMUTABLE # create immutable variable var_immu2 int ; CREATE VARIABLE # let var_immu2 = null; LET # let var_immu2 = null; LET # let var_immu2 = 1; LET For var_immu2 I think that the last 2 queries should have errored out. > > In revoke.sgml: > > + REVOKE [ GRANT OPTION FOR ] > > + { { READ | WRITE } [, ...] | ALL [ PRIVILEGES ] } > > + ON VARIABLE variable_name [, ...] > > + FROM { [ GROUP ] > class="parameter">role_name | PUBLIC } [, ...] > > + [ CASCADE | RESTRICT ] > > > > there's no extra documentation for that, and therefore no clarification on > > variable_name. > > > > This is same like function_name, domain_name, ... Ah right. > > pg_variable.c: > > Do we really need both session_variable_get_name() and > > get_session_variable_name()? > > > > They are different - first returns possibly qualified name, second returns > only name. Currently it is used just for error messages in > transformAssignmentIndirection, and I think so it is good for consistency > with other usage of this routine (transformAssignmentIndirection). I agree that consistency with other usage is a good thing, but both functions have very similar and confusing names. Usually when you need the qualified name the calling code just takes care of doing so. Wouldn't it be better to add say get_session_variable_namespace() and construct the target string in the calling code? Also, I didn't dig a lot but I didn't see other usage with optionally qualified name there? I'm not sure how it would make sense anyway since LET semantics are different and the current call for session variable emit incorrect messages: # create table tt(id integer); CREATE TABLE # create variable vv tt; CREATE VARIABLE # let vv.meh = 1; ERROR: 42703: cannot assign to field "meh" of column "meh" because there is no such column in data type tt LINE 1: let vv.meh = 1;