On Wed, 14 Jan 2026 at 20:07, Kirill Reshke <[email protected]> wrote: > On Wed, 14 Jan 2026 at 19:55, Japin Li <[email protected]> wrote: >> >> >> Or we could address it in this thread if you prefer. What do you think? >> > > As you wish - we can continue here, because this is a separate change > which has its independent value. >
Attach the v2 patch. 1. Move the IS_INDEX macro to pageinspect.h 2. Check relation kind for both brin and gist index -- Regards, Japin Li ChengDu WenWu Information Technology Co., Ltd.
>From e0f7ce413bd4d725da893efdc1f4bdbbf732ad27 Mon Sep 17 00:00:00 2001 From: Japin Li <[email protected]> Date: Wed, 14 Jan 2026 09:55:46 +0800 Subject: [PATCH v2] Add IS_INDEX macro to brin and gist index This commit also moves IS_INDEX macro to pageinspect.h Suggested-by: Japin Li <[email protected]> Suggested-by: Andrey Borodin <[email protected]> Reviewed-by: Andreas Karlsson <[email protected]> Reviewed-by: Kirill Reshke <[email protected]> Discussion: https://postgr.es/m/meapr01mb3031a889d4b3f610e9d2a3afb6...@meapr01mb3031.ausprd01.prod.outlook.com Discussion: https://postgr.es/m/[email protected] --- contrib/pageinspect/brinfuncs.c | 3 ++- contrib/pageinspect/gistfuncs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c index 26cf78252ed..4be2225e429 100644 --- a/contrib/pageinspect/brinfuncs.c +++ b/contrib/pageinspect/brinfuncs.c @@ -28,6 +28,7 @@ PG_FUNCTION_INFO_V1(brin_page_items); PG_FUNCTION_INFO_V1(brin_metapage_info); PG_FUNCTION_INFO_V1(brin_revmap_data); +#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX) #define IS_BRIN(r) ((r)->rd_rel->relam == BRIN_AM_OID) typedef struct brin_column_state @@ -164,7 +165,7 @@ brin_page_items(PG_FUNCTION_ARGS) indexRel = index_open(indexRelid, AccessShareLock); - if (!IS_BRIN(indexRel)) + if (!IS_INDEX(indexRel) || !IS_BRIN(indexRel)) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a %s index", diff --git a/contrib/pageinspect/gistfuncs.c b/contrib/pageinspect/gistfuncs.c index a205cb8a334..49d6d4940fc 100644 --- a/contrib/pageinspect/gistfuncs.c +++ b/contrib/pageinspect/gistfuncs.c @@ -30,6 +30,7 @@ PG_FUNCTION_INFO_V1(gist_page_opaque_info); PG_FUNCTION_INFO_V1(gist_page_items); PG_FUNCTION_INFO_V1(gist_page_items_bytea); +#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX) #define IS_GIST(r) ((r)->rd_rel->relam == GIST_AM_OID) @@ -217,7 +218,7 @@ gist_page_items(PG_FUNCTION_ARGS) /* Open the relation */ indexRel = index_open(indexRelid, AccessShareLock); - if (!IS_GIST(indexRel)) + if (!IS_INDEX(indexRel) || !IS_GIST(indexRel)) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not a %s index", -- 2.43.0
