Avoid loss of code coverage with unlogged-index test cases.
authorTom Lane <[email protected]>
Sun, 25 Sep 2022 17:10:10 +0000 (13:10 -0400)
committerTom Lane <[email protected]>
Sun, 25 Sep 2022 17:10:17 +0000 (13:10 -0400)
Commit 4fb5c794e 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 4c51a2d1e, 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 4fb5c794e 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 dec8ad367.  Since the testing deficiency that that
hacked around was later fixed by 2f2e24d90, 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

src/test/regress/expected/brin.out
src/test/regress/expected/gin.out
src/test/regress/expected/gist.out
src/test/regress/expected/spgist.out
src/test/regress/sql/brin.sql
src/test/regress/sql/gin.sql
src/test/regress/sql/gist.sql
src/test/regress/sql/spgist.sql

index ae4c424e79f3606e3f42579e370caba4aee10d98..73fa38396e4c0f161e4c163cc18d5f8c6a87bab0 100644 (file)
@@ -484,7 +484,7 @@ ERROR:  block number out of range: -1
 SELECT brin_summarize_range('brin_summarize_idx', 4294967296);
 ERROR:  block number out of range: 4294967296
 -- test value merging in add_value
-CREATE UNLOGGED TABLE brintest_2 (n numrange);
+CREATE TABLE brintest_2 (n numrange);
 CREATE INDEX brinidx_2 ON brintest_2 USING brin (n);
 INSERT INTO brintest_2 VALUES ('empty');
 INSERT INTO brintest_2 VALUES (numrange(0, 2^1000::numeric));
@@ -567,3 +567,8 @@ SELECT * FROM brintest_3 WHERE b < '0';
 
 DROP TABLE brintest_3;
 RESET enable_seqscan;
+-- test an unlogged table, mostly to get coverage of brinbuildempty
+CREATE UNLOGGED TABLE brintest_unlogged (n numrange);
+CREATE INDEX brinidx_unlogged ON brintest_unlogged USING brin (n);
+INSERT INTO brintest_unlogged VALUES (numrange(0, 2^1000::numeric));
+DROP TABLE brintest_unlogged;
index 1a0c3c6167fad4cfa93765fa287372e949962166..0af464309ee976afa6f71bbbfb38cc4068055c04 100644 (file)
@@ -74,7 +74,7 @@ select count(*) > 0 as ok from gin_test_tbl where i @> array[1];
 
 reset gin_fuzzy_search_limit;
 -- Test optimization of empty queries
-create unlogged table t_gin_test_tbl(i int4[], j int4[]);
+create temp table t_gin_test_tbl(i int4[], j int4[]);
 create index on t_gin_test_tbl using gin (i, j);
 insert into t_gin_test_tbl
 values
@@ -288,3 +288,12 @@ select count(*) from t_gin_test_tbl where j @> '{}'::int[];
 reset enable_seqscan;
 reset enable_bitmapscan;
 drop table t_gin_test_tbl;
+-- test an unlogged table, mostly to get coverage of ginbuildempty
+create unlogged table t_gin_test_tbl(i int4[], j int4[]);
+create index on t_gin_test_tbl using gin (i, j);
+insert into t_gin_test_tbl
+values
+  (null,    null),
+  ('{}',    null),
+  ('{1}',   '{2,3}');
+drop table t_gin_test_tbl;
index 822000cca703afadc7768b06227c73c839a2bf1e..c75bbb23b6e387e5c29cf248a617c938e16aff0c 100644 (file)
@@ -36,7 +36,7 @@ reindex index gist_pointidx;
 --
 -- Test Index-only plans on GiST indexes
 --
-create unlogged table gist_tbl (b box, p point, c circle);
+create table gist_tbl (b box, p point, c circle);
 insert into gist_tbl
 select box(point(0.05*i, 0.05*i), point(0.05*i, 0.05*i)),
        point(0.05*i, 0.05*i),
@@ -395,3 +395,9 @@ reset enable_seqscan;
 reset enable_bitmapscan;
 reset enable_indexonlyscan;
 drop table gist_tbl;
