Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit586c6a0

Browse files
committed
pageinspect: Fix failure with hash_bitmap_info() for partitioned indexes
This function reads directly a page from a relation, relying onindex_open() to open the index to read from. Unfortunately, this wouldcrash when using partitioned indexes, as these can be opened withindex_open() but they have no physical pages.Alexander has fixed the module, while I have written the test.Author: Alexander Lakhin, Michael PaquierDiscussion:https://postgr.es/m/18246-f4d9ff7cb3af77e6@postgresql.orgBackpatch-through: 12
1 parentb4c1d25 commit586c6a0

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

‎contrib/pageinspect/expected/hash.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
CREATE TABLE test_hash (a int, b text);
22
INSERT INTO test_hash VALUES (1, 'one');
33
CREATE INDEX test_hash_a_idx ON test_hash USING hash (a);
4+
CREATE TABLE test_hash_part (a int, b int) PARTITION BY RANGE (a);
5+
CREATE INDEX test_hash_part_idx ON test_hash_part USING hash(b);
46
\x
57
SELECT hash_page_type(get_raw_page('test_hash_a_idx', 0));
68
-[ RECORD 1 ]--+---------
@@ -40,6 +42,8 @@ SELECT * FROM hash_bitmap_info('test_hash_a_idx', 4);
4042
ERROR: invalid overflow block number 4
4143
SELECT * FROM hash_bitmap_info('test_hash_a_idx', 5);
4244
ERROR: invalid overflow block number 5
45+
SELECT * FROM hash_bitmap_info('test_hash_part_idx', 1); -- error
46+
ERROR: "test_hash_part_idx" is not a hash index
4347
SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask,
4448
lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM
4549
hash_metapage_info(get_raw_page('test_hash_a_idx', 0));
@@ -199,3 +203,4 @@ SELECT hash_page_type(decode(repeat('00', :block_size), 'hex'));
199203
hash_page_type | unused
200204

201205
DROP TABLE test_hash;
206+
DROP TABLE test_hash_part;

‎contrib/pageinspect/hashfuncs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include"access/hash.h"
1414
#include"access/htup_details.h"
15+
#include"access/relation.h"
1516
#include"catalog/pg_am.h"
1617
#include"catalog/pg_type.h"
1718
#include"funcapi.h"
@@ -27,6 +28,7 @@ PG_FUNCTION_INFO_V1(hash_page_items);
2728
PG_FUNCTION_INFO_V1(hash_bitmap_info);
2829
PG_FUNCTION_INFO_V1(hash_metapage_info);
2930

31+
#defineIS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
3032
#defineIS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID)
3133

3234
/* ------------------------------------------------
@@ -417,9 +419,9 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
417419
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
418420
errmsg("must be superuser to use raw page functions")));
419421

420-
indexRel=index_open(indexRelid,AccessShareLock);
422+
indexRel=relation_open(indexRelid,AccessShareLock);
421423

422-
if (!IS_HASH(indexRel))
424+
if (!IS_INDEX(indexRel)|| !IS_HASH(indexRel))
423425
ereport(ERROR,
424426
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
425427
errmsg("\"%s\" is not a %s index",

‎contrib/pageinspect/sql/hash.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ CREATE TABLE test_hash (a int, b text);
22
INSERT INTO test_hashVALUES (1,'one');
33
CREATEINDEXtest_hash_a_idxON test_hash USING hash (a);
44

5+
CREATETABLEtest_hash_part (aint, bint) PARTITION BY RANGE (a);
6+
CREATEINDEXtest_hash_part_idxON test_hash_part USING hash(b);
7+
58
\x
69

710
SELECT hash_page_type(get_raw_page('test_hash_a_idx',0));
@@ -19,6 +22,7 @@ SELECT * FROM hash_bitmap_info('test_hash_a_idx', 2);
1922
SELECT*FROM hash_bitmap_info('test_hash_a_idx',3);
2023
SELECT*FROM hash_bitmap_info('test_hash_a_idx',4);
2124
SELECT*FROM hash_bitmap_info('test_hash_a_idx',5);
25+
SELECT*FROM hash_bitmap_info('test_hash_part_idx',1);-- error
2226

2327

2428
SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask,
@@ -104,3 +108,4 @@ SELECT hash_page_stats(decode(repeat('00', :block_size), 'hex'));
104108
SELECT hash_page_type(decode(repeat('00', :block_size),'hex'));
105109

106110
DROPTABLE test_hash;
111+
DROPTABLE test_hash_part;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp