Skip to content

Commit dd11071

Browse files
japinlihackorum
authored andcommitted
Check relkind for both BRIN and GIST indexes
Previously, only the access method was checked for BRIN and GIST indexes, allowing non-index relations to be passed. This commit also removes the pointless IS_INDEX macro. Suggested-by: Japin Li <japinli@hotmail.com> Suggested-by: Andrey Borodin <x4mmm@yandex-team.ru> Reviewed-by: Andreas Karlsson <andreas@proxel.se> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/MEAPR01MB3031A889D4B3F610E9D2A3AFB68FA@MEAPR01MB3031.ausprd01.prod.outlook.com Discussion: https://postgr.es/m/BFCA6110-EC97-4569-917A-747A72F62CE8@yandex-team.ru
1 parent 086f6f1 commit dd11071

4 files changed

Lines changed: 7 additions & 9 deletions

File tree

contrib/pageinspect/brinfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PG_FUNCTION_INFO_V1(brin_page_items);
2929
PG_FUNCTION_INFO_V1(brin_metapage_info);
3030
PG_FUNCTION_INFO_V1(brin_revmap_data);
3131

32-
#define IS_BRIN(r) ((r)->rd_rel->relam == BRIN_AM_OID)
32+
#define IS_BRIN(r) ((r)->rd_rel->relkind == RELKIND_INDEX && (r)->rd_rel->relam == BRIN_AM_OID)
3333

3434
typedef struct brin_column_state
3535
{

contrib/pageinspect/btreefuncs.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ PG_FUNCTION_INFO_V1(bt_page_stats_1_9);
4949
PG_FUNCTION_INFO_V1(bt_page_stats);
5050
PG_FUNCTION_INFO_V1(bt_multi_page_stats);
5151

52-
#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
53-
#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
52+
#define IS_BTREE(r) ((r)->rd_rel->relkind == RELKIND_INDEX && (r)->rd_rel->relam == BTREE_AM_OID)
5453

5554
/* ------------------------------------------------
5655
* structure for single btree page statistics
@@ -225,7 +224,7 @@ check_relation_block_range(Relation rel, int64 blkno)
225224
static void
226225
bt_index_block_validate(Relation rel, int64 blkno)
227226
{
228-
if (!IS_INDEX(rel) || !IS_BTREE(rel))
227+
if (!IS_BTREE(rel))
229228
ereport(ERROR,
230229
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
231230
errmsg("\"%s\" is not a %s index",
@@ -858,7 +857,7 @@ bt_metap(PG_FUNCTION_ARGS)
858857
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
859858
rel = relation_openrv(relrv, AccessShareLock);
860859

861-
if (!IS_INDEX(rel) || !IS_BTREE(rel))
860+
if (!IS_BTREE(rel))
862861
ereport(ERROR,
863862
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
864863
errmsg("\"%s\" is not a %s index",

contrib/pageinspect/gistfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PG_FUNCTION_INFO_V1(gist_page_opaque_info);
3131
PG_FUNCTION_INFO_V1(gist_page_items);
3232
PG_FUNCTION_INFO_V1(gist_page_items_bytea);
3333

34-
#define IS_GIST(r) ((r)->rd_rel->relam == GIST_AM_OID)
34+
#define IS_GIST(r) ((r)->rd_rel->relkind == RELKIND_INDEX && (r)->rd_rel->relam == GIST_AM_OID)
3535

3636

3737
static Page verify_gist_page(bytea *raw_page);

contrib/pageinspect/hashfuncs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ PG_FUNCTION_INFO_V1(hash_page_items);
2828
PG_FUNCTION_INFO_V1(hash_bitmap_info);
2929
PG_FUNCTION_INFO_V1(hash_metapage_info);
3030

31-
#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
32-
#define IS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID)
31+
#define IS_HASH(r) ((r)->rd_rel->relkind == RELKIND_INDEX && (r)->rd_rel->relam == HASH_AM_OID)
3332

3433
/* ------------------------------------------------
3534
* structure for single hash page statistics
@@ -420,7 +419,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
420419
*/
421420
indexRel = relation_open(indexRelid, AccessShareLock);
422421

423-
if (!IS_INDEX(indexRel) || !IS_HASH(indexRel))
422+
if (!IS_HASH(indexRel))
424423
ereport(ERROR,
425424
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
426425
errmsg("\"%s\" is not a %s index",

0 commit comments

Comments
 (0)