1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00
Nathan Bossart 70d1c664f4 Fix contrib/pageinspect's test for sequences.
I managed to break this test in two different ways in commit
05036a3155.

First, the output of the new call to tuple_data_split() on the test
sequence is dependent on endianness.  This is fixed by setting a
special start value for the test sequence that produces the same
output regardless of the endianness of the machine.

Second, on versions older than v15, the new test case fails under
"force_parallel_mode = regress" with the following error:

	ERROR:  cannot access temporary tables during a parallel operation

This is because pageinspect's disk-accessing functions are
incorrectly marked PARALLEL SAFE on versions older than v15 (see
commit aeaaf520f4 for details).  This one is fixed by changing the
test sequence to be permanent.  The only reason it was previously
marked temporary was to avoid needing a DROP SEQUENCE command at
the end of the test.  Unlike some other tests in this file, the use
of a permanent sequence here shouldn't result in any test
instability like what was fixed by commit e2933a6e11.

Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/ZuOKOut5hhDlf_bP%40nathan
Backpatch-through: 12
2024-09-13 10:16:40 -05:00

252 lines
8.1 KiB
Plaintext

CREATE EXTENSION pageinspect;
-- Use a temp table so that effects of VACUUM are predictable
CREATE TEMP TABLE test1 (a int, b int);
INSERT INTO test1 VALUES (16777217, 131584);
VACUUM (DISABLE_PAGE_SKIPPING) test1; -- set up FSM
-- The page contents can vary, so just test that it can be read
-- successfully, but don't keep the output.
SELECT octet_length(get_raw_page('test1', 'main', 0)) AS main_0;
main_0
--------
8192
(1 row)
SELECT octet_length(get_raw_page('test1', 'main', 1)) AS main_1;
ERROR: block number 1 is out of range for relation "test1"
SELECT octet_length(get_raw_page('test1', 'fsm', 0)) AS fsm_0;
fsm_0
-------
8192
(1 row)
SELECT octet_length(get_raw_page('test1', 'fsm', 1)) AS fsm_1;
fsm_1
-------
8192
(1 row)
SELECT octet_length(get_raw_page('test1', 'vm', 0)) AS vm_0;
vm_0
------
8192
(1 row)
SELECT octet_length(get_raw_page('test1', 'vm', 1)) AS vm_1;
ERROR: block number 1 is out of range for relation "test1"
SELECT octet_length(get_raw_page('test1', 'main', -1));
ERROR: invalid block number
SELECT octet_length(get_raw_page('xxx', 'main', 0));
ERROR: relation "xxx" does not exist
SELECT octet_length(get_raw_page('test1', 'xxx', 0));
ERROR: invalid fork name
HINT: Valid fork names are "main", "fsm", "vm", and "init".
SELECT get_raw_page('test1', 0) = get_raw_page('test1', 'main', 0);
?column?
----------
t
(1 row)
SELECT pagesize, version FROM page_header(get_raw_page('test1', 0));
pagesize | version
----------+---------
8192 | 4
(1 row)
SELECT page_checksum(get_raw_page('test1', 0), 0) IS NOT NULL AS silly_checksum_test;
silly_checksum_test
---------------------
t
(1 row)
SELECT page_checksum(get_raw_page('test1', 0), -1);
ERROR: invalid block number
SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
FROM heap_page_items(get_raw_page('test1', 0));
tuple_data_split
-------------------------------
{"\\x01000001","\\x00020200"}
(1 row)
SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
fsm_page_contents
-------------------
0: 254 +
1: 254 +
3: 254 +
7: 254 +
15: 254 +
31: 254 +
63: 254 +
127: 254 +
255: 254 +
511: 254 +
1023: 254 +
2047: 254 +
4095: 254 +
fp_next_slot: 0 +
(1 row)
-- If we freeze the only tuple on test1, the infomask should
-- always be the same in all test runs.
VACUUM (FREEZE, DISABLE_PAGE_SKIPPING) test1;
SELECT t_infomask, t_infomask2, raw_flags, combined_flags
FROM heap_page_items(get_raw_page('test1', 0)),
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
t_infomask | t_infomask2 | raw_flags | combined_flags
------------+-------------+-----------------------------------------------------------+--------------------
2816 | 2 | {HEAP_XMIN_COMMITTED,HEAP_XMIN_INVALID,HEAP_XMAX_INVALID} | {HEAP_XMIN_FROZEN}
(1 row)
-- tests for decoding of combined flags
-- HEAP_XMAX_SHR_LOCK = (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)
SELECT * FROM heap_tuple_infomask_flags(x'0050'::int, 0);
raw_flags | combined_flags
---------------------------------------------+----------------------
{HEAP_XMAX_KEYSHR_LOCK,HEAP_XMAX_EXCL_LOCK} | {HEAP_XMAX_SHR_LOCK}
(1 row)
-- HEAP_XMIN_FROZEN = (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)
SELECT * FROM heap_tuple_infomask_flags(x'0300'::int, 0);
raw_flags | combined_flags
-----------------------------------------+--------------------
{HEAP_XMIN_COMMITTED,HEAP_XMIN_INVALID} | {HEAP_XMIN_FROZEN}
(1 row)
-- HEAP_MOVED = (HEAP_MOVED_IN | HEAP_MOVED_OFF)
SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
raw_flags | combined_flags
--------------------------------+----------------
{HEAP_MOVED_OFF,HEAP_MOVED_IN} | {HEAP_MOVED}
(1 row)
SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
raw_flags | combined_flags
--------------------------------+----------------
{HEAP_MOVED_OFF,HEAP_MOVED_IN} | {HEAP_MOVED}
(1 row)
-- test all flags of t_infomask and t_infomask2
SELECT unnest(raw_flags)
FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
unnest
-----------------------
HEAP_COMBOCID
HEAP_HASEXTERNAL
HEAP_HASNULL
HEAP_HASOID_OLD
HEAP_HASVARWIDTH
HEAP_HOT_UPDATED
HEAP_KEYS_UPDATED
HEAP_MOVED_IN
HEAP_MOVED_OFF
HEAP_ONLY_TUPLE
HEAP_UPDATED
HEAP_XMAX_COMMITTED
HEAP_XMAX_EXCL_LOCK
HEAP_XMAX_INVALID
HEAP_XMAX_IS_MULTI
HEAP_XMAX_KEYSHR_LOCK
HEAP_XMAX_LOCK_ONLY
HEAP_XMIN_COMMITTED
HEAP_XMIN_INVALID
(19 rows)
SELECT unnest(combined_flags)
FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
unnest
--------------------
HEAP_MOVED
HEAP_XMAX_SHR_LOCK
HEAP_XMIN_FROZEN
(3 rows)
-- no flags at all
SELECT * FROM heap_tuple_infomask_flags(0, 0);
raw_flags | combined_flags
-----------+----------------
{} | {}
(1 row)
-- no combined flags
SELECT * FROM heap_tuple_infomask_flags(x'0010'::int, 0);
raw_flags | combined_flags
-------------------------+----------------
{HEAP_XMAX_KEYSHR_LOCK} | {}
(1 row)
DROP TABLE test1;
-- check that using any of these functions with a partitioned table or index
-- would fail
create table test_partitioned (a int) partition by range (a);
create index test_partitioned_index on test_partitioned (a);
select get_raw_page('test_partitioned', 0); -- error about partitioned table
ERROR: cannot get raw page from relation "test_partitioned"
DETAIL: This operation is not supported for partitioned tables.
select get_raw_page('test_partitioned_index', 0); -- error about partitioned index
ERROR: cannot get raw page from relation "test_partitioned_index"
DETAIL: This operation is not supported for partitioned indexes.
-- a regular table which is a member of a partition set should work though
create table test_part1 partition of test_partitioned for values from ( 1 ) to (100);
select get_raw_page('test_part1', 0); -- get farther and error about empty table
ERROR: block number 0 is out of range for relation "test_part1"
drop table test_partitioned;
-- check null bitmap alignment for table whose number of attributes is multiple of 8
create table test8 (f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
insert into test8(f1, f8) values (x'7f00007f'::int, 0);
select t_bits, t_data from heap_page_items(get_raw_page('test8', 0));
t_bits | t_data
----------+--------------------
10000001 | \x7f00007f00000000
(1 row)
select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bits)
from heap_page_items(get_raw_page('test8', 0));
tuple_data_split
-------------------------------------------------------------
{"\\x7f00007f",NULL,NULL,NULL,NULL,NULL,NULL,"\\x00000000"}
(1 row)
drop table test8;
-- Failure with incorrect page size
-- Suppress the DETAIL message, to allow the tests to work across various
-- page sizes.
\set VERBOSITY terse
SELECT fsm_page_contents('aaa'::bytea);
ERROR: invalid page size
SELECT page_checksum('bbb'::bytea, 0);
ERROR: invalid page size
SELECT page_header('ccc'::bytea);
ERROR: invalid page size
\set VERBOSITY default
-- Tests with all-zero pages.
SHOW block_size \gset
SELECT fsm_page_contents(decode(repeat('00', :block_size), 'hex'));
fsm_page_contents
-------------------
(1 row)
SELECT page_header(decode(repeat('00', :block_size), 'hex'));
page_header
-----------------------
(0/0,0,0,0,0,0,0,0,0)
(1 row)
SELECT page_checksum(decode(repeat('00', :block_size), 'hex'), 1);
page_checksum
---------------
(1 row)
-- tests for sequences
create sequence test_sequence start 72057594037927937;
select tuple_data_split('test_sequence'::regclass, t_data, t_infomask, t_infomask2, t_bits)
from heap_page_items(get_raw_page('test_sequence', 0));
tuple_data_split
-------------------------------------------------------
{"\\x0100000000000001","\\x0000000000000000","\\x00"}
(1 row)
drop sequence test_sequence;