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

Commit cf223c3

Browse files
committed
Improve contrib/bloom regression test using code coverage info.
Originally, this test created a 100000-row test table, which made it run rather slowly compared to other contrib tests. Investigation with gcov showed that we got no further improvement in code coverage after the first 700 or so rows, making the large table 99% a waste of time. Cut it back to 2000 rows to fix the runtime problem and still leave some headroom for testing behaviors that may appear later. A closer look at the gcov results showed that the main coverage omissions in contrib/bloom occurred because the test never filled more than one entry in the notFullPage array; which is unsurprising because it exercised index cleanup only in the scenario of complete table deletion, allowing every page in the index to become deleted rather than not-full. Add testing that allows the not-full path to be exercised as well. Also, test the amvalidate function, because blvalidate.c had zero coverage without that, and besides it's a good idea to check for mistakes in the bloom opclass definitions.
1 parent bd905a0 commit cf223c3

File tree

2 files changed

+62
-16
lines changed

2 files changed

+62
-16
lines changed

contrib/bloom/expected/bloom.out

+46-14
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ CREATE TABLE tst (
33
i int4,
44
t text
55
);
6-
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,100000) i;
6+
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,2000) i;
77
CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (col1 = 3);
88
SET enable_seqscan=on;
99
SET enable_bitmapscan=off;
1010
SET enable_indexscan=off;
1111
SELECT count(*) FROM tst WHERE i = 7;
1212
count
1313
-------
14-
10000
14+
200
1515
(1 row)
1616

1717
SELECT count(*) FROM tst WHERE t = '5';
1818
count
1919
-------
20-
6264
20+
112
2121
(1 row)
2222

2323
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
2424
count
2525
-------
26-
588
26+
13
2727
(1 row)
2828

2929
SET enable_seqscan=off;
@@ -62,61 +62,93 @@ EXPLAIN (COSTS OFF) SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
6262
SELECT count(*) FROM tst WHERE i = 7;
6363
count
6464
-------
65-
10000
65+
200
6666
(1 row)
6767

6868
SELECT count(*) FROM tst WHERE t = '5';
6969
count
7070
-------
71-
6264
71+
112
7272
(1 row)
7373

7474
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
7575
count
7676
-------
77-
588
77+
13
7878
(1 row)
7979

8080
DELETE FROM tst;
81-
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,100000) i;
81+
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,2000) i;
8282
VACUUM ANALYZE tst;
8383
SELECT count(*) FROM tst WHERE i = 7;
8484
count
8585
-------
86-
10000
86+
200
8787
(1 row)
8888

8989
SELECT count(*) FROM tst WHERE t = '5';
9090
count
9191
-------
92-
6264
92+
112
9393
(1 row)
9494

9595
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
9696
count
9797
-------
98-
588
98+
13
99+
(1 row)
100+
101+
DELETE FROM tst WHERE i > 1 OR t = '5';
102+
VACUUM tst;
103+
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,2000) i;
104+
SELECT count(*) FROM tst WHERE i = 7;
105+
count
106+
-------
107+
200
108+
(1 row)
109+
110+
SELECT count(*) FROM tst WHERE t = '5';
111+
count
112+
-------
113+
112
114+
(1 row)
115+
116+
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
117+
count
118+
-------
119+
13
99120
(1 row)
100121

101122
VACUUM FULL tst;
102123
SELECT count(*) FROM tst WHERE i = 7;
103124
count
104125
-------
105-
10000
126+
200
106127
(1 row)
107128

108129
SELECT count(*) FROM tst WHERE t = '5';
109130
count
110131
-------
111-
6264
132+
112
112133
(1 row)
113134

114135
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
115136
count
116137
-------
117-
588
138+
13
118139
(1 row)
119140

120141
RESET enable_seqscan;
121142
RESET enable_bitmapscan;
122143
RESET enable_indexscan;
144+
-- Run amvalidator function on our opclasses
145+
SELECT opcname, amvalidate(opc.oid)
146+
FROM pg_opclass opc JOIN pg_am am ON am.oid = opcmethod
147+
WHERE amname = 'bloom'
148+
ORDER BY 1;
149+
opcname | amvalidate
150+
----------+------------
151+
int4_ops | t
152+
text_ops | t
153+
(2 rows)
154+

contrib/bloom/sql/bloom.sql

+16-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CREATE TABLE tst (
55
t text
66
);
77

8-
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,100000) i;
8+
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,2000) i;
99
CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (col1 = 3);
1010

1111
SET enable_seqscan=on;
@@ -29,13 +29,21 @@ SELECT count(*) FROM tst WHERE t = '5';
2929
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
3030

3131
DELETE FROM tst;
32-
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,100000) i;
32+
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,2000) i;
3333
VACUUM ANALYZE tst;
3434

3535
SELECT count(*) FROM tst WHERE i = 7;
3636
SELECT count(*) FROM tst WHERE t = '5';
3737
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
3838

39+
DELETE FROM tst WHERE i > 1 OR t = '5';
40+
VACUUM tst;
41+
INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,2000) i;
42+
43+
SELECT count(*) FROM tst WHERE i = 7;
44+
SELECT count(*) FROM tst WHERE t = '5';
45+
SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
46+
3947
VACUUM FULL tst;
4048

4149
SELECT count(*) FROM tst WHERE i = 7;
@@ -45,3 +53,9 @@ SELECT count(*) FROM tst WHERE i = 7 AND t = '5';
4553
RESET enable_seqscan;
4654
RESET enable_bitmapscan;
4755
RESET enable_indexscan;
56+
57+
-- Run amvalidator function on our opclasses
58+
SELECT opcname, amvalidate(opc.oid)
59+
FROM pg_opclass opc JOIN pg_am am ON am.oid = opcmethod
60+
WHERE amname = 'bloom'
61+
ORDER BY 1;

0 commit comments

Comments
 (0)