2 -- Test SP-GiST indexes.
4 -- There are other tests to test different SP-GiST opclasses. This is for
5 -- testing SP-GiST code itself.
6 create table spgist_point_tbl(id int4, p point);
7 create index spgist_point_idx on spgist_point_tbl using spgist(p) with (fillfactor = 75);
8 -- Test vacuum-root operation. It gets invoked when the root is also a leaf,
9 -- i.e. the index is very small.
10 insert into spgist_point_tbl (id, p)
11 select g, point(g*10, g*10) from generate_series(1, 10) g;
12 delete from spgist_point_tbl where id < 5;
13 vacuum spgist_point_tbl;
14 -- Insert more data, to make the index a few levels deep.
15 insert into spgist_point_tbl (id, p)
16 select g, point(g*10, g*10) from generate_series(1, 10000) g;
17 insert into spgist_point_tbl (id, p)
18 select g+100000, point(g*10+1, g*10+1) from generate_series(1, 10000) g;
19 -- To test vacuum, delete some entries from all over the index.
20 delete from spgist_point_tbl where id % 2 = 1;
21 -- And also delete some concentration of values. (SP-GiST doesn't currently
22 -- attempt to delete pages even when they become empty, but if it did, this
24 delete from spgist_point_tbl where id < 10000;
25 vacuum spgist_point_tbl;
26 -- Test rescan paths (cf. bug #15378)
27 -- use box and && rather than point, so that rescan happens when the
28 -- traverse stack is non-empty
29 create table spgist_box_tbl(id serial, b box);
30 insert into spgist_box_tbl(b)
31 select box(point(i,j),point(i+s,j+s))
32 from generate_series(1,100,5) i,
33 generate_series(1,100,5) j,
34 generate_series(1,10) s;
35 create index spgist_box_idx on spgist_box_tbl using spgist (b);
37 from (values (point(5,5)),(point(8,8)),(point(12,12))) v(p)
38 where exists(select * from spgist_box_tbl b where b.b && box(v.p,v.p));
44 -- The point opclass's choose method only uses the spgMatchNode action,
45 -- so the other actions are not tested by the above. Create an index using
46 -- text opclass, which uses the others actions.
47 create table spgist_text_tbl(id int4, t text);
48 create index spgist_text_idx on spgist_text_tbl using spgist(t);
49 insert into spgist_text_tbl (id, t)
50 select g, 'f' || repeat('o', 100) || g from generate_series(1, 10000) g
52 select g, 'baaaaaaaaaaaaaar' || g from generate_series(1, 1000) g;
53 -- Do a lot of insertions that have to split an existing node. Hopefully
54 -- one of these will cause the page to run out of space, causing the inner
55 -- tuple to be moved to another page.
56 insert into spgist_text_tbl (id, t)
57 select -g, 'f' || repeat('o', 100-g) || 'surprise' from generate_series(1, 100) g;
58 -- Test out-of-range fillfactor values
59 create index spgist_point_idx2 on spgist_point_tbl using spgist(p) with (fillfactor = 9);
60 ERROR: value 9 out of bounds for option "fillfactor"
61 DETAIL: Valid values are between "10" and "100".
62 create index spgist_point_idx2 on spgist_point_tbl using spgist(p) with (fillfactor = 101);
63 ERROR: value 101 out of bounds for option "fillfactor"
64 DETAIL: Valid values are between "10" and "100".
65 -- Modify fillfactor in existing index
66 alter index spgist_point_idx set (fillfactor = 90);
67 reindex index spgist_point_idx;
68 -- Test index over a domain
69 create domain spgist_text as varchar;
70 create table spgist_domain_tbl (f1 spgist_text);
71 create index spgist_domain_idx on spgist_domain_tbl using spgist(f1);
72 insert into spgist_domain_tbl values('fee'), ('fi'), ('fo'), ('fum');
74 select * from spgist_domain_tbl where f1 = 'fo';
76 -----------------------------------------------
77 Bitmap Heap Scan on spgist_domain_tbl
78 Recheck Cond: ((f1)::text = 'fo'::text)
79 -> Bitmap Index Scan on spgist_domain_idx
80 Index Cond: ((f1)::text = 'fo'::text)
83 select * from spgist_domain_tbl where f1 = 'fo';
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