1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# Copyright (c) 2021, PostgreSQL Global Development Group
# Test collations, in particular nondeterministic ones
# (only works with ICU)
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More;
if ($ENV{with_icu} eq 'yes')
{
plan tests => 2;
}
else
{
plan skip_all => 'ICU not supported by this build';
}
my $node_publisher = get_new_node('publisher');
$node_publisher->init(
allows_streaming => 'logical',
extra => [ '--locale=C', '--encoding=UTF8' ]);
$node_publisher->start;
my $node_subscriber = get_new_node('subscriber');
$node_subscriber->init(
allows_streaming => 'logical',
extra => [ '--locale=C', '--encoding=UTF8' ]);
$node_subscriber->start;
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
# Test plan: Create a table with a nondeterministic collation in the
# primary key column. Pre-insert rows on the publisher and subscriber
# that are collation-wise equal but byte-wise different. (We use a
# string in different normal forms for that.) Set up publisher and
# subscriber. Update the row on the publisher, but don't change the
# primary key column. The subscriber needs to find the row to be
# updated using the nondeterministic collation semantics. We need to
# test for both a replica identity index and for replica identity
# full, since those have different code paths internally.
$node_subscriber->safe_psql('postgres',
q{CREATE COLLATION ctest_nondet (provider = icu, locale = 'und', deterministic = false)}
);
# table with replica identity index
$node_publisher->safe_psql('postgres',
q{CREATE TABLE tab1 (a text PRIMARY KEY, b text)});
$node_publisher->safe_psql('postgres',
q{INSERT INTO tab1 VALUES (U&'\00E4bc', 'foo')});
$node_subscriber->safe_psql('postgres',
q{CREATE TABLE tab1 (a text COLLATE ctest_nondet PRIMARY KEY, b text)});
$node_subscriber->safe_psql('postgres',
q{INSERT INTO tab1 VALUES (U&'\0061\0308bc', 'foo')});
# table with replica identity full
$node_publisher->safe_psql('postgres', q{CREATE TABLE tab2 (a text, b text)});
$node_publisher->safe_psql('postgres',
q{ALTER TABLE tab2 REPLICA IDENTITY FULL});
$node_publisher->safe_psql('postgres',
q{INSERT INTO tab2 VALUES (U&'\00E4bc', 'foo')});
$node_subscriber->safe_psql('postgres',
q{CREATE TABLE tab2 (a text COLLATE ctest_nondet, b text)});
$node_subscriber->safe_psql('postgres',
q{ALTER TABLE tab2 REPLICA IDENTITY FULL});
$node_subscriber->safe_psql('postgres',
q{INSERT INTO tab2 VALUES (U&'\0061\0308bc', 'foo')});
# set up publication, subscription
$node_publisher->safe_psql('postgres',
q{CREATE PUBLICATION pub1 FOR ALL TABLES});
$node_subscriber->safe_psql('postgres',
qq{CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub1 WITH (copy_data = false)}
);
$node_publisher->wait_for_catchup('sub1');
# test with replica identity index
$node_publisher->safe_psql('postgres',
q{UPDATE tab1 SET b = 'bar' WHERE b = 'foo'});
$node_publisher->wait_for_catchup('sub1');
is($node_subscriber->safe_psql('postgres', q{SELECT b FROM tab1}),
qq(bar), 'update with primary key with nondeterministic collation');
# test with replica identity full
$node_publisher->safe_psql('postgres',
q{UPDATE tab2 SET b = 'bar' WHERE b = 'foo'});
$node_publisher->wait_for_catchup('sub1');
is($node_subscriber->safe_psql('postgres', q{SELECT b FROM tab2}),
qq(bar),
'update with replica identity full with nondeterministic collation');
|