|
34 | 34 | invalid_entry_order_leaf_page_test();
|
35 | 35 | invalid_entry_order_inner_page_test();
|
36 | 36 | invalid_entry_columns_order_test();
|
| 37 | +inconsistent_with_parent_key__parent_key_corrupted_test(); |
| 38 | +inconsistent_with_parent_key__child_key_corrupted_test(); |
37 | 39 |
|
38 | 40 | sub invalid_entry_order_leaf_page_test
|
39 | 41 | {
|
@@ -159,6 +161,82 @@ sub invalid_entry_columns_order_test
|
159 | 161 | like($stderr, qr/$expected/);
|
160 | 162 | }
|
161 | 163 |
|
| 164 | +sub inconsistent_with_parent_key__parent_key_corrupted_test |
| 165 | +{ |
| 166 | + my $relname = "test"; |
| 167 | + my $indexname = "test_gin_idx"; |
| 168 | + |
| 169 | + # fill the table until we have a split |
| 170 | + $node->safe_psql( |
| 171 | + 'postgres', qq( |
| 172 | + DROP TABLE IF EXISTS $relname; |
| 173 | + CREATE TABLE $relname (a text[]); |
| 174 | + INSERT INTO $relname (a) VALUES (('{' || 'llllllllll' || random_string($filler_size) ||'}')::text[]); |
| 175 | + INSERT INTO $relname (a) VALUES (('{' || 'mmmmmmmmmm' || random_string($filler_size) ||'}')::text[]); |
| 176 | + INSERT INTO $relname (a) VALUES (('{' || 'nnnnnnnnnn' || random_string($filler_size) ||'}')::text[]); |
| 177 | + INSERT INTO $relname (a) VALUES (('{' || 'xxxxxxxxxx' || random_string($filler_size) ||'}')::text[]); |
| 178 | + INSERT INTO $relname (a) VALUES (('{' || 'yyyyyyyyyy' || random_string($filler_size) ||'}')::text[]); |
| 179 | + CREATE INDEX $indexname ON $relname USING gin (a); |
| 180 | + )); |
| 181 | + my $relpath = relation_filepath($indexname); |
| 182 | + |
| 183 | + $node->stop; |
| 184 | + |
| 185 | + my $blkno = 1; # root |
| 186 | + |
| 187 | + # we have nnnnnnnnnn... as parent key in the root, so replace it with something smaller then child's keys |
| 188 | + string_replace_block( |
| 189 | + $relpath, |
| 190 | + 'nnnnnnnnnn', |
| 191 | + 'aaaaaaaaaa', |
| 192 | + $blkno |
| 193 | + ); |
| 194 | + |
| 195 | + $node->start; |
| 196 | + |
| 197 | + my ($result, $stdout, $stderr) = $node->psql('postgres', qq(SELECT gin_index_check('$indexname'))); |
| 198 | + my $expected = "index \"$indexname\" has inconsistent records on page 3 offset 3"; |
| 199 | + like($stderr, qr/$expected/); |
| 200 | +} |
| 201 | + |
| 202 | +sub inconsistent_with_parent_key__child_key_corrupted_test |
| 203 | +{ |
| 204 | + my $relname = "test"; |
| 205 | + my $indexname = "test_gin_idx"; |
| 206 | + |
| 207 | + # fill the table until we have a split |
| 208 | + $node->safe_psql( |
| 209 | + 'postgres', qq( |
| 210 | + DROP TABLE IF EXISTS $relname; |
| 211 | + CREATE TABLE $relname (a text[]); |
| 212 | + INSERT INTO $relname (a) VALUES (('{' || 'llllllllll' || random_string($filler_size) ||'}')::text[]); |
| 213 | + INSERT INTO $relname (a) VALUES (('{' || 'mmmmmmmmmm' || random_string($filler_size) ||'}')::text[]); |
| 214 | + INSERT INTO $relname (a) VALUES (('{' || 'nnnnnnnnnn' || random_string($filler_size) ||'}')::text[]); |
| 215 | + INSERT INTO $relname (a) VALUES (('{' || 'xxxxxxxxxx' || random_string($filler_size) ||'}')::text[]); |
| 216 | + INSERT INTO $relname (a) VALUES (('{' || 'yyyyyyyyyy' || random_string($filler_size) ||'}')::text[]); |
| 217 | + CREATE INDEX $indexname ON $relname USING gin (a); |
| 218 | + )); |
| 219 | + my $relpath = relation_filepath($indexname); |
| 220 | + |
| 221 | + $node->stop; |
| 222 | + |
| 223 | + my $blkno = 3; # leaf |
| 224 | + |
| 225 | + # we have nnnnnnnnnn... as parent key in the root, so replace child key with something bigger |
| 226 | + string_replace_block( |
| 227 | + $relpath, |
| 228 | + 'nnnnnnnnnn', |
| 229 | + 'pppppppppp', |
| 230 | + $blkno |
| 231 | + ); |
| 232 | + |
| 233 | + $node->start; |
| 234 | + |
| 235 | + my ($result, $stdout, $stderr) = $node->psql('postgres', qq(SELECT gin_index_check('$indexname'))); |
| 236 | + my $expected = "index \"$indexname\" has inconsistent records on page 3 offset 3"; |
| 237 | + like($stderr, qr/$expected/); |
| 238 | +} |
| 239 | + |
162 | 240 | # Returns the filesystem path for the named relation.
|
163 | 241 | sub relation_filepath
|
164 | 242 | {
|
|
0 commit comments