Skip to content

Commit 1d2fec9

Browse files
committed
Avoid loss of code coverage with unlogged-index test cases.
Commit 4fb5c79 intended to add coverage of some ambuildempty methods that were not getting reached, without removing any test coverage. However, by changing a temp table to unlogged it managed to negate the intent of 4c51a2d, which means that we didn't have reliable test coverage of ginvacuum.c anymore. As things stand, much of that file might or might not get reached depending on timing, which seems pretty undesirable. Although this is only clearly broken for the GIN test, it seems best to revert 4fb5c79 altogether and instead add bespoke test cases covering unlogged indexes for these four AMs. We don't need to do very much with them, so the extra tests are cheap. (Note that btree, hash, and bloom already have similar test cases, so they need no additional work.) We can also undo dec8ad3. Since the testing deficiency that that hacked around was later fixed by 2f2e24d, let's intentionally leave an unlogged table behind to improve test coverage in the modules that use the regression database for other test purposes. (The case I used also leaves an unlogged sequence behind.) Per report from Alex Kozhemyakin. Back-patch to v15 where the faulty test came in. Discussion: https://postgr.es/m/b00c8ee096ee46cd25c183125562a1a7@postgrespro.ru
1 parent dda1013 commit 1d2fec9

File tree

8 files changed

+68
-10
lines changed

8 files changed

+68
-10
lines changed

src/test/regress/expected/brin.out

+6-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ ERROR: block number out of range: -1
484484
SELECT brin_summarize_range('brin_summarize_idx', 4294967296);
485485
ERROR: block number out of range: 4294967296
486486
-- test value merging in add_value
487-
CREATE UNLOGGED TABLE brintest_2 (n numrange);
487+
CREATE TABLE brintest_2 (n numrange);
488488
CREATE INDEX brinidx_2 ON brintest_2 USING brin (n);
489489
INSERT INTO brintest_2 VALUES ('empty');
490490
INSERT INTO brintest_2 VALUES (numrange(0, 2^1000::numeric));
@@ -567,3 +567,8 @@ SELECT * FROM brintest_3 WHERE b < '0';
567567

568568
DROP TABLE brintest_3;
569569
RESET enable_seqscan;
570+
-- test an unlogged table, mostly to get coverage of brinbuildempty
571+
CREATE UNLOGGED TABLE brintest_unlogged (n numrange);
572+
CREATE INDEX brinidx_unlogged ON brintest_unlogged USING brin (n);
573+
INSERT INTO brintest_unlogged VALUES (numrange(0, 2^1000::numeric));
574+
DROP TABLE brintest_unlogged;

src/test/regress/expected/gin.out

+10-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ select count(*) > 0 as ok from gin_test_tbl where i @> array[1];
7474

7575
reset gin_fuzzy_search_limit;
7676
-- Test optimization of empty queries
77-
create unlogged table t_gin_test_tbl(i int4[], j int4[]);
77+
create temp table t_gin_test_tbl(i int4[], j int4[]);
7878
create index on t_gin_test_tbl using gin (i, j);
7979
insert into t_gin_test_tbl
8080
values
@@ -288,3 +288,12 @@ select count(*) from t_gin_test_tbl where j @> '{}'::int[];
288288
reset enable_seqscan;
289289
reset enable_bitmapscan;
290290
drop table t_gin_test_tbl;
291+
-- test an unlogged table, mostly to get coverage of ginbuildempty
292+
create unlogged table t_gin_test_tbl(i int4[], j int4[]);
293+
create index on t_gin_test_tbl using gin (i, j);
294+
insert into t_gin_test_tbl
295+
values
296+
(null, null),
297+
('{}', null),
298+
('{1}', '{2,3}');
299+
drop table t_gin_test_tbl;

src/test/regress/expected/gist.out

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ reindex index gist_pointidx;
3636
--
3737
-- Test Index-only plans on GiST indexes
3838
--
39-
create unlogged table gist_tbl (b box, p point, c circle);
39+
create table gist_tbl (b box, p point, c circle);
4040
insert into gist_tbl
4141
select box(point(0.05*i, 0.05*i), point(0.05*i, 0.05*i)),
4242
point(0.05*i, 0.05*i),
@@ -395,3 +395,9 @@ reset enable_seqscan;
395395
reset enable_bitmapscan;
396396
reset enable_indexonlyscan;
397397
drop table gist_tbl;
398+
-- test an unlogged table, mostly to get coverage of gistbuildempty
399+
create unlogged table gist_tbl (b box);
400+
create index gist_tbl_box_index on gist_tbl using gist (b);
401+
insert into gist_tbl
402+
select box(point(0.05*i, 0.05*i)) from generate_series(0,10) as i;
403+
drop table gist_tbl;

src/test/regress/expected/spgist.out

