1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

pageinspect: Fix failure with hash_bitmap_info() for partitioned indexes

This function reads directly a page from a relation, relying on
index_open() to open the index to read from.  Unfortunately, this would
crash when using partitioned indexes, as these can be opened with
index_open() but they have no physical pages.

Alexander has fixed the module, while I have written the test.

Author: Alexander Lakhin, Michael Paquier
Discussion: https://postgr.es/m/18246-f4d9ff7cb3af77e6@postgresql.org
Backpatch-through: 12
This commit is contained in:
Michael Paquier
2023-12-19 18:19:16 +09:00
parent b745f16804
commit 2e08440d61
3 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,8 @@
CREATE TABLE test_hash (a int, b text);
INSERT INTO test_hash VALUES (1, 'one');
CREATE INDEX test_hash_a_idx ON test_hash USING hash (a);
CREATE TABLE test_hash_part (a int, b int) PARTITION BY RANGE (a);
CREATE INDEX test_hash_part_idx ON test_hash_part USING hash(b);
\x
SELECT hash_page_type(get_raw_page('test_hash_a_idx', 0));
-[ RECORD 1 ]--+---------
@ -44,6 +46,8 @@ SELECT * FROM hash_bitmap_info('test_hash_a_idx', 5);
ERROR: invalid overflow block number 5
SELECT * FROM hash_bitmap_info('test_hash_a_idx', 6);
ERROR: block number 6 is out of range for relation "test_hash_a_idx"
SELECT * FROM hash_bitmap_info('test_hash_part_idx', 1); -- error
ERROR: "test_hash_part_idx" is not a hash index
SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask,
lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM
hash_metapage_info(get_raw_page('test_hash_a_idx', 0));
@ -203,3 +207,4 @@ SELECT hash_page_type(decode(repeat('00', :block_size), 'hex'));
hash_page_type | unused
DROP TABLE test_hash;
DROP TABLE test_hash_part;