|
24 | 24 | create index brin_wi_idx on brin_wi using brin (a) with (pages_per_range=1, autosummarize=on); |
25 | 25 | ' |
26 | 26 | ); |
| 27 | +# Another table with an index that requires a snapshot to run |
| 28 | +$node->safe_psql( |
| 29 | + 'postgres', |
| 30 | + 'create table journal (d timestamp) with (fillfactor = 10); |
| 31 | + create function packdate(d timestamp) returns text language plpgsql |
| 32 | + as $$ begin return to_char(d, \'yyyymm\'); end; $$ |
| 33 | + returns null on null input immutable; |
| 34 | + create index brin_packdate_idx on journal using brin (packdate(d)) |
| 35 | + with (autosummarize = on, pages_per_range = 1); |
| 36 | + ' |
| 37 | +); |
| 38 | + |
27 | 39 | my $count = $node->safe_psql('postgres', |
28 | 40 | "select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)" |
29 | 41 | ); |
30 | | -is($count, '1', "initial index state is correct"); |
| 42 | +is($count, '1', "initial brin_wi_index index state is correct"); |
| 43 | +$count = $node->safe_psql('postgres', |
| 44 | + "select count(*) from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)" |
| 45 | +); |
| 46 | +is($count, '1', "initial brin_packdate_idx index state is correct"); |
31 | 47 |
|
32 | 48 | $node->safe_psql('postgres', |
33 | 49 | 'insert into brin_wi select * from generate_series(1, 100)'); |
| 50 | +$node->safe_psql('postgres', |
| 51 | + "insert into journal select * from generate_series(timestamp '1976-08-01', '1976-10-28', '1 day')" |
| 52 | +); |
| 53 | + |
| 54 | +# Give a little time for autovacuum to react. This matches the naptime |
| 55 | +# configured above. |
| 56 | +sleep(1); |
34 | 57 |
|
35 | 58 | $node->poll_query_until( |
36 | 59 | 'postgres', |
37 | 60 | "select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)", |
38 | 61 | 't'); |
39 | 62 |
|
40 | | -$count = $node->safe_psql('postgres', |
41 | | - "select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)" |
| 63 | +$count = $node->safe_psql( |
| 64 | + 'postgres', |
| 65 | + "select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass) |
| 66 | + where not placeholder;" |
| 67 | +); |
| 68 | +cmp_ok($count, '>', '1', "$count brin_wi_idx ranges got summarized"); |
| 69 | + |
| 70 | +$node->poll_query_until( |
| 71 | + 'postgres', |
| 72 | + "select count(*) > 1 from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)", |
| 73 | + 't'); |
| 74 | + |
| 75 | +$count = $node->safe_psql( |
| 76 | + 'postgres', |
| 77 | + "select count(*) from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass) |
| 78 | + where not placeholder;" |
42 | 79 | ); |
43 | | -is($count, 't', "index got summarized"); |
| 80 | +cmp_ok($count, '>', '1', "$count brin_packdate_idx ranges got summarized"); |
| 81 | + |
44 | 82 | $node->stop; |
45 | 83 |
|
46 | 84 | done_testing(); |
0 commit comments