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 1tUIdF-00FbFr-OM for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jan 2025 04:52:58 +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 1tUIdE-00Fs1A-LL for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jan 2025 04:52:56 +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 1tUIdE-00Fs10-82 for pgsql-hackers@lists.postgresql.org; Sun, 05 Jan 2025 04:52:56 +0000 Received: from mail-vk1-xa2a.google.com ([2607:f8b0:4864:20::a2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tUIdC-000ICY-1J for pgsql-hackers@lists.postgresql.org; Sun, 05 Jan 2025 04:52:55 +0000 Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-518799f2828so6873373e0c.0 for ; Sat, 04 Jan 2025 20:52:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736052772; x=1736657572; 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=ynBsWr56oGSwAKL4mcPJRb19SlcXwgP8icd5j+FnAds=; b=Hc4Ha9BJbPLRIApiB9zOn5lWbJuyu4kFkh+kI30bo53Z14JM9Jjzl+m3Zu2PjY2oQW eRpCt/f0JvpOHYkrQiLIa0JkvsDBjbior4lKVw56YgNE9A4gEwc6Xq4D9s7oUhckyhkE 3ZoQYGnuf5uzMODmRbfBIdAFuGL48wR3puJ0oEh9oBeQDPLjRIrNyLFQeGog1sVGXEWe pC6lOXtCKHZjB5E32Q0ihfcLrBnB+I/zM9cZGDBRXm9QWYiIfU33PXPF92W3nUcPukS7 TscdafWI5hjKkZRT2srZ+LhiWgApSilcTGERjiwEM+898fjjPt+Jjb0J2BFmL6NEi5Si VHKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736052772; x=1736657572; 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=ynBsWr56oGSwAKL4mcPJRb19SlcXwgP8icd5j+FnAds=; b=NN9z5NFYUrsA1+fl3QBxLNQeQu5HeXE2/TcwWLvou1ZW3DgKuczGjNfYq5biRaVEoN z1uo+BbgtdMfBXW2Jq6RK+keK8WPh29KDA3G2WdBwhIc1fVYAknGgnnoLyahFsBGV17g Jgj2kvlFJdckWLH4BurYwdh1qJc3tZgqkIRM3Hau38uTpKxSwfnTn2Iu5V5rwGNfcq+a B49uQdRwTIQo1LfdXaaEo3bOiySOZtEKUk/uKVI7jmjY8e8bNg/OquUVaRj1m5ys8Fry BSLS3U81IynbUoBNPUSJPizpQvoaSOvJDj1ObOTlUGHqAzGjpqMW0iMpAupTXuvoGWfu 09uQ== X-Forwarded-Encrypted: i=1; AJvYcCUSa1yTw355tnwRSMg3cSNmffGohZQ4ktSq8Egi7bK3AOmNXy8auYFEjNe+W8dLkHcmAN9JCAnc++LsiWrY@lists.postgresql.org X-Gm-Message-State: AOJu0YySPsDxU7oTm3viiMHk02LGgLxNZcDPFiHFVyxyUjaWabK4wUUY XEVLbNEiVz2aHWzCBewhYRW03w7vpmoOvH1VosYA3nkfdz3rr0WtTErdphhh4gcIxCLHOXpVfi6 p2+NmOYNT4EooJH1SWyPZIjgg7qQje/mFcqStbQ== X-Gm-Gg: ASbGncuS0UeArHl035o63NbbY4gVC0dLhCXhAnB9yQWVqRKQcn3BcvbG90mcIorZWFS iBSQDCq0GPkACvrhaye+fK0c0KmyKjtBPv2V8 X-Google-Smtp-Source: AGHT+IHvIsW84apnZgrlHt2ViEys0HXhTQSqM9Ls5W/SM/DPjtf056xpMn+vZtOjHu1G9nbvsTHK85zjhJYFwW3nA/o= X-Received: by 2002:a05:6122:2b9:b0:516:dc0f:c925 with SMTP id 71dfb90a1353d-51b64c06b47mr35146602e0c.6.1736052771757; Sat, 04 Jan 2025 20:52:51 -0800 (PST) MIME-Version: 1.0 References: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> <20241120201313.t4wbhld4ktgielaf@erthalion.local> In-Reply-To: From: jian he Date: Sun, 5 Jan 2025 12:52:15 +0800 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 diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 9c2957eb546..624858db301 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -361,6 +361,9 @@ typedef struct Const * of the `paramid' field contain the SubLink's subLinkId, and * the low-order 16 bits contain the column number. (This type * of Param is also converted to PARAM_EXEC during planning.) + * + * PARAM_VARIABLE: The parameter is a reference to a session variable + * (paramid holds the variable's OID). */ typedef enum ParamKind { @@ -368,6 +371,7 @@ typedef enum ParamKind PARAM_EXEC, PARAM_SUBLINK, PARAM_MULTIEXPR, + PARAM_VARIABLE, } ParamKind; typedef struct Param @@ -380,6 +384,10 @@ typedef struct Param int32 paramtypmod pg_node_attr(query_jumble_ignore); /* OID of collation, or InvalidOid if none */ Oid paramcollid pg_node_attr(query_jumble_ignore); + /* OID of session variable if it is used */ + Oid paramvarid; + /* true when param is used like base node of assignment indirection */ + bool parambasenode; /* token location, or -1 if unknown */ ParseLoc location; } Param; comment should be "(paramvarid holds the variable's OID)" also + /* true when param is used like base node of assignment indirection */ is kind of hard to understand. param->parambasenode = true; only happens in transformLetStmt so we can change it to + /* true when param is used in part of the LET statement.*/ --- a/src/include/executor/execdesc.h +++ b/src/include/executor/execdesc.h @@ -51,6 +51,10 @@ typedef struct QueryDesc /* This field is set by ExecutePlan */ bool already_executed; /* true if previously executed */ + /* reference to session variables buffer */ + int num_session_variables; + SessionVariableValue *session_variables; + /* This is always set NULL by the core system, but plugins can change it */ struct Instrumentation *totaltime; /* total time spent in ExecutorRun */ } QueryDesc; QueryDesc->num_session_variables and QueryDesc->session_variables are never used in 0001 and 0002. it may be used in later patches, but at least 0001 and 0002, we don't need to change struct QueryDesc? contrib/postgres_fdw/deparse.c There are some cases of "case T_Param:" do we need to do something on it? also on src/backend/nodes/queryjumblefuncs.c, one appearance of "case T_Param:". (but it seems no need change here) CREATE VARIABLE v1 AS int; CREATE VARIABLE v2 AS int; SELECT pg_stat_statements_reset() IS NOT NULL AS t; select count(*) from tenk1 where unique1 = v1; select count(*) from tenk1 where unique1 = v2; should the last two queries be normalized as one query in pg_stat_statements? if so, then maybe in typedef struct Param we need change to: Oid paramvarid pg_node_attr(query_jumble_ignore); but then let v1 = v1+1; let v1 = v2+1; will be normalized as one query.