mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
pageinspect: Fix handling of page sizes and AM types
This commit fixes a set of issues related to the use of the SQL functions in this module when the caller is able to pass down raw page data as input argument: - The page size check was fuzzy in a couple of places, sometimes looking after only a sub-range, but what we are looking for is an exact match on BLCKSZ. After considering a few options here, I have settled down to do a generalization of get_page_from_raw(). Most of the SQL functions already used that, and this is not strictly required if not accessing an 8-byte-wide value from a raw page, but this feels safer in the long run for alignment-picky environment, particularly if a code path begins to access such values. This also reduces the number of strings that need to be translated. - The BRIN function brin_page_items() uses a Relation but it did not check the access method of the opened index, potentially leading to crashes. All the other functions in need of a Relation already did that. - Some code paths could fail on elog(), but we should to use ereport() for failures that can be triggered by the user. Tests are added to stress all the cases that are fixed as of this commit, with some junk raw pages (\set VERBOSITY ensures that this works across all page sizes) and unexpected index types when functions open relations. Author: Michael Paquier, Justin Prysby Discussion: https://postgr.es/m/20220218030020.GA1137@telsasoft.com Backpatch-through: 10
This commit is contained in:
@ -48,4 +48,8 @@ SELECT * FROM brin_page_items(get_raw_page('test1_a_idx', 2), 'test1_a_idx')
|
||||
1 | 0 | 1 | f | f | f | {1 .. 1}
|
||||
(1 row)
|
||||
|
||||
-- Failure for non-BRIN index.
|
||||
CREATE INDEX test1_a_btree ON test1 (a);
|
||||
SELECT brin_page_items(get_raw_page('test1_a_btree', 0), 'test1_a_btree');
|
||||
ERROR: "test1_a_btree" is not a BRIN index
|
||||
DROP TABLE test1;
|
||||
|
@ -57,4 +57,19 @@ data | 01 00 00 00 00 00 00 01
|
||||
|
||||
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 2));
|
||||
ERROR: block number 2 is out of range for relation "test1_a_idx"
|
||||
-- Failure when using a non-btree index.
|
||||
CREATE INDEX test1_a_hash ON test1 USING hash(a);
|
||||
SELECT bt_metap('test1_a_hash');
|
||||
ERROR: "test1_a_hash" is not a btree index
|
||||
SELECT bt_page_stats('test1_a_hash', 0);
|
||||
ERROR: "test1_a_hash" is not a btree index
|
||||
SELECT bt_page_items('test1_a_hash', 0);
|
||||
ERROR: "test1_a_hash" is not a btree index
|
||||
-- Failure with incorrect page size
|
||||
-- Suppress the DETAIL message, to allow the tests to work across various
|
||||
-- page sizes.
|
||||
\set VERBOSITY terse
|
||||
SELECT bt_page_items('aaa'::bytea);
|
||||
ERROR: invalid page size
|
||||
\set VERBOSITY default
|
||||
DROP TABLE test1;
|
||||
|
@ -35,3 +35,14 @@ FROM gin_leafpage_items(get_raw_page('test1_y_idx',
|
||||
-[ RECORD 1 ]
|
||||
?column? | t
|
||||
|
||||
-- Failure with incorrect page size
|
||||
-- Suppress the DETAIL message, to allow the tests to work across various
|
||||
-- page sizes.
|
||||
\set VERBOSITY terse
|
||||
SELECT gin_leafpage_items('aaa'::bytea);
|
||||
ERROR: invalid page size
|
||||
SELECT gin_metapage_info('bbb'::bytea);
|
||||
ERROR: invalid page size
|
||||
SELECT gin_page_opaque_info('ccc'::bytea);
|
||||
ERROR: invalid page size
|
||||
\set VERBOSITY default
|
||||
|
@ -159,4 +159,21 @@ SELECT * FROM hash_page_items(get_raw_page('test_hash_a_idx', 4));
|
||||
|
||||
SELECT * FROM hash_page_items(get_raw_page('test_hash_a_idx', 5));
|
||||
ERROR: page is not a hash bucket or overflow page
|
||||
-- Failure with non-hash index
|
||||
CREATE INDEX test_hash_a_btree ON test_hash USING btree (a);
|
||||
SELECT hash_bitmap_info('test_hash_a_btree', 0);
|
||||
ERROR: "test_hash_a_btree" is not a hash index
|
||||
-- Failure with incorrect page size
|
||||
-- Suppress the DETAIL message, to allow the tests to work across various
|
||||
-- page sizes.
|
||||
\set VERBOSITY terse
|
||||
SELECT hash_metapage_info('aaa'::bytea);
|
||||
ERROR: invalid page size
|
||||
SELECT hash_page_items('bbb'::bytea);
|
||||
ERROR: invalid page size
|
||||
SELECT hash_page_stats('ccc'::bytea);
|
||||
ERROR: invalid page size
|
||||
SELECT hash_page_type('ddd'::bytea);
|
||||
ERROR: invalid page size
|
||||
\set VERBOSITY default
|
||||
DROP TABLE test_hash;
|
||||
|
@ -113,3 +113,14 @@ select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bi
|
||||
(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
|
||||
|
Reference in New Issue
Block a user