summaryrefslogtreecommitdiff
path: root/contrib/pageinspect/hashfuncs.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-12-19 18:19:05 +0900
committerMichael Paquier <michael@paquier.xyz>2023-12-19 18:19:05 +0900
commit20847013642127e75ee4fe3ddb8228a1fb4b652f (patch)
tree4f414f3406ab654adad534bbf948c1d9f9801afa /contrib/pageinspect/hashfuncs.c
parenta8dd62ef4959141e410278fd68b3d1821e0bbbaa (diff)
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
Diffstat (limited to 'contrib/pageinspect/hashfuncs.c')
-rw-r--r--contrib/pageinspect/hashfuncs.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index f43f0928b11..5c38ec10952 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -12,6 +12,7 @@
#include "access/hash.h"
#include "access/htup_details.h"
+#include "access/relation.h"
#include "catalog/pg_am.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
@@ -27,6 +28,7 @@ PG_FUNCTION_INFO_V1(hash_page_items);
PG_FUNCTION_INFO_V1(hash_bitmap_info);
PG_FUNCTION_INFO_V1(hash_metapage_info);
+#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
#define IS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID)
/* ------------------------------------------------
@@ -413,9 +415,9 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to use raw page functions")));
- indexRel = index_open(indexRelid, AccessShareLock);
+ indexRel = relation_open(indexRelid, AccessShareLock);
- if (!IS_HASH(indexRel))
+ if (!IS_INDEX(indexRel) || !IS_HASH(indexRel))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a %s index",