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 1tV5ZE-005KCa-Kj for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 09:08:05 +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 1tV5ZD-001Wci-O9 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jan 2025 09:08:03 +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 1tV5ZD-001Wca-CI for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2025 09:08:03 +0000 Received: from mail-vk1-xa32.google.com ([2607:f8b0:4864:20::a32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tV5ZA-000JnJ-0W for pgsql-hackers@lists.postgresql.org; Tue, 07 Jan 2025 09:08:02 +0000 Received: by mail-vk1-xa32.google.com with SMTP id 71dfb90a1353d-518957b0533so4968099e0c.1 for ; Tue, 07 Jan 2025 01:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736240879; x=1736845679; 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=Sp9MIKPBMu5Ariy6IgGNupGt29EBUL3q/AWJe35aoa8=; b=B3Nu0dOmxEYNFnGo0riYHYCA8Oq69SzbFAUTnFS66EeUkXq1/z+0vKccwktf0RsgCn E9G+0QkTrFCCaowGvxiKYeHO5S34hrjQxySE7FQPfCiLxy8e1yRG325YGTAE9Nlw0kFw Xqhwy+v+OuKZDuhY17uRoT1R3qEoa7jTzLZ+KYUJoMkea18TANdu1qOf2/F/YmACqztY KNhkf22XiT7XJ27Te7YqLxKANBuiqUYn+gG4Ra6Z1Y0pMmfry7vjKSOV6FdC3odoFrqo 7h5ZMT67SHXL7UTSOCySbbNZ/S95JSnbPv88UDgEsP4PltjqUFxKCuSnFt0Eh6OSfHQU /flA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736240879; x=1736845679; 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=Sp9MIKPBMu5Ariy6IgGNupGt29EBUL3q/AWJe35aoa8=; b=YUTFNiKOmQ9B57w6FaLB2YD8IsHVoWaDvsps/QxJXaFDxfpmiemsVrQW/AWIWykUWy JVx91w3sC/tFLrTqrEScapZ3YAVJ4XnUCEP0BsnQYc/xPg4mb7RKbikdSwCEcSEhKrkN d7rsd1gXTA+W0+PQ1DkrpkyAeUBWmVNywYIE/zV7SNNsEl8WQuqjYroQIZ7qC2nkmCyx Sa8UsAUwIqCbQwqOJw4RUiPvkNXnWiXawVZ8fWvgrDnmWG5KVwWQykv0C2P+VH5MgKBM AjDirnJKDNHzqlWi+0z2NPtzDaqlZ+2fUgjhJ46769yr5tbg2WzdIM07baDQVtDqjgbW Hu4Q== X-Forwarded-Encrypted: i=1; AJvYcCV45+ybvkASRBkg5OmUUtYIdW0b4IpudSNT21f2ZLh+hTfIcslNNGHSFkHpjXlfDjIjPgfOm5QBq759Vi2k@lists.postgresql.org X-Gm-Message-State: AOJu0Yz4xG0HL5dXKxHYDBP6sN5MvAb90ZxGFWfcRc/LtK7M80JsVyEN Qz30GQV5m0SUvvThltUPKGWE4/1pCNMp72pqAaB7hBEUYow2naIfeMxk0GhJnz9k1RUiUd3yUHL If+nuukayb1AIEMz8sOxBPza4Rvs= X-Gm-Gg: ASbGncu3t2yJ+mm9liPWHhHpDKE+zjuuGBEIERjxpwnHV5hBIR5QvnjeGln5uGu0Cv7 Ja9c+Dos1SeUd70IbyJHrq6zwvXyYKGqzTuL7 X-Google-Smtp-Source: AGHT+IFKVhmwkPxMQYcImcQ43l/m1horQ2kS17L+t9QG/Lai7UaejNobwgi/DqTrTHZjzGOUGRwc2Hp9v2cbMhEjJPI= X-Received: by 2002:a05:6122:8c5:b0:515:4b68:c37f with SMTP id 71dfb90a1353d-51b75c73d5fmr42153843e0c.6.1736240878650; Tue, 07 Jan 2025 01:07:58 -0800 (PST) MIME-Version: 1.0 References: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> <20241120201313.t4wbhld4ktgielaf@erthalion.local> In-Reply-To: From: jian he Date: Tue, 7 Jan 2025 17:07:22 +0800 X-Gm-Features: AbW1kvYLcvZOcpCPkGoKiYpVQ5e1GqfLa6i_r23dAzLCeGTobBNXhsMoA2lyFMM Message-ID: Subject: Re: 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. some minor issues. 'transformMergeStmt also needs "qry->hasSessionVariables = pstate->p_hasSessionVariables;" ? acldefault in doc/src/sgml/func.sgml Need an update for SESSION VARIABLE? Table 9.70. Access Privilege Inquiry Functions sorting order: has_session_variable_privilege should after has_server_privilege? Similar to src/test/regress/sql/event_trigger.sql, we can use the following query to test four functions in Table 9.79. Object Information and Addressing Functions (9.27.5. Object Information and Addressing Functions) for session variables. SELECT e.varname, pg_describe_object('pg_variable'::regclass, e.oid, 0) as descr, b.type, b.object_names, b.object_args, pg_identify_object(a.classid, a.objid, a.objsubid) as ident FROM pg_variable as e, LATERAL pg_identify_object_as_address('pg_variable'::regclass, e.oid, 0) as b, LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a; in function transformColumnRef if (expr_kind_allows_session_variables(pstate->p_expr_kind)) { } can change to if (!node && !(relname && crerr == CRERR_NO_COLUMN) && expr_kind_allows_session_variables(pstate->p_expr_kind)) { } can reduce the function call of expr_kind_allows_session_variables, also not lose readability. typedef struct SVariableData says: /* * Stored value and type description can be outdated when we receive a * sinval message. We then have to check if the stored data are still * trustworthy. */ bool is_valid; CREATE VARIABLE var3 AS int; LET var3 = 10; GRANT SELECT ON VARIABLE var3 TO regress_noowner; I don't understand why the last statement GRANT SELECT needs to call pg_variable_cache_callback? and it will invalidate the original var3. +/* + * Returns a copy of the value of the session variable (in the current memory + * context). The caller is responsible for permission checks. + */ +Datum +GetSessionVariable(Oid varid, bool *isNull, Oid *typid) +{ + SVariable svar; + + svar = get_session_variable(varid); + + /* + * Although "svar" is freshly validated in this point, svar->is_valid can + * be false, if an invalidation message ws processed during the domain check. + * But the variable and all its dependencies are locked now, so we don't need + * to repeat the validation. + */ + Assert(svar); + + *typid = svar->typid; + + return copy_session_variable_value(svar, isNull); +} typo, "ws processed" should be "was processed". also the Assert is not helpful? since svar is NULL, get_session_variable would have segfault. also SVariable svar; is not initialized to NULL, so generally it will not be NULL by default. also the comments seem to imply that before copy_session_variable_value, svar->is_valid can be false. if svar->is_valid is false, then why do copy_session_variable_value.