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 -- Page 0 is the root, the rest are leaf pages
7 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 0));
8 lsn | nsn | rightlink | flags
9 -----+-----+------------+-------
10 0/1 | 0/0 | 4294967295 | {}
13 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 1));
14 lsn | nsn | rightlink | flags
15 -----+-----+------------+--------
16 0/1 | 0/0 | 4294967295 | {leaf}
19 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist_idx', 2));
20 lsn | nsn | rightlink | flags
21 -----+-----+-----------+--------
22 0/1 | 0/0 | 1 | {leaf}
25 SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 0), 'test_gist_idx');
26 itemoffset | ctid | itemlen | dead | keys
27 ------------+-----------+---------+------+-------------------------------
28 1 | (1,65535) | 40 | f | (p)=("(185,185),(1,1)")
29 2 | (2,65535) | 40 | f | (p)=("(370,370),(186,186)")
30 3 | (3,65535) | 40 | f | (p)=("(555,555),(371,371)")
31 4 | (4,65535) | 40 | f | (p)=("(740,740),(556,556)")
32 5 | (5,65535) | 40 | f | (p)=("(870,870),(741,741)")
33 6 | (6,65535) | 40 | f | (p)=("(1000,1000),(871,871)")
36 SELECT * FROM gist_page_items(get_raw_page('test_gist_idx', 1), 'test_gist_idx') LIMIT 5;
37 itemoffset | ctid | itemlen | dead | keys
38 ------------+-------+---------+------+---------------------
39 1 | (0,1) | 40 | f | (p)=("(1,1),(1,1)")
40 2 | (0,2) | 40 | f | (p)=("(2,2),(2,2)")
41 3 | (0,3) | 40 | f | (p)=("(3,3),(3,3)")
42 4 | (0,4) | 40 | f | (p)=("(4,4),(4,4)")
43 5 | (0,5) | 40 | f | (p)=("(5,5),(5,5)")
46 -- gist_page_items_bytea prints the raw key data as a bytea. The output of that is
47 -- platform-dependent (endianness), so omit the actual key data from the output.
48 SELECT itemoffset, ctid, itemlen FROM gist_page_items_bytea(get_raw_page('test_gist_idx', 0));
49 itemoffset | ctid | itemlen
50 ------------+-----------+---------
59 -- Suppress the DETAIL message, to allow the tests to work across various
60 -- page sizes and architectures.
62 -- Failures with non-GiST index.
63 CREATE INDEX test_gist_btree on test_gist(t);
64 SELECT gist_page_items(get_raw_page('test_gist_btree', 0), 'test_gist_btree');
65 ERROR: "test_gist_btree" is not a GiST index
66 SELECT gist_page_items(get_raw_page('test_gist_btree', 0), 'test_gist_idx');
67 ERROR: input page is not a valid GiST page
68 -- Failure with various modes.
70 SELECT gist_page_items_bytea('aaa'::bytea);
71 ERROR: invalid page size
72 SELECT gist_page_items('aaa'::bytea, 'test_gist_idx'::regclass);
73 ERROR: invalid page size
74 SELECT gist_page_opaque_info('aaa'::bytea);
75 ERROR: invalid page size
76 -- invalid special area size
77 SELECT * FROM gist_page_opaque_info(get_raw_page('test_gist', 0));
78 ERROR: input page is not a valid GiST page
79 SELECT gist_page_items_bytea(get_raw_page('test_gist', 0));
80 ERROR: input page is not a valid GiST page
81 SELECT gist_page_items_bytea(get_raw_page('test_gist_btree', 0));
82 ERROR: input page is not a valid GiST page
83 \set VERBOSITY default
84 -- Tests with all-zero pages.
86 SELECT gist_page_items_bytea(decode(repeat('00', :block_size), 'hex'));
88 -----------------------
91 SELECT gist_page_items(decode(repeat('00', :block_size), 'hex'), 'test_gist_idx'::regclass);
96 SELECT gist_page_opaque_info(decode(repeat('00', :block_size), 'hex'));
98 -----------------------
102 -- Test gist_page_items with included columns.
103 -- Non-leaf pages contain only the key attributes, and leaf pages contain
104 -- the included attributes.
105 ALTER TABLE test_gist ADD COLUMN i int DEFAULT NULL;
106 CREATE INDEX test_gist_idx_inc ON test_gist
107 USING gist (p) INCLUDE (t, i);
108 -- Mask the value of the key attribute to avoid alignment issues.
109 SELECT regexp_replace(keys, '\(p\)=\("(.*?)"\)', '(p)=("<val>")') AS keys_nonleaf_1
110 FROM gist_page_items(get_raw_page('test_gist_idx_inc', 0), 'test_gist_idx_inc')
111 WHERE itemoffset = 1;
117 SELECT keys AS keys_leaf_1
118 FROM gist_page_items(get_raw_page('test_gist_idx_inc', 1), 'test_gist_idx_inc')
119 WHERE itemoffset = 1;
121 ------------------------------------------------------
122 (p) INCLUDE (t, i)=("(1,1),(1,1)") INCLUDE (1, null)
125 DROP TABLE test_gist;