+9-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ vacuum spgist_point_tbl;
2626
-- Test rescan paths (cf. bug #15378)
2727
-- use box and && rather than point, so that rescan happens when the
2828
-- traverse stack is non-empty
29-
create unlogged table spgist_box_tbl(id serial, b box);
29+
create table spgist_box_tbl(id serial, b box);
3030
insert into spgist_box_tbl(b)
3131
select box(point(i,j),point(i+s,j+s))
3232
from generate_series(1,100,5) i,
@@ -41,7 +41,6 @@ select count(*)
4141
3
4242
(1 row)
4343

44-
drop table spgist_box_tbl;
4544
-- The point opclass's choose method only uses the spgMatchNode action,
4645
-- so the other actions are not tested by the above. Create an index using
4746
-- text opclass, which uses the others actions.
@@ -87,3 +86,11 @@ select * from spgist_domain_tbl where f1 = 'fo';
8786
fo
8887
(1 row)
8988

89+
-- test an unlogged table, mostly to get coverage of spgistbuildempty
90+
create unlogged table spgist_unlogged_tbl(id serial, b box);
91+
create index spgist_unlogged_idx on spgist_unlogged_tbl using spgist (b);
92+
insert into spgist_unlogged_tbl(b)
93+
select box(point(i,j))
94+
from generate_series(1,100,5) i,
95+
generate_series(1,10,5) j;
96+
-- leave this table around, to help in testing dump/restore

src/test/regress/sql/brin.sql

+7-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ SELECT brin_summarize_range('brin_summarize_idx', -1);
449449
SELECT brin_summarize_range('brin_summarize_idx', 4294967296);
450450

451451
-- test value merging in add_value
452-
CREATE UNLOGGED TABLE brintest_2 (n numrange);
452+
CREATE TABLE brintest_2 (n numrange);
453453
CREATE INDEX brinidx_2 ON brintest_2 USING brin (n);
454454
INSERT INTO brintest_2 VALUES ('empty');
455455
INSERT INTO brintest_2 VALUES (numrange(0, 2^1000::numeric));
@@ -509,3 +509,9 @@ SELECT * FROM brintest_3 WHERE b < '0';
509509

510510
DROP TABLE brintest_3;
511511
RESET enable_seqscan;
512+
513+
-- test an unlogged table, mostly to get coverage of brinbuildempty
514+
CREATE UNLOGGED TABLE brintest_unlogged (n numrange);
515+
CREATE INDEX brinidx_unlogged ON brintest_unlogged USING brin (n);
516+
INSERT INTO brintest_unlogged VALUES (numrange(0, 2^1000::numeric));
517+
DROP TABLE brintest_unlogged;

src/test/regress/sql/gin.sql

+11-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ select count(*) > 0 as ok from gin_test_tbl where i @> array[1];
5252
reset gin_fuzzy_search_limit;
5353

5454
-- Test optimization of empty queries
55-
create unlogged table t_gin_test_tbl(i int4[], j int4[]);
55+
create temp table t_gin_test_tbl(i int4[], j int4[]);
5656
create index on t_gin_test_tbl using gin (i, j);
5757
insert into t_gin_test_tbl
5858
values
@@ -171,3 +171,13 @@ reset enable_seqscan;
171171
reset enable_bitmapscan;
172172

173173
drop table t_gin_test_tbl;
174+
175+
-- test an unlogged table, mostly to get coverage of ginbuildempty
176+
create unlogged table t_gin_test_tbl(i int4[], j int4[]);
177+
create index on t_gin_test_tbl using gin (i, j);
178+
insert into t_gin_test_tbl
179+
values
180+
(null, null),
181+
('{}', null),
182+
('{1}', '{2,3}');
183+
drop table t_gin_test_tbl;

src/test/regress/sql/gist.sql

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ reindex index gist_pointidx;
4141
-- Test Index-only plans on GiST indexes
4242
--
4343

44-
create unlogged table gist_tbl (b box, p point, c circle);
44+
create table gist_tbl (b box, p point, c circle);
4545

4646
insert into gist_tbl
4747
select box(point(0.05*i, 0.05*i), point(0.05*i, 0.05*i)),
@@ -179,3 +179,10 @@ reset enable_bitmapscan;
179179
reset enable_indexonlyscan;
180180

181181
drop table gist_tbl;
182+
183+
-- test an unlogged table, mostly to get coverage of gistbuildempty
184+
create unlogged table gist_tbl (b box);
185+
create index gist_tbl_box_index on gist_tbl using gist (b);
186+
insert into gist_tbl
187+
select box(point(0.05*i, 0.05*i)) from generate_series(0,10) as i;
188+
drop table gist_tbl;

src/test/regress/sql/spgist.sql

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ vacuum spgist_point_tbl;
3434
-- use box and && rather than point, so that rescan happens when the
3535
-- traverse stack is non-empty
3636

37-
create unlogged table spgist_box_tbl(id serial, b box);
37+
create table spgist_box_tbl(id serial, b box);
3838
insert into spgist_box_tbl(b)
3939
select box(point(i,j),point(i+s,j+s))
4040
from generate_series(1,100,5) i,
@@ -45,7 +45,6 @@ create index spgist_box_idx on spgist_box_tbl using spgist (b);
4545
select count(*)
4646
from (values (point(5,5)),(point(8,8)),(point(12,12))) v(p)
4747
where exists(select * from spgist_box_tbl b where b.b && box(v.p,v.p));
48-
drop table spgist_box_tbl;
4948

5049
-- The point opclass's choose method only uses the spgMatchNode action,
5150
-- so the other actions are not tested by the above. Create an index using
@@ -81,3 +80,12 @@ insert into spgist_domain_tbl values('fee'), ('fi'), ('fo'), ('fum');
8180
explain (costs off)
8281
select * from spgist_domain_tbl where f1 = 'fo';
8382
select * from spgist_domain_tbl where f1 = 'fo';
83+
84+
-- test an unlogged table, mostly to get coverage of spgistbuildempty
85+
create unlogged table spgist_unlogged_tbl(id serial, b box);
86+
create index spgist_unlogged_idx on spgist_unlogged_tbl using spgist (b);
87+
insert into spgist_unlogged_tbl(b)
88+
select box(point(i,j))
89+
from generate_series(1,100,5) i,
90+
generate_series(1,10,5) j;
91+
-- leave this table around, to help in testing dump/restore

0 commit comments

Comments
 (0)