Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
 
# Copyright (c) 2021-2026, PostgreSQL Global Development Group
 
# Verify that work items work correctly
 
use strict;
use warnings FATAL => 'all';
 
use PostgreSQL::Test::Utils;
use Test::More;
use PostgreSQL::Test::Cluster;
 
my $node = PostgreSQL::Test::Cluster->new('tango');
$node->init;
$node->append_conf('postgresql.conf', 'autovacuum_naptime=1s');
$node->start;
 
$node->safe_psql('postgres', 'create extension pageinspect');
 
# Create a table with an autosummarizing BRIN index
$node->safe_psql(
    'postgres',
    'create table brin_wi (a int) with (fillfactor = 10);
     create index brin_wi_idx on brin_wi using brin (a) with (pages_per_range=1, autosummarize=on);
     '
);
# Another table with an index that requires a snapshot to run
$node->safe_psql(
    'postgres',
    'create table journal (d timestamp) with (fillfactor = 10);
     create function packdate(d timestamp) returns text language plpgsql
       as $$ begin return to_char(d, \'yyyymm\'); end; $$
       returns null on null input immutable;
     create index brin_packdate_idx on journal using brin (packdate(d))
       with (autosummarize = on, pages_per_range = 1);
     '
);
 
my $count = $node->safe_psql('postgres',
    "select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)"
);
is($count, '1', "initial brin_wi_idx index state is correct");
$count = $node->safe_psql('postgres',
    "select count(*) from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)"
);
is($count, '1', "initial brin_packdate_idx index state is correct");
 
$node->safe_psql('postgres',
    'insert into brin_wi select * from generate_series(1, 100)');
$node->safe_psql('postgres',
    "insert into journal select * from generate_series(timestamp '1976-08-01', '1976-10-28', '1 day')"
);
 
# Give a little time for autovacuum to react.  This matches the naptime
# configured above.
sleep(1);
 
$node->poll_query_until(
    'postgres',
    "select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)",
    't');
 
$count = $node->safe_psql(
    'postgres',
    "select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)
     where not placeholder;"
);
cmp_ok($count, '>', '1', "$count brin_wi_idx ranges got summarized");
 
$node->poll_query_until(
    'postgres',
    "select count(*) > 1 from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)",
    't');
 
$count = $node->safe_psql(
    'postgres',
    "select count(*) from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)
     where not placeholder;"
);
cmp_ok($count, '>', '1', "$count brin_packdate_idx ranges got summarized");
 
$node->stop;
 
done_testing();