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 1pSkLY-00029t-9U for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 19:55:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSkLW-0003AZ-Fx for pgsql-general@arkaria.postgresql.org; Thu, 16 Feb 2023 19:55:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSkLW-0003AQ-4V for pgsql-general@lists.postgresql.org; Thu, 16 Feb 2023 19:55:10 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSkLS-00025A-4l for pgsql-general@postgresql.org; Thu, 16 Feb 2023 19:55:09 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id D566F5C0103; Thu, 16 Feb 2023 14:55:04 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 Feb 2023 14:55:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1676577304; x= 1676663704; bh=G/tFIPe9ujkiEEeNFQq/StzAUAhf9O/hxLK+Of3aFXQ=; b=u 5P9MkIV/BHyksaEQYsNE+sbXrz4AKykjEhHcZLebkJnjPf/WHrx/lf2uieRjp+CN 0GKliLBQ9XHnUPHmHV9Q0PeH6eCysJ90QPRsjk7d8kFmECIj89Q5kJIWviQ8I816 Fc1HTrFef13PSMm00AERl0WqZ0r3nYlJCiuQa51kAHfwsf5IaUrCnIl4+VHWJLqY l65QP3qPBFFiGzfVl6CxkU0dADYhwaqYBCANq6dkk2Rxvq9adgKHmTFjrzTgtYg7 TF9nLYg651nElNtNNyTyGIRuXOo/MnA9KQCsjJE8q0+TqMJdSUW41jGaGGRK5GE5 yqKrV5lgyReyPDW4hqLaA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1676577304; x= 1676663704; bh=G/tFIPe9ujkiEEeNFQq/StzAUAhf9O/hxLK+Of3aFXQ=; b=H bfZ8iZajEvS11qkKfpOlem7KQKjKvYeS7ljcBEnuXs1CJEsssieA5Yl/3mcdcGbg mshE7h5Ef4Og6V3sd6RHj12hOvhHxTMaema8f9fp8tAqF47VawSyMltzIDma8il7 oORGhBHMIJ9VfQKIOvgPCD805XbDpkm6v7+WjPjRz6sU306KSYlVAbwDCJKY1vji R97er145UbwyWRcSvfjfmm7j+NuSFPKQBCLEJRKXZOP+uOuIwbpMV7PVJCQzawde HTAp774S94AeJnLZRxcS1s+Kd45MWrHyMIAkJ8n9wU9LlYoGJf4maVJKlrE0dYIM kQ9TG2voRiBhItGbrDC4Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudeijedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttdefjeenucfhrhhomheptegu rhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhmqeenucggtffrrghtthgvrhhnpeejgedthfeuhfetgfffvdehudelteegjeduveff keetgeejieehueduleelgfffffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Feb 2023 14:55:04 -0500 (EST) Message-ID: <26d69af5-a895-c388-04e8-76523d095d74@aklaver.com> Date: Thu, 16 Feb 2023 11:55:03 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: How to avoid Trigger ping/pong / infinite loop Content-Language: en-US To: Dominique Devienne Cc: pgsql-general@postgresql.org References: <4790b5f7-f6ce-8399-78ad-398e13eb4b6f@aklaver.com> From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/16/23 10:21, Dominique Devienne wrote: > On Thu, Feb 16, 2023 at 6:58 PM Adrian Klaver > wrote: > > > "... which would be either impossible or too slow to base any RLS > policy on." > > and > > "At time point, changing the legacy code base is not really an > option..." > > seem to be at odds. > > > I don't see why you say that. Because saying it is impossible to use while you say you are using it is contradictory. > > So is the current system working or not? > > > The legacy system is 3-tier, so uses the denormalized info in C++ in the > mid-tier, > while the new system uses PostgreSQL and is 2-tier, so the same denormalized > info must drive both modes of execution. The same code-base is used for > both, > but when different backends. Making the code base work under two back ends, > is already hard enough, w/o changing it more extensively to use a new > normalized > model even in the legacy case. So is that clearer? Not really. From your original post: "...had-hoc text format for values, in key-value pairs in a table, " So is the information in the mid-tier code in some 'table' like structure or in text form in a Postgres table. > > But that's a bit orthogonal to my question too. > > > I also have new code that will read and write that same > information, but > > would much prefer to use a normalized data model, the same one that > > would be appropriate for efficient RLS. > > > > So I'm wondering if I can have my cake and eat it too, by > synchronizing > > the normalized and denormalized information (necessarily duplicated > > then), server-side via triggers, w/o running into infinite loops. > > A VIEW over both sets of data? > > > I'm not following. How is that related to mutual synchronization via > triggers? Avoiding triggers all together by using a VIEW query to keep all the information in one place. Of course this depends on the answer to my question above about where the denormalized data is actually stored. > Keeping two copies of the data is of course denormalization, but cannot > be avoided. > One copy is basically an optimization for RLS, so could be read-only I > guess, making > the sync one-way and simpler, but then that would force any new code to > also use > the old denormalized way to update the info. Thus I'd prefer the new > model to be > read-write, but then that requires two-sync sync. Thus my question. -- Adrian Klaver adrian.klaver@aklaver.com