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 1uHqtL-00B2cR-Nr for pgsql-hackers@arkaria.postgresql.org; Wed, 21 May 2025 21:22:23 +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 1uHqtK-00BQYa-Jt for pgsql-hackers@arkaria.postgresql.org; Wed, 21 May 2025 21:22:22 +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 1uHqtK-00BQXt-AP for pgsql-hackers@lists.postgresql.org; Wed, 21 May 2025 21:22:22 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uHqtH-000CTY-3D for pgsql-hackers@lists.postgresql.org; Wed, 21 May 2025 21:22:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2025010100; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-ID:Content-Description; bh=zWEYcqAVwaXoWW6a5tfBh3VaPdQUAn0phewzV5aZsrc=; b=NlkzEt6XWe8Okx/1TrxV5xsJI2 zJ+RnDJ5MtmHL5oQV8k395Dgbc13ftVk2iLZAtjW+v5J9NtkGRUiyTtjH4qwzm8jxcW+Py/v6f/Iz PsIhmLFWDxImKPFTtOBgj3ESgmbnt4+hcbs/XM/N07JKNI0scmP+L2pL0rb6XErGeUcCAziaSUIeH JFL9vYdZxdImdzf2hXXt7CORkXgzxRjDYqrL7F6IrGGCuPiFxnF34/q2qqVHywdpEuPWtWQ5CVxJ5 lN7RBvTXQML+z9xBSLngFuxaMQLrB54XLoWXMCb7TC3UEs7TvDQjvw9T59W2mIK747/5fDwxQXnsO t9nu/tog==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1uHqtD-00GQzp-0e; Wed, 21 May 2025 17:22:15 -0400 Date: Wed, 21 May 2025 17:22:15 -0400 From: Bruce Momjian To: Pavel Stehule Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Laurenz Albe , Erik Rijkers , Michael Paquier , Amit Kapila , DUVAL REMI , PostgreSQL Hackers , jian he , Alvaro Herrera Subject: Re: proposal: schema variables Message-ID: References: <3chredgnjcmccym2kczawfih226b4ac6co7p6z4jeofevrcosi@mrsxkx2x2c65> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 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 On Wed, May 21, 2025 at 09:12:54AM +0200, Pavel Stehule wrote: > Last discussion is related to reducing the size of the session variable patch > set. > > I have an idea to use variable's fencing more aggressively from the start, and > then we can reduce it in future. This should not break issues with > compatibility and doesn't need some like version flags. > > The real problem of proposed session variables is possible collisions between > session variables identifiers and table or columns identifiers. I designed some > tools to minimize the risk of unwanted collisions, but these tools increase the > size of code and don't reduce the complexity of the patch and tests. The > proposed change probably doesn't reduce a lot of code, but can reduce some > tests, and mainly possible risk of some unwanted impact - at the end it can be > less work for reviewers and less stress for committers - and the implementation > can be divided to allone workable following steps. Yes, I remember the discussions about how the creation of server variables could break existing queries. Our scoping rules are already complex, so adding another scope would add a lot of complexity. > Step 1 > ===== > > So the main change is the hard requirement for usage variable's fence > everywhere where collisions are possible - and then in the first step, the > collisions will not be possible, and then we don't need it to solve, and we > don't need to test it. > > CREATE VARIABLE public.foo AS int; > LET foo = 10; > SELECT VARIABLE(foo); Yes, I can see how adding fencing like VARIABLE() would simplify things. > Step 2 > ===== > Necessity of usage variable fencing in PL/pgSQL can be a problem for migration > from PL/SQL. But this can be solved separately by using SPI params hooks - > similar to how PL/pgSQL works with PL/pgSQL variables. In this step we can push > optimization for fast execution of the LET statement or optimization of usage > variables in queries. Yes, there is already going to be migration requirements in moving from PL/SQL to PL/pgSQL, so the requirement to add VARIABLE() seems minimal. > After this step will be possible: > > DO $$ > BEGIN >   RAISE NOTICE '% %', foo, VARIABLE(public.foo); > END; > $$; > > SELECT VARIABLE(foo); > > No other visible change in this step. WIth this step the people who do > migration form Oracle and PL/pgSQL developers will be very happy. They don't > need more. There can be collisions, but the collisions can be limited just to > PL/pgSQL scope, and we can use already implemented mechanisms. > > Step 3 > ===== > We can talk in future about less requirement of usage variable fencing in > queries. This needs to introduce some form of detection collisions and how they > should be solved (outside PL/pgSQL). > We can talk about other features like temporal, default values, transactional, > etc ... I feel that if we haven't found a good solution to this in 13 years, we should assume it is unsolvable and just accept an imperfect solution. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Do not let urgent matters crowd out time for investment in the future.