+-- test an unlogged table, mostly to get coverage of gistbuildempty
+create unlogged table gist_tbl (b box);
+create index gist_tbl_box_index on gist_tbl using gist (b);
+insert into gist_tbl
+  select box(point(0.05*i, 0.05*i)) from generate_series(0,10) as i;
+drop table gist_tbl;
index f07b6f0145e4b86210a65b5fb58d6d30c0faa799..2e9112856000abd5ebac9b9fd1ff94d519c10445 100644 (file)
@@ -26,7 +26,7 @@ vacuum spgist_point_tbl;
 -- Test rescan paths (cf. bug #15378)
 -- use box and && rather than point, so that rescan happens when the
 -- traverse stack is non-empty
-create unlogged table spgist_box_tbl(id serial, b box);
+create table spgist_box_tbl(id serial, b box);
 insert into spgist_box_tbl(b)
 select box(point(i,j),point(i+s,j+s))
   from generate_series(1,100,5) i,
@@ -41,7 +41,6 @@ select count(*)
      3
 (1 row)
 
-drop table spgist_box_tbl;
 -- The point opclass's choose method only uses the spgMatchNode action,
 -- so the other actions are not tested by the above. Create an index using
 -- text opclass, which uses the others actions.
@@ -87,3 +86,11 @@ select * from spgist_domain_tbl where f1 = 'fo';
  fo
 (1 row)
 
+-- test an unlogged table, mostly to get coverage of spgistbuildempty
+create unlogged table spgist_unlogged_tbl(id serial, b box);
+create index spgist_unlogged_idx on spgist_unlogged_tbl using spgist (b);
+insert into spgist_unlogged_tbl(b)
+select box(point(i,j))
+  from generate_series(1,100,5) i,
+       generate_series(1,10,5) j;
+-- leave this table around, to help in testing dump/restore
index 33a30fcf777c7174a5c9bc34569fc8440073412b..e68e9e18df51d0b66978f1acdd6409b08ca17702 100644 (file)
@@ -449,7 +449,7 @@ SELECT brin_summarize_range('brin_summarize_idx', -1);
 SELECT brin_summarize_range('brin_summarize_idx', 4294967296);
 
 -- test value merging in add_value
-CREATE UNLOGGED TABLE brintest_2 (n numrange);
+CREATE TABLE brintest_2 (n numrange);
 CREATE INDEX brinidx_2 ON brintest_2 USING brin (n);
 INSERT INTO brintest_2 VALUES ('empty');
 INSERT INTO brintest_2 VALUES (numrange(0, 2^1000::numeric));
@@ -509,3 +509,9 @@ SELECT * FROM brintest_3 WHERE b < '0';
 
 DROP TABLE brintest_3;
 RESET enable_seqscan;
+
+-- test an unlogged table, mostly to get coverage of brinbuildempty
+CREATE UNLOGGED TABLE brintest_unlogged (n numrange);
+CREATE INDEX brinidx_unlogged ON brintest_unlogged USING brin (n);
+INSERT INTO brintest_unlogged VALUES (numrange(0, 2^1000::numeric));
+DROP TABLE brintest_unlogged;
index 746880937bb0a3587178feae1fa0c9e8feffdf98..0c6905ba3bb173589f6af1fc2e4b89c18615e1a9 100644 (file)
@@ -52,7 +52,7 @@ select count(*) > 0 as ok from gin_test_tbl where i @> array[1];
 reset gin_fuzzy_search_limit;
 
 -- Test optimization of empty queries
-create unlogged table t_gin_test_tbl(i int4[], j int4[]);
+create temp table t_gin_test_tbl(i int4[], j int4[]);
 create index on t_gin_test_tbl using gin (i, j);
 insert into t_gin_test_tbl
 values
@@ -171,3 +171,13 @@ reset enable_seqscan;
 reset enable_bitmapscan;
 
 drop table t_gin_test_tbl;
+
+-- test an unlogged table, mostly to get coverage of ginbuildempty
+create unlogged table t_gin_test_tbl(i int4[], j int4[]);
+create index on t_gin_test_tbl using gin (i, j);
+insert into t_gin_test_tbl
+values
+  (null,    null),
+  ('{}',    null),
+  ('{1}',   '{2,3}');
+drop table t_gin_test_tbl;
index 77a51bd6b390196fc360990e8c70a0a993f24119..6f1fc65f128a2f86d02e0a2f12ff95f06f6b57d1 100644 (file)
@@ -41,7 +41,7 @@ reindex index gist_pointidx;
 -- Test Index-only plans on GiST indexes
 --
 
-create unlogged table gist_tbl (b box, p point, c circle);
+create table gist_tbl (b box, p point, c circle);
 
 insert into gist_tbl
 select box(point(0.05*i, 0.05*i), point(0.05*i, 0.05*i)),
@@ -179,3 +179,10 @@ reset enable_bitmapscan;
 reset enable_indexonlyscan;
 
 drop table gist_tbl;
+
+-- test an unlogged table, mostly to get coverage of gistbuildempty
+create unlogged table gist_tbl (b box);
+create index gist_tbl_box_index on gist_tbl using gist (b);
+insert into gist_tbl
+  select box(point(0.05*i, 0.05*i)) from generate_series(0,10) as i;
+drop table gist_tbl;
index d56b80a51b6d36f422858cb9cf098574737277f3..4828ede68c3d9d002d6e75ed3bb0c013733c7f2b 100644 (file)
@@ -34,7 +34,7 @@ vacuum spgist_point_tbl;
 -- use box and && rather than point, so that rescan happens when the
 -- traverse stack is non-empty
 
-create unlogged table spgist_box_tbl(id serial, b box);
+create table spgist_box_tbl(id serial, b box);
 insert into spgist_box_tbl(b)
 select box(point(i,j),point(i+s,j+s))
   from generate_series(1,100,5) i,
@@ -45,7 +45,6 @@ create index spgist_box_idx on spgist_box_tbl using spgist (b);
 select count(*)
   from (values (point(5,5)),(point(8,8)),(point(12,12))) v(p)
  where exists(select * from spgist_box_tbl b where b.b && box(v.p,v.p));
-drop table spgist_box_tbl;
 
 -- The point opclass's choose method only uses the spgMatchNode action,
 -- 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');
 explain (costs off)
 select * from spgist_domain_tbl where f1 = 'fo';
 select * from spgist_domain_tbl where f1 = 'fo';
+
+-- test an unlogged table, mostly to get coverage of spgistbuildempty
+create unlogged table spgist_unlogged_tbl(id serial, b box);
+create index spgist_unlogged_idx on spgist_unlogged_tbl using spgist (b);
+insert into spgist_unlogged_tbl(b)
+select box(point(i,j))
+  from generate_series(1,100,5) i,
+       generate_series(1,10,5) j;
+-- leave this table around, to help in testing dump/restore