mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-07 22:56:51 +02:00
c08d82f38e
The contrib extensions pageinspect, pg_visibility and pgstattuple only work against regular relations which have storage. They don't work against foreign tables, partitioned (parent) tables, views, et al. Add checks to the user-callable functions to return a useful error message to the user if they mistakenly pass an invalid relation to a function which doesn't accept that kind of relation. In passing, improve some of the existing checks to use ereport() instead of elog(), add a function to consolidate common checks where appropriate, and add some regression tests. Author: Amit Langote, with various changes by me Reviewed by: Michael Paquier and Corey Huinker Discussion: https://postgr.es/m/ab91fd9d-4751-ee77-c87b-4dd704c1e59c@lab.ntt.co.jp
83 lines
2.4 KiB
Plaintext
83 lines
2.4 KiB
Plaintext
CREATE EXTENSION pageinspect;
|
|
CREATE TABLE test1 (a int, b int);
|
|
INSERT INTO test1 VALUES (16777217, 131584);
|
|
VACUUM 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('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 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)
|
|
|
|
DROP TABLE test1;
|
|
-- check that using any of these functions with a partitioned table would fail
|
|
create table test_partitioned (a int) partition by range (a);
|
|
select get_raw_page('test_partitioned', 0); -- error about partitioned table
|
|
ERROR: cannot get raw page from partitioned table "test_partitioned"
|
|
-- 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;
|