Update copyright for 2022
[pgsql.git] / contrib / bloom / t / 001_wal.pl
blob06e664688a01ddc0c160ad19bd02a15d40480359
2 # Copyright (c) 2021-2022, PostgreSQL Global Development Group
4 # Test generic xlog record work for bloom index replication.
5 use strict;
6 use warnings;
7 use PostgreSQL::Test::Cluster;
8 use PostgreSQL::Test::Utils;
9 use Test::More tests => 31;
11 my $node_primary;
12 my $node_standby;
14 # Run few queries on both primary and standby and check their results match.
15 sub test_index_replay
17 my ($test_name) = @_;
19 local $Test::Builder::Level = $Test::Builder::Level + 1;
21 # Wait for standby to catch up
22 $node_primary->wait_for_catchup($node_standby);
24 my $queries = qq(SET enable_seqscan=off;
25 SET enable_bitmapscan=on;
26 SET enable_indexscan=on;
27 SELECT * FROM tst WHERE i = 0;
28 SELECT * FROM tst WHERE i = 3;
29 SELECT * FROM tst WHERE t = 'b';
30 SELECT * FROM tst WHERE t = 'f';
31 SELECT * FROM tst WHERE i = 3 AND t = 'c';
32 SELECT * FROM tst WHERE i = 7 AND t = 'e';
35 # Run test queries and compare their result
36 my $primary_result = $node_primary->safe_psql("postgres", $queries);
37 my $standby_result = $node_standby->safe_psql("postgres", $queries);
39 is($primary_result, $standby_result, "$test_name: query result matches");
40 return;
43 # Initialize primary node
44 $node_primary = PostgreSQL::Test::Cluster->new('primary');
45 $node_primary->init(allows_streaming => 1);
46 $node_primary->start;
47 my $backup_name = 'my_backup';
49 # Take backup
50 $node_primary->backup($backup_name);
52 # Create streaming standby linking to primary
53 $node_standby = PostgreSQL::Test::Cluster->new('standby');
54 $node_standby->init_from_backup($node_primary, $backup_name,
55 has_streaming => 1);
56 $node_standby->start;
58 # Create some bloom index on primary
59 $node_primary->safe_psql("postgres", "CREATE EXTENSION bloom;");
60 $node_primary->safe_psql("postgres", "CREATE TABLE tst (i int4, t text);");
61 $node_primary->safe_psql("postgres",
62 "INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,100000) i;"
64 $node_primary->safe_psql("postgres",
65 "CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (col1 = 3);");
67 # Test that queries give same result
68 test_index_replay('initial');
70 # Run 10 cycles of table modification. Run test queries after each modification.
71 for my $i (1 .. 10)
73 $node_primary->safe_psql("postgres", "DELETE FROM tst WHERE i = $i;");
74 test_index_replay("delete $i");
75 $node_primary->safe_psql("postgres", "VACUUM tst;");
76 test_index_replay("vacuum $i");
77 my ($start, $end) = (100001 + ($i - 1) * 10000, 100000 + $i * 10000);
78 $node_primary->safe_psql("postgres",
79 "INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series($start,$end) i;"
81 test_index_replay("insert $i");