diff options
author | Michael Paquier | 2022-03-16 02:19:39 +0000 |
---|---|---|
committer | Michael Paquier | 2022-03-16 02:19:39 +0000 |
commit | 076f4d9539e9687d68ada32353c0c16d9bfa3cfb (patch) | |
tree | ac1b8bae68c90c8bce6c07a71bb7b3767d77e456 /contrib/pageinspect/expected | |
parent | 5e6368b42ee6d4b59e085301ca7b0e50f37a897b (diff) |
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/[email protected]
Backpatch-through: 10
Diffstat (limited to 'contrib/pageinspect/expected')
-rw-r--r-- | contrib/pageinspect/expected/brin.out | 4 | ||||
-rw-r--r-- | contrib/pageinspect/expected/btree.out | 15 | ||||
-rw-r--r-- | contrib/pageinspect/expected/gin.out | 11 | ||||
-rw-r--r-- | contrib/pageinspect/expected/gist.out | 15 | ||||
-rw-r--r-- | contrib/pageinspect/expected/hash.out | 17 | ||||
-rw-r--r-- | contrib/pageinspect/expected/page.out | 11 |
6 files changed, 73 insertions, 0 deletions
diff --git a/contrib/pageinspect/expected/brin.out b/contrib/pageinspect/expected/brin.out index 71eb190380c..10cd36c1778 100644 --- a/contrib/pageinspect/expected/brin.out +++ b/contrib/pageinspect/expected/brin.out @@ -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; diff --git a/contrib/pageinspect/expected/btree.out b/contrib/pageinspect/expected/btree.out index c60bc88560c..80b3dfe861c 100644 --- a/contrib/pageinspect/expected/btree.out +++ b/contrib/pageinspect/expected/btree.out @@ -70,4 +70,19 @@ tids | 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; diff --git a/contrib/pageinspect/expected/gin.out b/contrib/pageinspect/expected/gin.out index ef7570b9723..802f48284bf 100644 --- a/contrib/pageinspect/expected/gin.out +++ b/contrib/pageinspect/expected/gin.out @@ -36,3 +36,14 @@ FROM gin_leafpage_items(get_raw_page('test1_y_idx', ?column? | t DROP TABLE test1; +-- 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 diff --git a/contrib/pageinspect/expected/gist.out b/contrib/pageinspect/expected/gist.out index 93abfcdd5e1..3f33e040661 100644 --- a/contrib/pageinspect/expected/gist.out +++ b/contrib/pageinspect/expected/gist.out @@ -64,4 +64,19 @@ SELECT itemoffset, ctid, itemlen FROM gist_page_items_bytea(get_raw_page('test_g 6 | (6,65535) | 40 (6 rows) +-- Failure with non-GiST index. +CREATE INDEX test_gist_btree on test_gist(t); +SELECT gist_page_items(get_raw_page('test_gist_btree', 0), 'test_gist_btree'); +ERROR: "test_gist_btree" is not a GiST index +-- Failure with incorrect page size +-- Suppress the DETAIL message, to allow the tests to work across various +-- page sizes. +\set VERBOSITY terse +SELECT gist_page_items_bytea('aaa'::bytea); +ERROR: invalid page size +SELECT gist_page_items('aaa'::bytea, 'test_gist_idx'::regclass); +ERROR: invalid page size +SELECT gist_page_opaque_info('aaa'::bytea); +ERROR: invalid page size +\set VERBOSITY default DROP TABLE test_gist; diff --git a/contrib/pageinspect/expected/hash.out b/contrib/pageinspect/expected/hash.out index bd0628d0136..6c606630dd7 100644 --- a/contrib/pageinspect/expected/hash.out +++ b/contrib/pageinspect/expected/hash.out @@ -163,4 +163,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; diff --git a/contrib/pageinspect/expected/page.out b/contrib/pageinspect/expected/page.out index 4e325ae56dd..9bbdda7f180 100644 --- a/contrib/pageinspect/expected/page.out +++ b/contrib/pageinspect/expected/page.out @@ -207,3 +207,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 |