Debian Codegraph @

contrib/pageinspect/sql/page.sql

raw
1 CREATE EXTENSION pageinspect;
2
3 -- Use a temp table so that effects of VACUUM are predictable
4 CREATE TEMP TABLE test1 (a int, b int);
5 INSERT INTO test1 VALUES (16777217, 131584);
6
7 VACUUM (DISABLE_PAGE_SKIPPING) test1; -- set up FSM
8
9 -- The page contents can vary, so just test that it can be read
10 -- successfully, but don't keep the output.
11
12 SELECT octet_length(get_raw_page('test1', 'main', 0)) AS main_0;
13 SELECT octet_length(get_raw_page('test1', 'main', 1)) AS main_1;
14
15 SELECT octet_length(get_raw_page('test1', 'fsm', 0)) AS fsm_0;
16 SELECT octet_length(get_raw_page('test1', 'fsm', 1)) AS fsm_1;
17
18 SELECT octet_length(get_raw_page('test1', 'vm', 0)) AS vm_0;
19 SELECT octet_length(get_raw_page('test1', 'vm', 1)) AS vm_1;
20
21 SELECT octet_length(get_raw_page('test1', 'main', -1));
22 SELECT octet_length(get_raw_page('xxx', 'main', 0));
23 SELECT octet_length(get_raw_page('test1', 'xxx', 0));
24
25 SELECT get_raw_page('test1', 0) = get_raw_page('test1', 'main', 0);
26
27 SELECT pagesize, version FROM page_header(get_raw_page('test1', 0));
28
29 SELECT page_checksum(get_raw_page('test1', 0), 0) IS NOT NULL AS silly_checksum_test;
30 SELECT page_checksum(get_raw_page('test1', 0), -1);
31
32 SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
33 FROM heap_page_items(get_raw_page('test1', 0));
34
35 SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
36
37 -- If we freeze the only tuple on test1, the infomask should
38 -- always be the same in all test runs.
39 VACUUM (FREEZE, DISABLE_PAGE_SKIPPING) test1;
40
41 SELECT t_infomask, t_infomask2, raw_flags, combined_flags
42 FROM heap_page_items(get_raw_page('test1', 0)),
43 LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
44
45 -- tests for decoding of combined flags
46 -- HEAP_XMAX_SHR_LOCK = (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)
47 SELECT * FROM heap_tuple_infomask_flags(x'0050'::int, 0);
48 -- HEAP_XMIN_FROZEN = (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)
49 SELECT * FROM heap_tuple_infomask_flags(x'0300'::int, 0);
50 -- HEAP_MOVED = (HEAP_MOVED_IN | HEAP_MOVED_OFF)
51 SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
52 SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
53
54 -- test all flags of t_infomask and t_infomask2
55 SELECT unnest(raw_flags)
56 FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
57 SELECT unnest(combined_flags)
58 FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
59
60 -- no flags at all
61 SELECT * FROM heap_tuple_infomask_flags(0, 0);
62 -- no combined flags
63 SELECT * FROM heap_tuple_infomask_flags(x'0010'::int, 0);
64
65 DROP TABLE test1;
66
67 -- check that using any of these functions with a partitioned table or index
68 -- would fail
69 create table test_partitioned (a int) partition by range (a);
70 create index test_partitioned_index on test_partitioned (a);
71 select get_raw_page('test_partitioned', 0); -- error about partitioned table
72 select get_raw_page('test_partitioned_index', 0); -- error about partitioned index
73
74 -- a regular table which is a member of a partition set should work though
75 create table test_part1 partition of test_partitioned for values from ( 1 ) to (100);
76 select get_raw_page('test_part1', 0); -- get farther and error about empty table
77 drop table test_partitioned;
78
79 -- check null bitmap alignment for table whose number of attributes is multiple of 8
80 create table test8 (f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
81 insert into test8(f1, f8) values (x'7f00007f'::int, 0);
82 select t_bits, t_data from heap_page_items(get_raw_page('test8', 0));
83 select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bits)
84 from heap_page_items(get_raw_page('test8', 0));
85 drop table test8;
86
87 -- check storage of generated columns
88 -- stored
89 create table test9s (a int not null, b int generated always as (a * 2) stored);
90 insert into test9s values (131584);
91 select raw_flags, t_bits, t_data
92 from heap_page_items(get_raw_page('test9s', 0)), lateral heap_tuple_infomask_flags(t_infomask, t_infomask2);
93 select tuple_data_split('test9s'::regclass, t_data, t_infomask, t_infomask2, t_bits)
94 from heap_page_items(get_raw_page('test9s', 0));
95 drop table test9s;
96
97 -- virtual
98 create table test9v (a int not null, b int generated always as (a * 2) virtual);
99 insert into test9v values (131584);
100 select raw_flags, t_bits, t_data
101 from heap_page_items(get_raw_page('test9v', 0)), lateral heap_tuple_infomask_flags(t_infomask, t_infomask2);
102 select tuple_data_split('test9v'::regclass, t_data, t_infomask, t_infomask2, t_bits)
103 from heap_page_items(get_raw_page('test9v', 0));
104 drop table test9v;
105
106 -- Failure with incorrect page size
107 -- Suppress the DETAIL message, to allow the tests to work across various
108 -- page sizes.
109 \set VERBOSITY terse
110 SELECT fsm_page_contents('aaa'::bytea);
111 SELECT page_checksum('bbb'::bytea, 0);
112 SELECT page_header('ccc'::bytea);
113 \set VERBOSITY default
114
115 -- Tests with all-zero pages.
116 SHOW block_size \gset
117 SELECT fsm_page_contents(decode(repeat('00', :block_size), 'hex'));
118 SELECT page_header(decode(repeat('00', :block_size), 'hex'));
119 SELECT page_checksum(decode(repeat('00', :block_size), 'hex'), 1);
120
121 -- tests for sequences
122 create sequence test_sequence start 72057594037927937;
123 select tuple_data_split('test_sequence'::regclass, t_data, t_infomask, t_infomask2, t_bits)
124 from heap_page_items(get_raw_page('test_sequence', 0));
125 drop sequence test_sequence;