pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Dominique Devienne <ddevienne@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: How to avoid Trigger ping/pong / infinite loop
Date: Thu, 16 Feb 2023 11:55:03 -0800
Message-ID: <26d69af5-a895-c388-04e8-76523d095d74@aklaver.com> (raw)
In-Reply-To: <CAFCRh-8J6JpJJZtBFoWod-3BWDAJqubX+XA7PsNG54uXmkisYQ@mail.gmail.com>
References: <CAFCRh-9gaDm41u-R1Ecc1=0hAtJnisxgqUC8csWUeJpkFGGxBQ@mail.gmail.com>
	<4790b5f7-f6ce-8399-78ad-398e13eb4b6f@aklaver.com>
	<CAFCRh-8J6JpJJZtBFoWod-3BWDAJqubX+XA7PsNG54uXmkisYQ@mail.gmail.com>

On 2/16/23 10:21, Dominique Devienne wrote:
> On Thu, Feb 16, 2023 at 6:58 PM Adrian Klaver <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>> 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






view thread (7+ messages)  latest in thread

Message-ID: <26d69af5-a895-c388-04e8-76523d095d74@aklaver.com>
Permalink:  ../26d69af5-a895-c388-04e8-76523d095d74@aklaver.com/
Also on:    postgresql.org/message-id/26d69af5-a895-c388-04e8-76523d095d74@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, ddevienne@gmail.com
  Subject: Re: How to avoid Trigger ping/pong / infinite loop
  In-Reply-To: <26d69af5-a895-c388-04e8-76523d095d74@aklaver.com>
  References: <CAFCRh-9gaDm41u-R1Ecc1=0hAtJnisxgqUC8csWUeJpkFGGxBQ@mail.gmail.com> <4790b5f7-f6ce-8399-78ad-398e13eb4b6f@aklaver.com> <CAFCRh-8J6JpJJZtBFoWod-3BWDAJqubX+XA7PsNG54uXmkisYQ@mail.gmail.com> <26d69af5-a895-c388-04e8-76523d095d74@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox