Debian Codegraph @

contrib/pageinspect/expected/page.out

raw
1 CREATE EXTENSION pageinspect;
2 -- Use a temp table so that effects of VACUUM are predictable
3 CREATE TEMP TABLE test1 (a int, b int);
4 INSERT INTO test1 VALUES (16777217, 131584);
5 VACUUM (DISABLE_PAGE_SKIPPING) test1; -- set up FSM
6 -- The page contents can vary, so just test that it can be read
7 -- successfully, but don't keep the output.
8 SELECT octet_length(get_raw_page('test1', 'main', 0)) AS main_0;
9 main_0
10 --------
11 8192
12 (1 row)
13
14 SELECT octet_length(get_raw_page('test1', 'main', 1)) AS main_1;
15 ERROR: block number 1 is out of range for relation "test1"
16 SELECT octet_length(get_raw_page('test1', 'fsm', 0)) AS fsm_0;
17 fsm_0
18 -------
19 8192
20 (1 row)
21
22 SELECT octet_length(get_raw_page('test1', 'fsm', 1)) AS fsm_1;
23 fsm_1
24 -------
25 8192
26 (1 row)
27
28 SELECT octet_length(get_raw_page('test1', 'vm', 0)) AS vm_0;
29 vm_0
30 ------
31 8192
32 (1 row)
33
34 SELECT octet_length(get_raw_page('test1', 'vm', 1)) AS vm_1;
35 ERROR: block number 1 is out of range for relation "test1"
36 SELECT octet_length(get_raw_page('test1', 'main', -1));
37 ERROR: invalid block number
38 SELECT octet_length(get_raw_page('xxx', 'main', 0));
39 ERROR: relation "xxx" does not exist
40 SELECT octet_length(get_raw_page('test1', 'xxx', 0));
41 ERROR: invalid fork name
42 HINT: Valid fork names are "main", "fsm", "vm", and "init".
43 SELECT get_raw_page('test1', 0) = get_raw_page('test1', 'main', 0);
44 ?column?
45 ----------
46 t
47 (1 row)
48
49 SELECT pagesize, version FROM page_header(get_raw_page('test1', 0));
50 pagesize | version
51 ----------+---------
52 8192 | 4
53 (1 row)
54
55 SELECT page_checksum(get_raw_page('test1', 0), 0) IS NOT NULL AS silly_checksum_test;
56 silly_checksum_test
57 ---------------------
58 t
59 (1 row)
60
61 SELECT page_checksum(get_raw_page('test1', 0), -1);
62 ERROR: invalid block number
63 SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
64 FROM heap_page_items(get_raw_page('test1', 0));
65 tuple_data_split
66 -------------------------------
67 {"\\x01000001","\\x00020200"}
68 (1 row)
69
70 SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
71 fsm_page_contents
72 -------------------
73 0: 254 +
74 1: 254 +
75 3: 254 +
76 7: 254 +
77 15: 254 +
78 31: 254 +
79 63: 254 +
80 127: 254 +
81 255: 254 +
82 511: 254 +
83 1023: 254 +
84 2047: 254 +
85 4095: 254 +
86 fp_next_slot: 0 +
87
88 (1 row)
89
90 -- If we freeze the only tuple on test1, the infomask should
91 -- always be the same in all test runs.
92 VACUUM (FREEZE, DISABLE_PAGE_SKIPPING) test1;
93 SELECT t_infomask, t_infomask2, raw_flags, combined_flags
94 FROM heap_page_items(get_raw_page('test1', 0)),
95 LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
96 t_infomask | t_infomask2 | raw_flags | combined_flags
97 ------------+-------------+-----------------------------------------------------------+--------------------
98 2816 | 2 | {HEAP_XMIN_COMMITTED,HEAP_XMIN_INVALID,HEAP_XMAX_INVALID} | {HEAP_XMIN_FROZEN}
99 (1 row)
100
101 -- tests for decoding of combined flags
102 -- HEAP_XMAX_SHR_LOCK = (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)
103 SELECT * FROM heap_tuple_infomask_flags(x'0050'::int, 0);
104 raw_flags | combined_flags
105 ---------------------------------------------+----------------------
106 {HEAP_XMAX_KEYSHR_LOCK,HEAP_XMAX_EXCL_LOCK} | {HEAP_XMAX_SHR_LOCK}
107 (1 row)
108
109 -- HEAP_XMIN_FROZEN = (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)
110 SELECT * FROM heap_tuple_infomask_flags(x'0300'::int, 0);
111 raw_flags | combined_flags
112 -----------------------------------------+--------------------
113 {HEAP_XMIN_COMMITTED,HEAP_XMIN_INVALID} | {HEAP_XMIN_FROZEN}
114 (1 row)
115
116 -- HEAP_MOVED = (HEAP_MOVED_IN | HEAP_MOVED_OFF)
117 SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
118 raw_flags | combined_flags
119 --------------------------------+----------------
120 {HEAP_MOVED_OFF,HEAP_MOVED_IN} | {HEAP_MOVED}
121 (1 row)
122
123 SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
124 raw_flags | combined_flags
125 --------------------------------+----------------
126 {HEAP_MOVED_OFF,HEAP_MOVED_IN} | {HEAP_MOVED}
127 (1 row)
128
129 -- test all flags of t_infomask and t_infomask2
130 SELECT unnest(raw_flags)
131 FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
132 unnest
133 -----------------------
134 HEAP_COMBOCID
135 HEAP_HASEXTERNAL
136 HEAP_HASNULL
137 HEAP_HASOID_OLD
138 HEAP_HASVARWIDTH
139 HEAP_HOT_UPDATED
140 HEAP_KEYS_UPDATED
141 HEAP_MOVED_IN
142 HEAP_MOVED_OFF
143 HEAP_ONLY_TUPLE
144 HEAP_UPDATED
145 HEAP_XMAX_COMMITTED
146 HEAP_XMAX_EXCL_LOCK
147 HEAP_XMAX_INVALID
148 HEAP_XMAX_IS_MULTI
149 HEAP_XMAX_KEYSHR_LOCK
150 HEAP_XMAX_LOCK_ONLY
151 HEAP_XMIN_COMMITTED
152 HEAP_XMIN_INVALID
153 (19 rows)
154
155 SELECT unnest(combined_flags)
156 FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
157 unnest
158 --------------------
159 HEAP_MOVED
160 HEAP_XMAX_SHR_LOCK
161 HEAP_XMIN_FROZEN
162 (3 rows)
163
164 -- no flags at all
165 SELECT * FROM heap_tuple_infomask_flags(0, 0);
166 raw_flags | combined_flags
167 -----------+----------------
168 {} | {}
169 (1 row)
170
171 -- no combined flags
172 SELECT * FROM heap_tuple_infomask_flags(x'0010'::int, 0);
173 raw_flags | combined_flags
174 -------------------------+----------------
175 {HEAP_XMAX_KEYSHR_LOCK} | {}
176 (1 row)
177
178 DROP TABLE test1;
179 -- check that using any of these functions with a partitioned table or index
180 -- would fail
181 create table test_partitioned (a int) partition by range (a);
182 create index test_partitioned_index on test_partitioned (a);
183 select get_raw_page('test_partitioned', 0); -- error about partitioned table
184 ERROR: cannot get raw page from relation "test_partitioned"
185 DETAIL: This operation is not supported for partitioned tables.
186 select get_raw_page('test_partitioned_index', 0); -- error about partitioned index
187 ERROR: cannot get raw page from relation "test_partitioned_index"
188 DETAIL: This operation is not supported for partitioned indexes.
189 -- a regular table which is a member of a partition set should work though
190 create table test_part1 partition of test_partitioned for values from ( 1 ) to (100);
191 select get_raw_page('test_part1', 0); -- get farther and error about empty table
192 ERROR: block number 0 is out of range for relation "test_part1"
193 drop table test_partitioned;
194 -- check null bitmap alignment for table whose number of attributes is multiple of 8
195 create table test8 (f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
196 insert into test8(f1, f8) values (x'7f00007f'::int, 0);
197 select t_bits, t_data from heap_page_items(get_raw_page('test8', 0));
198 t_bits | t_data
199 ----------+--------------------
200 10000001 | \x7f00007f00000000
201 (1 row)
202
203 select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bits)
204 from heap_page_items(get_raw_page('test8', 0));
205 tuple_data_split
206 -------------------------------------------------------------
207 {"\\x7f00007f",NULL,NULL,NULL,NULL,NULL,NULL,"\\x00000000"}
208 (1 row)
209
210 drop table test8;
211 -- check storage of generated columns
212 -- stored
213 create table test9s (a int not null, b int generated always as (a * 2) stored);
214 insert into test9s values (131584);
215 select raw_flags, t_bits, t_data
216 from heap_page_items(get_raw_page('test9s', 0)), lateral heap_tuple_infomask_flags(t_infomask, t_infomask2);
217 raw_flags | t_bits | t_data
218 ---------------------+--------+--------------------
219 {HEAP_XMAX_INVALID} | | \x0002020000040400
220 (1 row)
221
222 select tuple_data_split('test9s'::regclass, t_data, t_infomask, t_infomask2, t_bits)
223 from heap_page_items(get_raw_page('test9s', 0));
224 tuple_data_split
225 -------------------------------
226 {"\\x00020200","\\x00040400"}
227 (1 row)
228
229 drop table test9s;
230 -- virtual
231 create table test9v (a int not null, b int generated always as (a * 2) virtual);
232 insert into test9v values (131584);
233 select raw_flags, t_bits, t_data
234 from heap_page_items(get_raw_page('test9v', 0)), lateral heap_tuple_infomask_flags(t_infomask, t_infomask2);
235 raw_flags | t_bits | t_data
236 ----------------------------------+----------+------------
237 {HEAP_HASNULL,HEAP_XMAX_INVALID} | 10000000 | \x00020200
238 (1 row)
239
240 select tuple_data_split('test9v'::regclass, t_data, t_infomask, t_infomask2, t_bits)
241 from heap_page_items(get_raw_page('test9v', 0));
242 tuple_data_split
243 ----------------------
244 {"\\x00020200",NULL}
245 (1 row)
246
247 drop table test9v;
248 -- Failure with incorrect page size
249 -- Suppress the DETAIL message, to allow the tests to work across various
250 -- page sizes.
251 \set VERBOSITY terse
252 SELECT fsm_page_contents('aaa'::bytea);
253 ERROR: invalid page size
254 SELECT page_checksum('bbb'::bytea, 0);
255 ERROR: invalid page size
256 SELECT page_header('ccc'::bytea);
257 ERROR: invalid page size
258 \set VERBOSITY default
259 -- Tests with all-zero pages.
260 SHOW block_size \gset
261 SELECT fsm_page_contents(decode(repeat('00', :block_size), 'hex'));
262 fsm_page_contents
263 -------------------
264
265 (1 row)
266
267 SELECT page_header(decode(repeat('00', :block_size), 'hex'));
268 page_header
269 -----------------------
270 (0/0,0,0,0,0,0,0,0,0)
271 (1 row)
272
273 SELECT page_checksum(decode(repeat('00', :block_size), 'hex'), 1);
274 page_checksum
275 ---------------
276
277 (1 row)
278
279 -- tests for sequences
280 create sequence test_sequence start 72057594037927937;
281 select tuple_data_split('test_sequence'::regclass, t_data, t_infomask, t_infomask2, t_bits)
282 from heap_page_items(get_raw_page('test_sequence', 0));
283 tuple_data_split
284 -------------------------------------------------------
285 {"\\x0100000000000001","\\x0000000000000000","\\x00"}
286 (1 row)
287
288 drop sequence test_sequence;