pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aleksander Alekseev <a.alekseev@postgrespro.ru>
To: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: [BUGS] 10.0: Logical replication doesn't execute BEFORE UPDATE OF <columns> trigger
Date: Tue, 10 Oct 2017 13:26:13 +0300
Message-ID: <20171010102613.GA28161@e733.localdomain> (raw)
In-Reply-To: <CAD21AoA_LHYD06qTLjGbE2_L8vp-LDdV1d97WLw=DWf3p=3SLw@mail.gmail.com>
References: <20171009141341.GA16999@e733.localdomain>
	<CAD21AoCZg1FLa3vqS3=+HB-j3PCq6Z02DCDm19vSufONd4Wvaw@mail.gmail.com>
	<CAD21AoA_LHYD06qTLjGbE2_L8vp-LDdV1d97WLw=DWf3p=3SLw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Hi Masahiko,

> > I think the cause of this issue is that the apply worker doesn't set
> > updatedCols of RangeTblEntry when applying updates. So TriggerEnabled
> > always ends up with false. I'll make a patch and submit.
> >
> 
> Attached patch store the updated columns bitmap set to RangeTblEntry.
> In my environment this bug seems to be fixed by the patch.

Thanks a lot for a quick response. I can confirm that your patch fixes
the issue and passes all tests. Hopefully someone will merge it shortly.

Here is another patch from me. It adds a corresponding TAP test. Before
applying your patch:

```
t/001_rep_changes.pl .. ok
t/002_types.pl ........ ok   
t/003_constraints.pl .. 1/5
#   Failed test 'check replica trigger with specified list of affected columns applied on subscriber'
#   at t/003_constraints.pl line 151.
#          got: 'k2|v1'
#     expected: 'k2|v1
# triggered|true'
# Looks like you failed 1 test of 5.
t/003_constraints.pl .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/5 subtests
t/004_sync.pl ......... ok
t/005_encoding.pl ..... ok
t/006_rewrite.pl ...... ok
t/007_ddl.pl .......... ok
```

After:

```
t/001_rep_changes.pl .. ok
t/002_types.pl ........ ok
t/003_constraints.pl .. ok
t/004_sync.pl ......... ok
t/005_encoding.pl ..... ok
t/006_rewrite.pl ...... ok
t/007_ddl.pl .......... ok
All tests successful.
```

-- 
Best regards,
Aleksander Alekseev

Attachments:

subscription_new_tap_test.patch (text/x-diff, 2.5K) download diff --git a/src/test/subscription/t/003_constraints.pl b/src/test/subscription/t/003_constraints.pl index 06863aef84..f1fc5ae863 100644 --- a/src/test/subscription/t/003_constraints.pl +++ b/src/test/subscription/t/003_constraints.pl @@ -3,7 +3,7 @@ use strict; use warnings; use PostgresNode; use TestLib; -use Test::More tests => 4; +use Test::More tests => 5; # Initialize publisher node my $node_publisher = get_new_node('publisher'); @@ -21,6 +21,9 @@ $node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres', "CREATE TABLE tab_fk_ref (id int PRIMARY KEY, bid int REFERENCES tab_fk (bid));" ); +$node_publisher->safe_psql('postgres', +"CREATE TABLE tab_upd_tst (k TEXT PRIMARY KEY, v TEXT);" +); # Setup structure on subscriber $node_subscriber->safe_psql('postgres', @@ -28,6 +31,9 @@ $node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres', "CREATE TABLE tab_fk_ref (id int PRIMARY KEY, bid int REFERENCES tab_fk (bid));" ); +$node_subscriber->safe_psql('postgres', +"CREATE TABLE tab_upd_tst (k TEXT PRIMARY KEY, v TEXT);" +); # Setup logical replication my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; @@ -112,5 +118,38 @@ $result = $node_subscriber->safe_psql('postgres', "SELECT count(*), min(bid), max(bid) FROM tab_fk_ref;"); is($result, qq(2|1|2), 'check replica trigger applied on subscriber'); +# Add replica trigger with specified list of affected columns +$node_subscriber->safe_psql( + 'postgres', qq{ +CREATE OR REPLACE FUNCTION upd_fn() +RETURNS trigger AS \$\$ +BEGIN + INSERT INTO tab_upd_tst VALUES ('triggered', 'true'); + RETURN NEW; +END +\$\$ LANGUAGE plpgsql; + +CREATE TRIGGER upd_trg +BEFORE UPDATE OF k ON tab_upd_tst +FOR EACH ROW EXECUTE PROCEDURE upd_fn(); + +ALTER TABLE tab_upd_tst ENABLE REPLICA TRIGGER upd_trg; +}); + +# Insert data +$node_publisher->safe_psql('postgres', + "INSERT INTO tab_upd_tst (k, v) VALUES ('k1', 'v1');"); +$node_publisher->safe_psql('postgres', + "UPDATE tab_upd_tst SET k = 'k2' WHERE k = 'k1';"); + +$node_publisher->poll_query_until('postgres', $caughtup_query) + or die "Timed out while waiting for subscriber to catch up"; + +# Trigger should be executed +$result = + $node_subscriber->safe_psql('postgres', "SELECT k, v FROM tab_upd_tst ORDER BY k"); +is( $result, qq(k2|v1 +triggered|true), 'check replica trigger with specified list of affected columns applied on subscriber'); + $node_subscriber->stop('fast'); $node_publisher->stop('fast');
signature.asc (application/pgp-signature, 832B) download

view thread (7+ messages)  latest in thread

Message-ID: <20171010102613.GA28161@e733.localdomain>
Permalink:  ../20171010102613.GA28161@e733.localdomain/
Also on:    postgresql.org/message-id/20171010102613.GA28161@e733.localdomain

 ·  · 

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-bugs@postgresql.org
  Cc: a.alekseev@postgrespro.ru, sawada.mshk@gmail.com, pgsql-hackers@postgresql.org
  Subject: Re: [BUGS] 10.0: Logical replication doesn't execute BEFORE UPDATE OF <columns> trigger
  In-Reply-To: <20171010102613.GA28161@e733.localdomain>
  References: <20171009141341.GA16999@e733.localdomain> <CAD21AoCZg1FLa3vqS3=+HB-j3PCq6Z02DCDm19vSufONd4Wvaw@mail.gmail.com> <CAD21AoA_LHYD06qTLjGbE2_L8vp-LDdV1d97WLw=DWf3p=3SLw@mail.gmail.com> <20171010102613.GA28161@e733.localdomain>

* 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