Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7054c23

Browse files
author
Commitfest Bot
committed
[CF 5715] amcheck support for BRIN indexes
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5715 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAE7r3MKZkMwuEeFU5M73Jk3yp+2CBr41a3tfvb3CHym+ysAVEA@mail.gmail.com Author(s): Arseniy Mukhin
2 parents c3eda50 + 9467670 commit 7054c23

File tree

11 files changed

+1539
-5
lines changed

11 files changed

+1539
-5
lines changed

contrib/amcheck/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ OBJS = \
66
verify_common.o \
77
verify_gin.o \
88
verify_heapam.o \
9-
verify_nbtree.o
9+
verify_nbtree.o \
10+
verify_brinam.o
1011

1112
EXTENSION = amcheck
1213
DATA = amcheck--1.2--1.3.sql amcheck--1.1--1.2.sql amcheck--1.0--1.1.sql amcheck--1.0.sql \
13-
amcheck--1.3--1.4.sql amcheck--1.4--1.5.sql
14+
amcheck--1.3--1.4.sql amcheck--1.4--1.5.sql amcheck--1.5--1.6.sql
1415
PGFILEDESC = "amcheck - function for verifying relation integrity"
1516

1617
REGRESS = check check_btree check_gin check_heap

contrib/amcheck/amcheck--1.5--1.6.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* contrib/amcheck/amcheck--1.5--1.6.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "ALTER EXTENSION amcheck UPDATE TO '1.6'" to load this file. \quit
5+
6+
7+
--
8+
-- brin_index_check()
9+
--
10+
CREATE FUNCTION brin_index_check(index regclass,
11+
regular_pages_check boolean default false,
12+
heap_all_consistent boolean default false,
13+
consistent_operator_names text[] default '{}'
14+
)
15+
RETURNS VOID
16+
AS 'MODULE_PATHNAME', 'brin_index_check'
17+
LANGUAGE C STRICT PARALLEL RESTRICTED;
18+
19+
-- We don't want this to be available to public
20+
REVOKE ALL ON FUNCTION brin_index_check(regclass, boolean, boolean, text[]) FROM PUBLIC;

