Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/backend/storage/buffer/bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/file.h>
#include <unistd.h>

#include "access/amapi.h"
#include "access/tableam.h"
#include "access/xloginsert.h"
#include "access/xlogutils.h"
Expand Down Expand Up @@ -4021,6 +4022,17 @@ RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)
}
else if (RELKIND_HAS_STORAGE(relation->rd_rel->relkind))
{
if (relation->rd_rel->relkind == RELKIND_INDEX &&
relation->rd_indam != NULL &&
relation->rd_indam->amnblocks != NULL)
{
BlockNumber nblocks;

nblocks = relation->rd_indam->amnblocks(relation, forkNum);
if (BlockNumberIsValid(nblocks))
return nblocks;
}

return smgrnblocks(RelationGetSmgr(relation), forkNum);
}
else
Expand Down
7 changes: 7 additions & 0 deletions src/include/access/amapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ typedef void (*aminitparallelscan_function) (void *target);
/* (re)start parallel index scan */
typedef void (*amparallelrescan_function) (IndexScanDesc scan);

/* report number of index blocks */
typedef BlockNumber (*amnblocks_function) (Relation indexRelation,
ForkNumber forkNum);

/*
* API struct for an index AM. Note this must be stored in a single palloc'd
* chunk of memory.
Expand Down Expand Up @@ -333,6 +337,9 @@ typedef struct IndexAmRoutine
amestimateparallelscan_function amestimateparallelscan; /* can be NULL */
aminitparallelscan_function aminitparallelscan; /* can be NULL */
amparallelrescan_function amparallelrescan; /* can be NULL */

/* report number of index blocks, can be NULL */
amnblocks_function amnblocks; /* can be NULL */
} IndexAmRoutine;


Expand Down