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
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
Description: PGP signature