From: Mark Dilger <mark.dilger@enterprisedb.com>
To: Mitar <mmitar@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Determining if a table really changed in a trigger
Date: Tue, 26 Oct 2021 15:46:54 -0700
Message-ID: <6526D693-D520-4B94-B44F-4A2770FBF778@enterprisedb.com> (raw)
In-Reply-To: <CAKLmikMy+90f3GSqeMKsiV-qTX0Zc3VyGDCerrOJHo_usV=K4A@mail.gmail.com>
References: <CAKLmikNjiz=zwf9suiAHoBLrRpjLTNsQ=f4PGD3RMFBxzR-3OA@mail.gmail.com>
<E35E8F8C-4F85-4FFB-8A98-B1924678874E@enterprisedb.com>
<CAKLmikPA6Nj65X_sbSh6XoROLuY_FeXd8AmpxuM-LWw5EnMxpQ@mail.gmail.com>
<AD34DA0A-C6F4-4993-953C-36D7D973315D@enterprisedb.com>
<CAKLmikMy+90f3GSqeMKsiV-qTX0Zc3VyGDCerrOJHo_usV=K4A@mail.gmail.com>
> On Oct 26, 2021, at 3:39 PM, Mitar <mmitar@gmail.com> wrote:
>
> On Tue, Oct 26, 2021 at 10:55 PM Mark Dilger
> <mark.dilger@enterprisedb.com> wrote:
>> Note that there is a performance cost to storing the old rows using the REFERENCING clause of the trigger
>
> Yea, by moving the trivial update check to a rule, I need REFERENCING
> only to see if there were any changes at all. This seems a bit
> excessive. Is there a way to check if any rows have been affected by
> an UPDATE inside a per statement trigger without using REFERENCING?
I felt the same way about it, but after glancing quickly through the code and docs nothing jumped out. The information is clearly available, as it gets returned at the end of the UPDATE statement in the "UPDATE 0" OR "UPDATE 3", but I don't see how to access that from the trigger. I might have to submit a patch for that if nobody else knows a way to get it. (Hopefully somebody will respond with the answer...?)
> I also notice that you check if a table has any rows with:
>
> SELECT true INTO have_rows FROM old_values LIMIT 1;
> IF have_rows THEN ...
>
> Is this just a question of style or is this a better approach than my:
>
> PERFORM * FROM old_values LIMIT 1;
> IF FOUND THEN ...
There is no reason to prefer my spelling of that over yours. I didn't put much thought into it, but rather just wrote it the first way that occurred to me.
—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
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: mark.dilger@enterprisedb.com, mmitar@gmail.com
Subject: Re: Determining if a table really changed in a trigger
In-Reply-To: <6526D693-D520-4B94-B44F-4A2770FBF778@enterprisedb.com>
References: <CAKLmikNjiz=zwf9suiAHoBLrRpjLTNsQ=f4PGD3RMFBxzR-3OA@mail.gmail.com> <E35E8F8C-4F85-4FFB-8A98-B1924678874E@enterprisedb.com> <CAKLmikPA6Nj65X_sbSh6XoROLuY_FeXd8AmpxuM-LWw5EnMxpQ@mail.gmail.com> <AD34DA0A-C6F4-4993-953C-36D7D973315D@enterprisedb.com> <CAKLmikMy+90f3GSqeMKsiV-qTX0Zc3VyGDCerrOJHo_usV=K4A@mail.gmail.com> <6526D693-D520-4B94-B44F-4A2770FBF778@enterprisedb.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