Debian Codegraph @

contrib/pageinspect/sql/gist.sql

raw
1 -- The gist_page_opaque_info() function prints the page's LSN.
2 -- Use an unlogged index, so that the LSN is predictable.
3 CREATE UNLOGGED TABLE test_gist AS SELECT point(i,i) p, i::text t FROM
4 generate_series(1,1000) i;
5 CREATE INDEX test_gist_idx ON test_gist USING gist (p);
6
7 -- Page 0 is the root, the rest are leaf pages
8 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 0));
9 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 1));
10 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2));
11
12 SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx');
13 SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 1), 'test_gist_idx') LIMIT 5;
14
15 -- gist_page_items_bytea prints the raw key data as a bytea. The output of that is
16 -- platform-dependent (endianness), so omit the actual key data from the output.
17 SELECT itemoffset, ctid, itemlen FROM gist_page_items_bytea(get_raw_page('test_gist_idx', 0));
18
19 -- Suppress the DETAIL message, to allow the tests to work across various
20 -- page sizes and architectures.
21 \set VERBOSITY terse
22
23 -- Failures with non-GiST index.
24 CREATE INDEX test_gist_btree on test_gist(t);
25 SELECT gist_page_items(get_raw_page('test_gist_btree', 0), 'test_gist_btree');
26 SELECT gist_page_items(get_raw_page('test_gist_btree', 0), 'test_gist_idx');
27
28 -- Failure with various modes.
29 -- invalid page size
30 SELECT gist_page_items_bytea('aaa'::bytea);
31 SELECT gist_page_items('aaa'::bytea, 'test_gist_idx'::regclass);
32 SELECT gist_page_opaque_info('aaa'::bytea);
33 -- invalid special area size
34 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist', 0));
35 SELECT gist_page_items_bytea(get_raw_page('test_gist', 0));
36 SELECT gist_page_items_bytea(get_raw_page('test_gist_btree', 0));
37 \set VERBOSITY default
38
39 -- Tests with all-zero pages.
40 SHOW block_size \gset
41 SELECT gist_page_items_bytea(decode(repeat('00', :block_size), 'hex'));
42 SELECT gist_page_items(decode(repeat('00', :block_size), 'hex'), 'test_gist_idx'::regclass);
43 SELECT gist_page_opaque_info(decode(repeat('00', :block_size), 'hex'));
44
45 -- Test gist_page_items with included columns.
46 -- Non-leaf pages contain only the key attributes, and leaf pages contain
47 -- the included attributes.
48 ALTER TABLE test_gist ADD COLUMN i int DEFAULT NULL;
49 CREATE INDEX test_gist_idx_inc ON test_gist
50 USING gist (p) INCLUDE (t, i);
51 -- Mask the value of the key attribute to avoid alignment issues.
52 SELECT regexp_replace(keys, '\(p\)=\("(.*?)"\)', '(p)=("<val>")') AS keys_nonleaf_1
53 FROM gist_page_items(get_raw_page('test_gist_idx_inc', 0), 'test_gist_idx_inc')
54 WHERE itemoffset = 1;
55 SELECT keys AS keys_leaf_1
56 FROM gist_page_items(get_raw_page('test_gist_idx_inc', 1), 'test_gist_idx_inc')
57 WHERE itemoffset = 1;
58
59 DROP TABLE test_gist;