|
237 | 237 | $node_publisher->safe_psql('postgres',
|
238 | 238 | "CREATE TABLE tab_rowfilter_child (b text) INHERITS (tab_rowfilter_inherited)"
|
239 | 239 | );
|
| 240 | +$node_publisher->safe_psql('postgres', |
| 241 | + "CREATE TABLE tab_rowfilter_viaroot_part (a int) PARTITION BY RANGE (a)"); |
| 242 | +$node_publisher->safe_psql('postgres', |
| 243 | + "CREATE TABLE tab_rowfilter_viaroot_part_1 PARTITION OF tab_rowfilter_viaroot_part FOR VALUES FROM (1) TO (20)" |
| 244 | +); |
240 | 245 |
|
241 | 246 | # setup structure on subscriber
|
242 | 247 | $node_subscriber->safe_psql('postgres',
|
|
283 | 288 | $node_subscriber->safe_psql('postgres',
|
284 | 289 | "CREATE TABLE tab_rowfilter_child (b text) INHERITS (tab_rowfilter_inherited)"
|
285 | 290 | );
|
| 291 | +$node_subscriber->safe_psql('postgres', |
| 292 | + "CREATE TABLE tab_rowfilter_viaroot_part (a int)"); |
| 293 | +$node_subscriber->safe_psql('postgres', |
| 294 | + "CREATE TABLE tab_rowfilter_viaroot_part_1 (a int)" |
| 295 | +); |
286 | 296 |
|
287 | 297 | # setup logical replication
|
288 | 298 | $node_publisher->safe_psql('postgres',
|
|
330 | 340 | "CREATE PUBLICATION tap_pub_inherits FOR TABLE tab_rowfilter_inherited WHERE (a > 15)"
|
331 | 341 | );
|
332 | 342 |
|
| 343 | +# two publications, each publishing the partition through a different ancestor, with |
| 344 | +# different row filters |
| 345 | +$node_publisher->safe_psql('postgres', |
| 346 | + "CREATE PUBLICATION tap_pub_viaroot_1 FOR TABLE tab_rowfilter_viaroot_part WHERE (a > 15) WITH (publish_via_partition_root)" |
| 347 | +); |
| 348 | +$node_publisher->safe_psql('postgres', |
| 349 | + "CREATE PUBLICATION tap_pub_viaroot_2 FOR TABLE tab_rowfilter_viaroot_part_1 WHERE (a < 15) WITH (publish_via_partition_root)" |
| 350 | +); |
| 351 | + |
333 | 352 | #
|
334 | 353 | # The following INSERTs are executed before the CREATE SUBSCRIPTION, so these
|
335 | 354 | # SQL commands are for testing the initial data copy using logical replication.
|
|
376 | 395 | );
|
377 | 396 |
|
378 | 397 | $node_subscriber->safe_psql('postgres',
|
379 |
| - "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub_1, tap_pub_2, tap_pub_3, tap_pub_4a, tap_pub_4b, tap_pub_5a, tap_pub_5b, tap_pub_toast, tap_pub_inherits" |
| 398 | + "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub_1, tap_pub_2, tap_pub_3, tap_pub_4a, tap_pub_4b, tap_pub_5a, tap_pub_5b, tap_pub_toast, tap_pub_inherits, tap_pub_viaroot_2, tap_pub_viaroot_1" |
380 | 399 | );
|
381 | 400 |
|
382 | 401 | $node_publisher->wait_for_catchup($appname);
|
|
534 | 553 | "INSERT INTO tab_rowfilter_inherited (a) VALUES (14), (16)");
|
535 | 554 | $node_publisher->safe_psql('postgres',
|
536 | 555 | "INSERT INTO tab_rowfilter_child (a, b) VALUES (13, '13'), (17, '17')");
|
| 556 | +$node_publisher->safe_psql('postgres', |
| 557 | + "INSERT INTO tab_rowfilter_viaroot_part (a) VALUES (14), (15), (16)"); |
537 | 558 |
|
538 | 559 | $node_publisher->wait_for_catchup($appname);
|
539 | 560 |
|
|
688 | 709 | "SELECT a = repeat('1234567890', 200), b FROM tab_rowfilter_toast");
|
689 | 710 | is($result, qq(t|1), 'check replicated rows to tab_rowfilter_toast');
|
690 | 711 |
|
| 712 | +# Check expected replicated rows for tab_rowfilter_viaroot_part and |
| 713 | +# tab_rowfilter_viaroot_part_1. We should replicate only rows matching |
| 714 | +# the row filter for the top-level ancestor: |
| 715 | +# |
| 716 | +# tab_rowfilter_viaroot_part filter is: (a > 15) |
| 717 | +# - INSERT (14) NO, 14 < 15 |
| 718 | +# - INSERT (15) NO, 15 = 15 |
| 719 | +# - INSERT (16) YES, 16 > 15 |
| 720 | +$result = |
| 721 | + $node_subscriber->safe_psql('postgres', |
| 722 | + "SELECT a FROM tab_rowfilter_viaroot_part"); |
| 723 | +is( $result, qq(16), |
| 724 | + 'check replicated rows to tab_rowfilter_viaroot_part' |
| 725 | +); |
| 726 | + |
| 727 | +# Check there is no data in tab_rowfilter_viaroot_part_1 because rows are |
| 728 | +# replicated via the top most parent table tab_rowfilter_viaroot_part |
| 729 | +$result = |
| 730 | + $node_subscriber->safe_psql('postgres', |
| 731 | + "SELECT a FROM tab_rowfilter_viaroot_part_1"); |
| 732 | +is( $result, qq(), |
| 733 | + 'check replicated rows to tab_rowfilter_viaroot_part_1' |
| 734 | +); |
| 735 | + |
691 | 736 | # Testcase end: FOR TABLE with row filter publications
|
692 | 737 | # ======================================================
|
693 | 738 |
|
|
0 commit comments