contrib/amcheck/amcheck.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# amcheck extension
22
comment = 'functions for verifying relation integrity'
3-
default_version = '1.5'
3+
default_version = '1.6'
44
module_pathname = '$libdir/amcheck'
55
relocatable = true
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
-- helper func
2+
CREATE OR REPLACE FUNCTION random_string( INT ) RETURNS TEXT AS $$
3+
SELECT string_agg(substring('0123456789bcdfghjkmnpqrstvwxyz', ceil(random() * 30)::INTEGER, 1), '') FROM generate_series(1, $1);
4+
$$ LANGUAGE sql;
5+
-- empty table index should be valid
6+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
7+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a);
8+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
9+
brin_index_check
10+
------------------
11+
12+
(1 row)
13+
14+
-- cleanup
15+
DROP TABLE brintest;
16+
-- multi attributes with varlena attribute test
17+
CREATE TABLE brintest (id BIGSERIAL, a TEXT) WITH (FILLFACTOR = 10);
18+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a TEXT_minmax_ops, id int8_minmax_ops) WITH (PAGES_PER_RANGE = 2);
19+
INSERT INTO brintest (a) SELECT random_string((x % 100)) FROM generate_series(1,5000) x;
20+
-- create some empty ranges
21+
DELETE FROM brintest WHERE id > 2000 AND id < 4000;
22+
SELECT brin_index_check('brintest_a_idx'::REGCLASS);
23+
brin_index_check
24+
------------------
25+
26+
(1 row)
27+
28+
-- rebuild index
29+
DROP INDEX brintest_a_idx;
30+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a TEXT_minmax_ops) WITH (PAGES_PER_RANGE = 2);
31+
SELECT brin_index_check('brintest_a_idx'::REGCLASS);
32+
brin_index_check
33+
------------------
34+
35+
(1 row)
36+
37+
-- cleanup
38+
DROP TABLE brintest;
39+
-- min_max opclass
40+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
41+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_ops) WITH (PAGES_PER_RANGE = 2);
42+
INSERT INTO brintest (a) SELECT x FROM generate_series(1,100000) x;
43+
-- create some empty ranges
44+
DELETE FROM brintest WHERE a > 20000 AND a < 40000;
45+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
46+
brin_index_check
47+
------------------
48+
49+
(1 row)
50+
51+
-- rebuild index
52+
DROP INDEX brintest_a_idx;
53+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_ops) WITH (PAGES_PER_RANGE = 2);
54+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
55+
brin_index_check
56+
------------------
57+
58+
(1 row)
59+
60+
-- cleanup
61+
DROP TABLE brintest;
62+
-- multi_min_max opclass
63+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
64+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_multi_ops) WITH (PAGES_PER_RANGE = 2);
65+
INSERT INTO brintest (a) SELECT x FROM generate_series(1,100000) x;
66+
-- create some empty ranges
67+
DELETE FROM brintest WHERE a > 20000 AND a < 40000;
68+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
69+
brin_index_check
70+
------------------
71+
72+
(1 row)
73+
74+
-- rebuild index
75+
DROP INDEX brintest_a_idx;
76+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_multi_ops) WITH (PAGES_PER_RANGE = 2);
77+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
78+
brin_index_check
79+
------------------
80+
81+
(1 row)
82+
83+
-- cleanup
84+
DROP TABLE brintest;
85+
-- bloom opclass
86+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
87+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_bloom_ops) WITH (PAGES_PER_RANGE = 2);
88+
INSERT INTO brintest (a) SELECT x FROM generate_series(1,100000) x;
89+
-- create some empty ranges
90+
DELETE FROM brintest WHERE a > 20000 AND a < 40000;
91+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
92+
brin_index_check
93+
------------------
94+
95+
(1 row)
96+
97+
-- rebuild index
98+
DROP INDEX brintest_a_idx;
99+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_bloom_ops) WITH (PAGES_PER_RANGE = 2);
100+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
101+
brin_index_check
102+
------------------
103+
104+
(1 row)
105+
106+
-- cleanup
107+
DROP TABLE brintest;
108+
-- inclusion opclass
109+
CREATE TABLE brintest (id SERIAL PRIMARY KEY, a BOX);
110+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a BOX_INCLUSION_OPS) WITH (PAGES_PER_RANGE = 2);
111+
INSERT INTO brintest (a)
112+
SELECT BOX(point(random() * 1000, random() * 1000), point(random() * 1000, random() * 1000))
113+
FROM generate_series(1, 10000);
114+
-- create some empty ranges
115+
DELETE FROM brintest WHERE id > 2000 AND id < 4000;
116+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true, '{"@>"}');
117+
brin_index_check
118+
------------------
119+
120+
(1 row)
121+
122+
-- rebuild index
123+
DROP INDEX brintest_a_idx;
124+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a BOX_INCLUSION_OPS) WITH (PAGES_PER_RANGE = 2);
125+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true, '{"@>"}');
126+
brin_index_check
127+
------------------
128+
129+
(1 row)
130+
131+
-- cleanup
132+
DROP TABLE brintest;
133+
-- cleanup
134+
DROP FUNCTION random_string;

contrib/amcheck/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ amcheck_sources = files(
55
'verify_gin.c',
66
'verify_heapam.c',
77
'verify_nbtree.c',
8+
'verify_brinam.c'
89
)
910

1011
if host_system == 'windows'
@@ -27,6 +28,7 @@ install_data(
2728
'amcheck--1.2--1.3.sql',
2829
'amcheck--1.3--1.4.sql',
2930
'amcheck--1.4--1.5.sql',
31+
'amcheck--1.5--1.6.sql',
3032
kwargs: contrib_data_args,
3133
)
3234

