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 1tOXtq-0074vC-GI for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Dec 2024 07:58:18 +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 1tOXto-006wHO-Ne for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Dec 2024 07:58:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tOXto-006wFb-9I for pgsql-hackers@lists.postgresql.org; Fri, 20 Dec 2024 07:58:16 +0000 Received: from mail-ua1-x92d.google.com ([2607:f8b0:4864:20::92d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tOXtl-000WAJ-Dt for pgsql-hackers@lists.postgresql.org; Fri, 20 Dec 2024 07:58:14 +0000 Received: by mail-ua1-x92d.google.com with SMTP id a1e0cc1a2514c-85c5316f15cso464192241.1 for ; Thu, 19 Dec 2024 23:58:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734681491; x=1735286291; 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=mvmyfCA3tZ3oSHx/dwHMD/Qtr492PgzSwYmFwWC0Km0=; b=Q5PVRBU5w7uqi0moQgl43Uvv8UicXXFs6jwnFQRKnebrdHydmBwNNwA0hISBtbqI9b YOl/Hu2dT04AzsGrS0yZ1m1k+MAGLe0gx5ke903krbHjd/ob2gXsWhT+Z95czt+I6x5+ 573eAxSS+UqtQLOIqg62PXUlINPPY9AjVtumHWQoEdDtw2tQLXb+G4H2w0ZM+XP6U5K7 KgSWea5OBPK0rJpio/CzqU6tsTVqVuhKSUpfG0gyV056DlxbGMaZdjCjCMHbubkBCXQV 2hI5tKM/Yj1L2mnwWz3UlyQHzA7umRA2tQE8U44zZqt3WVlujlqPo91KBWj5hRDn48M5 wtmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734681491; x=1735286291; 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=mvmyfCA3tZ3oSHx/dwHMD/Qtr492PgzSwYmFwWC0Km0=; b=G/uzYxnofee8fAdPaUu8X92ymI9+jmVwg1ckwZkw3Q0su+PoeLRcrqzOwTbJQEeY9l GZ5rioZve/sHwuotGRwbbgf88t+mo7MkCZlOjjVWyB1Is+mG4QgbgonziORz7tsTJ3pH afblApOaK7v1CxkP6J/a6X+QDk/jYVeF4bRMnMDbviaXV3r1ZXga57l6olJLvUuGq0hn pfx/3HpzAr3cjEbxW4db+a/nttkxjAr3ba8VLocvj8mK5xaSrIbbmJ0Ii2EaiT7nzmFD VYWlbMzBD5WOlqJmprT3xdC6Q3FLMRq3qNzy8gqLdblmaV1C/rpliGAXQK7UPowYX3/J 8tRQ== X-Forwarded-Encrypted: i=1; AJvYcCVazG6Ok0f5cYNVK36vZc4lJ4hcufG5wWGwJ5AuDeGfubYN+Fo+cWrdjuLZmwHuHjPA2rOfrYRP4+3XTEFC@lists.postgresql.org X-Gm-Message-State: AOJu0Yzu3rDi9UH46OeakmyBFTOCCZd5PSf3/gdBQDE6D/kVdtXOeyIP /JGagA+fl5CnseLyVi/raTN3SNHWnqPpib/cGZ4pPvaFgtAbtE6zXt1vtvk29VFSjS+AUSnKe5H f+Y8Bio6G4IfZMZy2h0VOB/t7qB4= X-Gm-Gg: ASbGncu6n4SfPA/Z81VzDZA7puRAPQCnEF1mT/IQDcu9r9JqO20DtE87VcvETHcu7fW D4yvH41bKUgO4KyrtBNN3qRve5A0ouj1Dd7hsZqU= X-Google-Smtp-Source: AGHT+IG6nI3DVh1P6YaizT31FYcJtRS4JXWglkvMJIsgqm7eWVk+QVUzeM6nVKdd8932xcSlplhe2STMpGJIXQ/70E8= X-Received: by 2002:a05:6102:c0e:b0:4b2:9e5c:130c with SMTP id ada2fe7eead31-4b2cc31e2cfmr2101269137.2.1734681491509; Thu, 19 Dec 2024 23:58:11 -0800 (PST) MIME-Version: 1.0 References: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> <20241120201313.t4wbhld4ktgielaf@erthalion.local> In-Reply-To: From: jian he Date: Fri, 20 Dec 2024 15:57:33 +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 hi. review is based on v20241219-0002-Storage-for-session-variables-and-SQL-interface.patch and v20241219-0001-Enhancing-catalog-for-support-session-variables-and-.patch. in doc/src/sgml/catalogs.sgml defaclobjtype char Type of object this entry is for: r = relation (table, view), S = sequence, f = function, T = type, n = schema this need updated for session variable? psql meta command \ddp src/bin/psql/describe.c listDefaultACLs also need to change. ----------------<<>>------------------------- +-- show variable +SELECT public.svar; +SELECT public.svar.c; +SELECT (public.svar).*; + +-- the variable is shadowed, raise error +SELECT public.svar.c FROM public.svar; + +-- can be fixed by alias +SELECT public.svar.c FROM public.svar x The above tests are duplicated in session_variables.sql. ----------------<<>>------------------------- --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -49,7 +49,7 @@ typedef struct PlannedStmt NodeTag type; - CmdType commandType; /* select|insert|update|delete|merge|utility */ + CmdType commandType; /* select|let|insert|update|delete|merge|utility */ since we don't have CMD_LET CmdType. so this comment change is not necessary? ----------------<<>>------------------------- the following are simple tests that triggers makeParamSessionVariable error messages. we don't have related tests, we can add it on session_variables.sql. create type t1 as (a int, b int); CREATE VARIABLE v1 text; CREATE VARIABLE v2 as t1; select v1.a; select v2.c; also select v2.c; ERROR: could not identify column "c" in variable LINE 1: select v2.c; ^ the error message is no good. i think we want: ERROR: could not identify column "c" in variable "public.v1" ----------------<<>>------------------------- + /* + * Check for duplicates. Note that this does not really prevent + * duplicates, it's here just to provide nicer error message in common + * case. The real protection is the unique key on the catalog. + */ + if (SearchSysCacheExists2(VARIABLENAMENSP, + PointerGetDatum(varName), + ObjectIdGetDatum(varNamespace))) + { + } I am confused by these comments. i think the SearchSysCacheExists2 do actually prevent duplicates. I noticed that publication_add_relation also has similar comments. ----------------<<>>------------------------- typedef struct LetStmt { NodeTag type; List *target; /* target variable */ Node *query; /* source expression */ int location; } LetStmt; here, location should be a type of ParseLoc. ----------------<<>>------------------------- in 0001, 0002, function SetSessionVariableWithSecurityCheck never being used. ----------------<<>>------------------------- +/* + * transformLetStmt - + * transform an Let Statement + */ +static Query * +transformLetStmt(ParseState *pstate, LetStmt *stmt) ... + /* + * Save target session variable ID. This value is used multiple times: by + * the query rewriter (for getting related defexpr), by planner (for + * acquiring an AccessShareLock on target variable), and by the executor + * (we need to know the target variable ID). + */ + query->resultVariable = varid; "defexpr", do you mean "default expression"? Generally letsmt is like: "let variable = (SelectStmt)" is there nothing related to the DEFAULT expression? "(we need to know the target variable ID)." in ExecuteLetStmt that is true. but I commented out the following lines, the regress test still succeeded. extract_query_dependencies_walker /* record dependency on the target variable of a LET command */ // if (OidIsValid(query->resultVariable)) // record_plan_variable_dependency(context, query->resultVariable); ScanQueryForLocks // /* process session variables */ // if (OidIsValid(parsetree->resultVariable)) // { // if (acquire) // LockDatabaseObject(VariableRelationId, parsetree->resultVariable, // 0, AccessShareLock); // else // UnlockDatabaseObject(VariableRelationId, parsetree->resultVariable, // 0, AccessShareLock); // } ----------------<<>>------------------------- in transformLetStmt, we already did ACL privilege check, we don't need do it again at ExecuteLetStmt?