2014-11-19 18:24:58 +01:00
|
|
|
--
|
|
|
|
-- Test SP-GiST indexes.
|
|
|
|
--
|
|
|
|
-- There are other tests to test different SP-GiST opclasses. This is for
|
|
|
|
-- testing SP-GiST code itself.
|
|
|
|
create table spgist_point_tbl(id int4, p point);
|
2017-10-19 14:14:18 +02:00
|
|
|
create index spgist_point_idx on spgist_point_tbl using spgist(p) with (fillfactor = 75);
|
2014-11-19 18:24:58 +01:00
|
|
|
-- Test vacuum-root operation. It gets invoked when the root is also a leaf,
|
|
|
|
-- i.e. the index is very small.
|
|
|
|
insert into spgist_point_tbl (id, p)
|
|
|
|
select g, point(g*10, g*10) from generate_series(1, 10) g;
|
|
|
|
delete from spgist_point_tbl where id < 5;
|
|
|
|
vacuum spgist_point_tbl;
|
|
|
|
-- Insert more data, to make the index a few levels deep.
|
|
|
|
insert into spgist_point_tbl (id, p)
|
|
|
|
select g, point(g*10, g*10) from generate_series(1, 10000) g;
|
|
|
|
insert into spgist_point_tbl (id, p)
|
|
|
|
select g+100000, point(g*10+1, g*10+1) from generate_series(1, 10000) g;
|
|
|
|
-- To test vacuum, delete some entries from all over the index.
|
|
|
|
delete from spgist_point_tbl where id % 2 = 1;
|
|
|
|
-- And also delete some concentration of values. (SP-GiST doesn't currently
|
|
|
|
-- attempt to delete pages even when they become empty, but if it did, this
|
|
|
|
-- would exercise it)
|
|
|
|
delete from spgist_point_tbl where id < 10000;
|
|
|
|
vacuum spgist_point_tbl;
|
2018-09-11 19:14:19 +02:00
|
|
|
-- Test rescan paths (cf. bug #15378)
|
|
|
|
-- use box and && rather than point, so that rescan happens when the
|
|
|
|
-- traverse stack is non-empty
|
Avoid loss of code coverage with unlogged-index test cases.
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
2022-09-25 19:10:10 +02:00
|
|
|
create table spgist_box_tbl(id serial, b box);
|
2018-09-11 19:14:19 +02:00
|
|
|
insert into spgist_box_tbl(b)
|
|
|
|
select box(point(i,j),point(i+s,j+s))
|
|
|
|
from generate_series(1,100,5) i,
|
|
|
|
generate_series(1,100,5) j,
|
|
|
|
generate_series(1,10) s;
|
|
|
|
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));
|
|
|
|
count
|
|
|
|
-------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
2014-11-19 18:24:58 +01:00
|
|
|
-- 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.
|
|
|
|
create table spgist_text_tbl(id int4, t text);
|
|
|
|
create index spgist_text_idx on spgist_text_tbl using spgist(t);
|
|
|
|
insert into spgist_text_tbl (id, t)
|
|
|
|
select g, 'f' || repeat('o', 100) || g from generate_series(1, 10000) g
|
|
|
|
union all
|
|
|
|
select g, 'baaaaaaaaaaaaaar' || g from generate_series(1, 1000) g;
|
|
|
|
-- Do a lot of insertions that have to split an existing node. Hopefully
|
|
|
|
-- one of these will cause the page to run out of space, causing the inner
|
|
|
|
-- tuple to be moved to another page.
|
|
|
|
insert into spgist_text_tbl (id, t)
|
|
|
|
select -g, 'f' || repeat('o', 100-g) || 'surprise' from generate_series(1, 100) g;
|
2017-10-19 14:14:18 +02:00
|
|
|
-- Test out-of-range fillfactor values
|
|
|
|
create index spgist_point_idx2 on spgist_point_tbl using spgist(p) with (fillfactor = 9);
|
|
|
|
ERROR: value 9 out of bounds for option "fillfactor"
|
|
|
|
DETAIL: Valid values are between "10" and "100".
|
|
|
|
create index spgist_point_idx2 on spgist_point_tbl using spgist(p) with (fillfactor = 101);
|
|
|
|
ERROR: value 101 out of bounds for option "fillfactor"
|
|
|
|
DETAIL: Valid values are between "10" and "100".
|
|
|
|
-- Modify fillfactor in existing index
|
|
|
|
alter index spgist_point_idx set (fillfactor = 90);
|
|
|
|
reindex index spgist_point_idx;
|
2021-11-20 20:29:56 +01:00
|
|
|
-- Test index over a domain
|
|
|
|
create domain spgist_text as varchar;
|
|
|
|
create table spgist_domain_tbl (f1 spgist_text);
|
|
|
|
create index spgist_domain_idx on spgist_domain_tbl using spgist(f1);
|
|
|
|
insert into spgist_domain_tbl values('fee'), ('fi'), ('fo'), ('fum');
|
|
|
|
explain (costs off)
|
|
|
|
select * from spgist_domain_tbl where f1 = 'fo';
|
|
|
|
QUERY PLAN
|
|
|
|
-----------------------------------------------
|
|
|
|
Bitmap Heap Scan on spgist_domain_tbl
|
|
|
|
Recheck Cond: ((f1)::text = 'fo'::text)
|
|
|
|
-> Bitmap Index Scan on spgist_domain_idx
|
|
|
|
Index Cond: ((f1)::text = 'fo'::text)
|
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
select * from spgist_domain_tbl where f1 = 'fo';
|
|
|
|
f1
|
|
|
|
----
|
|
|
|
fo
|
|
|
|
(1 row)
|
|
|
|
|
Avoid loss of code coverage with unlogged-index test cases.
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
2022-09-25 19:10:10 +02:00
|
|
|
-- 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
|