@@ -40,6 +42,7 @@ tests += {
4042
'check_btree',
4143
'check_gin',
4244
'check_heap',
45+
'check_brin'
4346
],
4447
},
4548
'tap': {

contrib/amcheck/sql/check_brin.sql

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
-- helper func
2+
CREATE OR REPLACE FUNCTION random_string( INT ) RETURNS TEXT AS $$
3+
SELECT string_agg(substring('0123456789bcdfghjkmnpqrstvwxyz', ceil(random() * 30)::INTEGER, 1), '') FROM generate_series(1, $1);
4+
$$ LANGUAGE sql;
5+
6+
7+
-- empty table index should be valid
8+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
9+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a);
10+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
11+
-- cleanup
12+
DROP TABLE brintest;
13+
14+
15+
-- multi attributes with varlena attribute test
16+
CREATE TABLE brintest (id BIGSERIAL, a TEXT) WITH (FILLFACTOR = 10);
17+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a TEXT_minmax_ops, id int8_minmax_ops) WITH (PAGES_PER_RANGE = 2);
18+
INSERT INTO brintest (a) SELECT random_string((x % 100)) FROM generate_series(1,5000) x;
19+
-- create some empty ranges
20+
DELETE FROM brintest WHERE id > 2000 AND id < 4000;
21+
SELECT brin_index_check('brintest_a_idx'::REGCLASS);
22+
23+
-- rebuild index
24+
DROP INDEX brintest_a_idx;
25+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a TEXT_minmax_ops) WITH (PAGES_PER_RANGE = 2);
26+
SELECT brin_index_check('brintest_a_idx'::REGCLASS);
27+
-- cleanup
28+
DROP TABLE brintest;
29+
30+
31+
32+
-- min_max opclass
33+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
34+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_ops) WITH (PAGES_PER_RANGE = 2);
35+
INSERT INTO brintest (a) SELECT x FROM generate_series(1,100000) x;
36+
-- create some empty ranges
37+
DELETE FROM brintest WHERE a > 20000 AND a < 40000;
38+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
39+
40+
-- rebuild index
41+
DROP INDEX brintest_a_idx;
42+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_ops) WITH (PAGES_PER_RANGE = 2);
43+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
44+
-- cleanup
45+
DROP TABLE brintest;
46+
47+
48+
49+
-- multi_min_max opclass
50+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
51+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_multi_ops) WITH (PAGES_PER_RANGE = 2);
52+
INSERT INTO brintest (a) SELECT x FROM generate_series(1,100000) x;
53+
-- create some empty ranges
54+
DELETE FROM brintest WHERE a > 20000 AND a < 40000;
55+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
56+
57+
-- rebuild index
58+
DROP INDEX brintest_a_idx;
59+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_minmax_multi_ops) WITH (PAGES_PER_RANGE = 2);
60+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
61+
-- cleanup
62+
DROP TABLE brintest;
63+
64+
65+
66+
-- bloom opclass
67+
CREATE TABLE brintest (a BIGINT) WITH (FILLFACTOR = 10);
68+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_bloom_ops) WITH (PAGES_PER_RANGE = 2);
69+
INSERT INTO brintest (a) SELECT x FROM generate_series(1,100000) x;
70+
-- create some empty ranges
71+
DELETE FROM brintest WHERE a > 20000 AND a < 40000;
72+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
73+
74+
-- rebuild index
75+
DROP INDEX brintest_a_idx;
76+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a int8_bloom_ops) WITH (PAGES_PER_RANGE = 2);
77+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true);
78+
-- cleanup
79+
DROP TABLE brintest;
80+
81+
82+
-- inclusion opclass
83+
CREATE TABLE brintest (id SERIAL PRIMARY KEY, a BOX);
84+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a BOX_INCLUSION_OPS) WITH (PAGES_PER_RANGE = 2);
85+
INSERT INTO brintest (a)
86+
SELECT BOX(point(random() * 1000, random() * 1000), point(random() * 1000, random() * 1000))
87+
FROM generate_series(1, 10000);
88+
-- create some empty ranges
89+
DELETE FROM brintest WHERE id > 2000 AND id < 4000;
90+
91+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true, '{"@>"}');
92+
93+
-- rebuild index
94+
DROP INDEX brintest_a_idx;
95+
CREATE INDEX brintest_a_idx ON brintest USING BRIN (a BOX_INCLUSION_OPS) WITH (PAGES_PER_RANGE = 2);
96+
SELECT brin_index_check('brintest_a_idx'::REGCLASS, true, true, '{"@>"}');
97+
-- cleanup
98+
DROP TABLE brintest;
99+
100+
101+
-- cleanup
102+
DROP FUNCTION random_string;

0 commit comments

Comments
 (0)