PostgreSQL Source Code  git master
pgstatindex.c File Reference
#include "postgres.h"
#include "access/gin_private.h"
#include "access/hash.h"
#include "access/htup_details.h"
#include "access/nbtree.h"
#include "access/relation.h"
#include "access/table.h"
#include "catalog/namespace.h"
#include "catalog/pg_am.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
#include "storage/lmgr.h"
#include "utils/builtins.h"
#include "utils/rel.h"
#include "utils/varlena.h"
Include dependency graph for pgstatindex.c:

Go to the source code of this file.

Data Structures

struct  BTIndexStat
 
struct  GinIndexStat
 
struct  HashIndexStat
 

Macros

#define IS_INDEX(r)   ((r)->rd_rel->relkind == RELKIND_INDEX)
 
#define IS_BTREE(r)   ((r)->rd_rel->relam == BTREE_AM_OID)
 
#define IS_GIN(r)   ((r)->rd_rel->relam == GIN_AM_OID)
 
#define IS_HASH(r)   ((r)->rd_rel->relam == HASH_AM_OID)
 

Typedefs

typedef struct BTIndexStat BTIndexStat
 
typedef struct GinIndexStat GinIndexStat
 
typedef struct HashIndexStat HashIndexStat
 

Functions

 PG_FUNCTION_INFO_V1 (pgstatindex)
 
 PG_FUNCTION_INFO_V1 (pgstatindexbyid)
 
 PG_FUNCTION_INFO_V1 (pg_relpages)
 
 PG_FUNCTION_INFO_V1 (pg_relpagesbyid)
 
 PG_FUNCTION_INFO_V1 (pgstatginindex)
 
 PG_FUNCTION_INFO_V1 (pgstathashindex)
 
 PG_FUNCTION_INFO_V1 (pgstatindex_v1_5)
 
 PG_FUNCTION_INFO_V1 (pgstatindexbyid_v1_5)
 
 PG_FUNCTION_INFO_V1 (pg_relpages_v1_5)
 
 PG_FUNCTION_INFO_V1 (pg_relpagesbyid_v1_5)
 
 PG_FUNCTION_INFO_V1 (pgstatginindex_v1_5)
 
Datum pgstatginindex_internal (Oid relid, FunctionCallInfo fcinfo)
 
static Datum pgstatindex_impl (Relation rel, FunctionCallInfo fcinfo)
 
static int64 pg_relpages_impl (Relation rel)
 
static void GetHashPageStats (Page page, HashIndexStat *stats)
 
Datum pgstatindex (PG_FUNCTION_ARGS)
 
Datum pgstatindex_v1_5 (PG_FUNCTION_ARGS)
 
Datum pgstatindexbyid (PG_FUNCTION_ARGS)
 
Datum pgstatindexbyid_v1_5 (PG_FUNCTION_ARGS)
 
Datum pg_relpages (PG_FUNCTION_ARGS)
 
Datum pg_relpages_v1_5 (PG_FUNCTION_ARGS)
 
Datum pg_relpagesbyid (PG_FUNCTION_ARGS)
 
Datum pg_relpagesbyid_v1_5 (PG_FUNCTION_ARGS)
 
Datum pgstatginindex (PG_FUNCTION_ARGS)
 
Datum pgstatginindex_v1_5 (PG_FUNCTION_ARGS)
 
Datum pgstathashindex (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ IS_BTREE

#define IS_BTREE (   r)    ((r)->rd_rel->relam == BTREE_AM_OID)

Definition at line 71 of file pgstatindex.c.

Referenced by pgstatindex_impl().

◆ IS_GIN

#define IS_GIN (   r)    ((r)->rd_rel->relam == GIN_AM_OID)

Definition at line 72 of file pgstatindex.c.

Referenced by pgstatginindex_internal().

◆ IS_HASH

#define IS_HASH (   r)    ((r)->rd_rel->relam == HASH_AM_OID)

Definition at line 73 of file pgstatindex.c.

Referenced by pgstathashindex().

◆ IS_INDEX

#define IS_INDEX (   r)    ((r)->rd_rel->relkind == RELKIND_INDEX)

Definition at line 70 of file pgstatindex.c.

Referenced by pgstatginindex_internal(), and pgstatindex_impl().

Typedef Documentation

◆ BTIndexStat

typedef struct BTIndexStat BTIndexStat

◆ GinIndexStat

typedef struct GinIndexStat GinIndexStat

◆ HashIndexStat

typedef struct HashIndexStat HashIndexStat

Function Documentation

◆ GetHashPageStats()

static void GetHashPageStats ( Page  page,
HashIndexStat stats 
)
static

Definition at line 721 of file pgstatindex.c.

References HashIndexStat::dead_items, FirstOffsetNumber, HashIndexStat::free_space, ItemIdIsDead, HashIndexStat::live_items, PageGetExactFreeSpace(), PageGetItemId, and PageGetMaxOffsetNumber.

Referenced by pgstathashindex().

722 {
723  OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
724  int off;
725 
726  /* count live and dead tuples, and free space */
727  for (off = FirstOffsetNumber; off <= maxoff; off++)
728  {
729  ItemId id = PageGetItemId(page, off);
730 
731  if (!ItemIdIsDead(id))
732  stats->live_items++;
733  else
734  stats->dead_items++;
735  }
736  stats->free_space += PageGetExactFreeSpace(page);
737 }
uint64 free_space
Definition: pgstatindex.c:127
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
uint16 OffsetNumber
Definition: off.h:24
int64 dead_items
Definition: pgstatindex.c:126
#define FirstOffsetNumber
Definition: off.h:27
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:951
int64 live_items
Definition: pgstatindex.c:125

◆ PG_FUNCTION_INFO_V1() [1/11]

PG_FUNCTION_INFO_V1 ( pgstatindex  )

◆ PG_FUNCTION_INFO_V1() [2/11]

PG_FUNCTION_INFO_V1 ( pgstatindexbyid  )

◆ PG_FUNCTION_INFO_V1() [3/11]

PG_FUNCTION_INFO_V1 ( pg_relpages  )

◆ PG_FUNCTION_INFO_V1() [4/11]

PG_FUNCTION_INFO_V1 ( pg_relpagesbyid  )

◆ PG_FUNCTION_INFO_V1() [5/11]

PG_FUNCTION_INFO_V1 ( pgstatginindex  )

◆ PG_FUNCTION_INFO_V1() [6/11]

PG_FUNCTION_INFO_V1 ( pgstathashindex  )

◆ PG_FUNCTION_INFO_V1() [7/11]

PG_FUNCTION_INFO_V1 ( pgstatindex_v1_5  )

◆ PG_FUNCTION_INFO_V1() [8/11]

PG_FUNCTION_INFO_V1 ( pgstatindexbyid_v1_5  )

◆ PG_FUNCTION_INFO_V1() [9/11]

PG_FUNCTION_INFO_V1 ( pg_relpages_v1_5  )

◆ PG_FUNCTION_INFO_V1() [10/11]

PG_FUNCTION_INFO_V1 ( pg_relpagesbyid_v1_5  )

◆ PG_FUNCTION_INFO_V1() [11/11]

PG_FUNCTION_INFO_V1 ( pgstatginindex_v1_5  )

◆ pg_relpages()

Datum pg_relpages ( PG_FUNCTION_ARGS  )

Definition at line 383 of file pgstatindex.c.

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, makeRangeVarFromNameList(), PG_GETARG_TEXT_PP, pg_relpages_impl(), PG_RETURN_INT64, relation_openrv(), relname, superuser(), and textToQualifiedNameList().

384 {
386  Relation rel;
387  RangeVar *relrv;
388 
389  if (!superuser())
390  ereport(ERROR,
391  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
392  errmsg("must be superuser to use pgstattuple functions")));
393 
395  rel = relation_openrv(relrv, AccessShareLock);
396 
398 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3107
NameData relname
Definition: pg_class.h:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define ERROR
Definition: elog.h:46
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3688
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909
Definition: c.h:621
static int64 pg_relpages_impl(Relation rel)
Definition: pgstatindex.c:444

◆ pg_relpages_impl()

static int64 pg_relpages_impl ( Relation  rel)
static

Definition at line 444 of file pgstatindex.c.

References AccessShareLock, ereport, errcode(), errdetail_relkind_not_supported(), errmsg(), ERROR, RelationData::rd_rel, relation_close(), RelationGetNumberOfBlocks, and RelationGetRelationName.

Referenced by pg_relpages(), pg_relpages_v1_5(), pg_relpagesbyid(), and pg_relpagesbyid_v1_5().

445 {
446  int64 relpages;
447 
448  if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
449  ereport(ERROR,
450  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
451  errmsg("cannot get page count of relation \"%s\"",
453  errdetail_relkind_not_supported(rel->rd_rel->relkind)));
454 
455  /* note: this will work OK on non-local temp tables */
456 
457  relpages = RelationGetNumberOfBlocks(rel);
458 
460 
461  return relpages;
462 }
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
Form_pg_class rd_rel
Definition: rel.h:109
#define ERROR
Definition: elog.h:46
#define RelationGetRelationName(relation)
Definition: rel.h:511
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:212
#define ereport(elevel,...)
Definition: elog.h:157
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ pg_relpages_v1_5()

Datum pg_relpages_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 402 of file pgstatindex.c.

References AccessShareLock, makeRangeVarFromNameList(), PG_GETARG_TEXT_PP, pg_relpages_impl(), PG_RETURN_INT64, relation_openrv(), relname, and textToQualifiedNameList().

403 {
405  Relation rel;
406  RangeVar *relrv;
407 
409  rel = relation_openrv(relrv, AccessShareLock);
410 
412 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define AccessShareLock
Definition: lockdefs.h:36
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3107
NameData relname
Definition: pg_class.h:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3688
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
Definition: c.h:621
static int64 pg_relpages_impl(Relation rel)
Definition: pgstatindex.c:444

◆ pg_relpagesbyid()

Datum pg_relpagesbyid ( PG_FUNCTION_ARGS  )

Definition at line 416 of file pgstatindex.c.

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, PG_GETARG_OID, pg_relpages_impl(), PG_RETURN_INT64, relation_open(), and superuser().

417 {
418  Oid relid = PG_GETARG_OID(0);
419  Relation rel;
420 
421  if (!superuser())
422  ereport(ERROR,
423  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
424  errmsg("must be superuser to use pgstattuple functions")));
425 
426  rel = relation_open(relid, AccessShareLock);
427 
429 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:46
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909
static int64 pg_relpages_impl(Relation rel)
Definition: pgstatindex.c:444

◆ pg_relpagesbyid_v1_5()

Datum pg_relpagesbyid_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 433 of file pgstatindex.c.

References AccessShareLock, PG_GETARG_OID, pg_relpages_impl(), PG_RETURN_INT64, and relation_open().

434 {
435  Oid relid = PG_GETARG_OID(0);
436  Relation rel;
437 
438  rel = relation_open(relid, AccessShareLock);
439 
441 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define AccessShareLock
Definition: lockdefs.h:36
unsigned int Oid
Definition: postgres_ext.h:31
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
static int64 pg_relpages_impl(Relation rel)
Definition: pgstatindex.c:444

◆ pgstatginindex()

Datum pgstatginindex ( PG_FUNCTION_ARGS  )

Definition at line 473 of file pgstatindex.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_OID, PG_RETURN_DATUM, pgstatginindex_internal(), and superuser().

474 {
475  Oid relid = PG_GETARG_OID(0);
476 
477  if (!superuser())
478  ereport(ERROR,
479  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
480  errmsg("must be superuser to use pgstattuple functions")));
481 
483 }
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:495
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:46
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ pgstatginindex_internal()

Datum pgstatginindex_internal ( Oid  relid,
FunctionCallInfo  fcinfo 
)

Definition at line 495 of file pgstatindex.c.

References AccessShareLock, BufferGetPage, elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), GIN_METAPAGE_BLKNO, GIN_SHARE, GinPageGetMeta, GinMetaPageData::ginVersion, heap_form_tuple(), HeapTupleGetDatum, Int32GetDatum, Int64GetDatum(), IS_GIN, IS_INDEX, LockBuffer(), GinMetaPageData::nPendingHeapTuples, GinMetaPageData::nPendingPages, GinIndexStat::pending_pages, GinIndexStat::pending_tuples, ReadBuffer(), relation_close(), RELATION_IS_OTHER_TEMP, relation_open(), RelationGetRelationName, TYPEFUNC_COMPOSITE, UInt32GetDatum, UnlockReleaseBuffer(), values, and GinIndexStat::version.

Referenced by pgstatginindex(), and pgstatginindex_v1_5().

496 {
497  Relation rel;
498  Buffer buffer;
499  Page page;
500  GinMetaPageData *metadata;
501  GinIndexStat stats;
502  HeapTuple tuple;
503  TupleDesc tupleDesc;
504  Datum values[3];
505  bool nulls[3] = {false, false, false};
506  Datum result;
507 
508  rel = relation_open(relid, AccessShareLock);
509 
510  if (!IS_INDEX(rel) || !IS_GIN(rel))
511  ereport(ERROR,
512  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
513  errmsg("relation \"%s\" is not a GIN index",
514  RelationGetRelationName(rel))));
515 
516  /*
517  * Reject attempts to read non-local temporary relations; we would be
518  * likely to get wrong data since we have no visibility into the owning
519  * session's local buffers.
520  */
521  if (RELATION_IS_OTHER_TEMP(rel))
522  ereport(ERROR,
523  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
524  errmsg("cannot access temporary indexes of other sessions")));
525 
526  /*
527  * Read metapage
528  */
529  buffer = ReadBuffer(rel, GIN_METAPAGE_BLKNO);
530  LockBuffer(buffer, GIN_SHARE);
531  page = BufferGetPage(buffer);
532  metadata = GinPageGetMeta(page);
533 
534  stats.version = metadata->ginVersion;
535  stats.pending_pages = metadata->nPendingPages;
536  stats.pending_tuples = metadata->nPendingHeapTuples;
537 
538  UnlockReleaseBuffer(buffer);
540 
541  /*
542  * Build a tuple descriptor for our result type
543  */
544  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
545  elog(ERROR, "return type must be a row type");
546 
547  values[0] = Int32GetDatum(stats.version);
548  values[1] = UInt32GetDatum(stats.pending_pages);
549  values[2] = Int64GetDatum(stats.pending_tuples);
550 
551  /*
552  * Build and return the tuple
553  */
554  tuple = heap_form_tuple(tupleDesc, values, nulls);
555  result = HeapTupleGetDatum(tuple);
556 
557  return result;
558 }
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:207
int64 pending_tuples
Definition: pgstatindex.c:107
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:52
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define IS_INDEX(r)
Definition: pgstatindex.c:70
int64 nPendingHeapTuples
Definition: ginblock.h:75
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3791
#define ERROR
Definition: elog.h:46
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define RelationGetRelationName(relation)
Definition: rel.h:511
#define UInt32GetDatum(X)
Definition: postgres.h:537
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1697
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define GIN_SHARE
Definition: gin_private.h:49
BlockNumber pending_pages
Definition: pgstatindex.c:106
#define IS_GIN(r)
Definition: pgstatindex.c:72
uintptr_t Datum
Definition: postgres.h:411
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4007
#define ereport(elevel,...)
Definition: elog.h:157
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:631
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:694
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
int32 ginVersion
Definition: ginblock.h:100
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define Int32GetDatum(X)
Definition: postgres.h:523
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
#define GinPageGetMeta(p)
Definition: ginblock.h:105
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78
BlockNumber nPendingPages
Definition: ginblock.h:74

◆ pgstatginindex_v1_5()

Datum pgstatginindex_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 487 of file pgstatindex.c.

References PG_GETARG_OID, PG_RETURN_DATUM, and pgstatginindex_internal().

488 {
489  Oid relid = PG_GETARG_OID(0);
490 
492 }
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:495
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353

◆ pgstathashindex()

Datum pgstathashindex ( PG_FUNCTION_ARGS  )

Definition at line 567 of file pgstatindex.c.

References _hash_getbuf(), _hash_relbuf(), AccessShareLock, BAS_BULKREAD, HashIndexStat::bitmap_pages, BlessTupleDesc(), HashIndexStat::bucket_pages, buf, BUFFER_LOCK_SHARE, BufferGetBlockNumber(), BufferGetPage, CHECK_FOR_INTERRUPTS, HashIndexStat::dead_items, elog, ereport, errcode(), errmsg(), ERROR, Float8GetDatum(), HashIndexStat::free_space, get_call_result_type(), GetAccessStrategy(), GetHashPageStats(), HASH_METAPAGE, HASH_READ, HashMetaPageData::hashm_bsize, HashMetaPageData::hashm_version, HashPageOpaqueData::hasho_flag, HashPageGetMeta, heap_form_tuple(), HeapTupleGetDatum, index_close(), index_open(), Int32GetDatum, Int64GetDatum(), IS_HASH, LH_BITMAP_PAGE, LH_BUCKET_PAGE, LH_META_PAGE, LH_OVERFLOW_PAGE, LH_PAGE_TYPE, LH_UNUSED_PAGE, HashIndexStat::live_items, LockBuffer(), MAIN_FORKNUM, MAXALIGN, MemSet, HashIndexStat::overflow_pages, PageGetSpecialPointer, PageGetSpecialSize, PageIsNew, PG_GETARG_OID, PG_RETURN_DATUM, RBM_NORMAL, ReadBufferExtended(), RELATION_IS_OTHER_TEMP, RelationGetNumberOfBlocks, RelationGetRelationName, HashIndexStat::space_per_page, TYPEFUNC_COMPOSITE, UnlockReleaseBuffer(), HashIndexStat::unused_pages, values, and HashIndexStat::version.

568 {
569  Oid relid = PG_GETARG_OID(0);
570  BlockNumber nblocks;
571  BlockNumber blkno;
572  Relation rel;
573  HashIndexStat stats;
574  BufferAccessStrategy bstrategy;
575  HeapTuple tuple;
576  TupleDesc tupleDesc;
577  Datum values[8];
578  bool nulls[8];
579  Buffer metabuf;
580  HashMetaPage metap;
581  float8 free_percent;
582  uint64 total_space;
583 
584  rel = index_open(relid, AccessShareLock);
585 
586  /* index_open() checks that it's an index */
587  if (!IS_HASH(rel))
588  ereport(ERROR,
589  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
590  errmsg("relation \"%s\" is not a hash index",
591  RelationGetRelationName(rel))));
592 
593  /*
594  * Reject attempts to read non-local temporary relations; we would be
595  * likely to get wrong data since we have no visibility into the owning
596  * session's local buffers.
597  */
598  if (RELATION_IS_OTHER_TEMP(rel))
599  ereport(ERROR,
600  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
601  errmsg("cannot access temporary indexes of other sessions")));
602 
603  /* Get the information we need from the metapage. */
604  memset(&stats, 0, sizeof(stats));
606  metap = HashPageGetMeta(BufferGetPage(metabuf));
607  stats.version = metap->hashm_version;
608  stats.space_per_page = metap->hashm_bsize;
609  _hash_relbuf(rel, metabuf);
610 
611  /* Get the current relation length */
612  nblocks = RelationGetNumberOfBlocks(rel);
613 
614  /* prepare access strategy for this index */
615  bstrategy = GetAccessStrategy(BAS_BULKREAD);
616 
617  /* Start from blkno 1 as 0th block is metapage */
618  for (blkno = 1; blkno < nblocks; blkno++)
619  {
620  Buffer buf;
621  Page page;
622 
624 
625  buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL,
626  bstrategy);
628  page = (Page) BufferGetPage(buf);
629 
630  if (PageIsNew(page))
631  stats.unused_pages++;
632  else if (PageGetSpecialSize(page) !=
633  MAXALIGN(sizeof(HashPageOpaqueData)))
634  ereport(ERROR,
635  (errcode(ERRCODE_INDEX_CORRUPTED),
636  errmsg("index \"%s\" contains corrupted page at block %u",
638  BufferGetBlockNumber(buf))));
639  else
640  {
641  HashPageOpaque opaque;
642  int pagetype;
643 
644  opaque = (HashPageOpaque) PageGetSpecialPointer(page);
645  pagetype = opaque->hasho_flag & LH_PAGE_TYPE;
646 
647  if (pagetype == LH_BUCKET_PAGE)
648  {
649  stats.bucket_pages++;
650  GetHashPageStats(page, &stats);
651  }
652  else if (pagetype == LH_OVERFLOW_PAGE)
653  {
654  stats.overflow_pages++;
655  GetHashPageStats(page, &stats);
656  }
657  else if (pagetype == LH_BITMAP_PAGE)
658  stats.bitmap_pages++;
659  else if (pagetype == LH_UNUSED_PAGE)
660  stats.unused_pages++;
661  else
662  ereport(ERROR,
663  (errcode(ERRCODE_INDEX_CORRUPTED),
664  errmsg("unexpected page type 0x%04X in HASH index \"%s\" block %u",
665  opaque->hasho_flag, RelationGetRelationName(rel),
666  BufferGetBlockNumber(buf))));
667  }
668  UnlockReleaseBuffer(buf);
669  }
670 
671  /* Done accessing the index */
673 
674  /* Count unused pages as free space. */
675  stats.free_space += (uint64) stats.unused_pages * stats.space_per_page;
676 
677  /*
678  * Total space available for tuples excludes the metapage and the bitmap
679  * pages.
680  */
681  total_space = (uint64) (nblocks - (stats.bitmap_pages + 1)) *
682  stats.space_per_page;
683 
684  if (total_space == 0)
685  free_percent = 0.0;
686  else
687  free_percent = 100.0 * stats.free_space / total_space;
688 
689  /*
690  * Build a tuple descriptor for our result type
691  */
692  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
693  elog(ERROR, "return type must be a row type");
694 
695  tupleDesc = BlessTupleDesc(tupleDesc);
696 
697  /*
698  * Build and return the tuple
699  */
700  MemSet(nulls, 0, sizeof(nulls));
701  values[0] = Int32GetDatum(stats.version);
702  values[1] = Int64GetDatum((int64) stats.bucket_pages);
703  values[2] = Int64GetDatum((int64) stats.overflow_pages);
704  values[3] = Int64GetDatum((int64) stats.bitmap_pages);
705  values[4] = Int64GetDatum((int64) stats.unused_pages);
706  values[5] = Int64GetDatum(stats.live_items);
707  values[6] = Int64GetDatum(stats.dead_items);
708  values[7] = Float8GetDatum(free_percent);
709  tuple = heap_form_tuple(tupleDesc, values, nulls);
710 
712 }
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:542
BlockNumber overflow_pages
Definition: pgstatindex.c:121
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:207
#define LH_BITMAP_PAGE
Definition: hash.h:56
#define LH_META_PAGE
Definition: hash.h:57
BlockNumber bitmap_pages
Definition: pgstatindex.c:122
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:741
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
#define MemSet(start, val, len)
Definition: c.h:1008
uint32 BlockNumber
Definition: block.h:31
uint64 free_space
Definition: pgstatindex.c:127
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:69
unsigned int Oid
Definition: postgres_ext.h:31
BlockNumber unused_pages
Definition: pgstatindex.c:123
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1706
int32 space_per_page
Definition: pgstatindex.c:118
#define LH_UNUSED_PAGE
Definition: hash.h:53
#define LH_PAGE_TYPE
Definition: hash.h:63
#define HASH_READ
Definition: hash.h:337
int64 dead_items
Definition: pgstatindex.c:126
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3791
#define ERROR
Definition: elog.h:46
double float8
Definition: c.h:565
static void GetHashPageStats(Page page, HashIndexStat *stats)
Definition: pgstatindex.c:721
uint32 hashm_version
Definition: hash.h:245
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2082
static char * buf
Definition: pg_test_fsync.c:68
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define RelationGetRelationName(relation)
Definition: rel.h:511
#define IS_HASH(r)
Definition: pgstatindex.c:73
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1697
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
uint16 hashm_bsize
Definition: hash.h:248
#define HASH_METAPAGE
Definition: hash.h:196
uintptr_t Datum
Definition: postgres.h:411
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define LH_OVERFLOW_PAGE
Definition: hash.h:54
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4007
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:212
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:265
#define ereport(elevel,...)
Definition: elog.h:157
#define LH_BUCKET_PAGE
Definition: hash.h:55
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:631
#define PageGetSpecialPointer(page)
Definition: bufpage.h:326
HashPageOpaqueData * HashPageOpaque
Definition: hash.h:86
#define MAXALIGN(LEN)
Definition: c.h:757
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
#define PageGetSpecialSize(page)
Definition: bufpage.h:300
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
uint16 hasho_flag
Definition: hash.h:82
static Datum values[MAXATTR]
Definition: bootstrap.c:156
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2748
#define Int32GetDatum(X)
Definition: postgres.h:523
#define PageIsNew(page)
Definition: bufpage.h:229
#define HashPageGetMeta(page)
Definition: hash.h:321
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
int Buffer
Definition: buf.h:23
BlockNumber bucket_pages
Definition: pgstatindex.c:120
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132
Pointer Page
Definition: bufpage.h:78
int64 live_items
Definition: pgstatindex.c:125

◆ pgstatindex()

Datum pgstatindex ( PG_FUNCTION_ARGS  )

Definition at line 145 of file pgstatindex.c.

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, makeRangeVarFromNameList(), PG_GETARG_TEXT_PP, PG_RETURN_DATUM, pgstatindex_impl(), relation_openrv(), relname, superuser(), and textToQualifiedNameList().

146 {
148  Relation rel;
149  RangeVar *relrv;
150 
151  if (!superuser())
152  ereport(ERROR,
153  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
154  errmsg("must be superuser to use pgstattuple functions")));
155 
157  rel = relation_openrv(relrv, AccessShareLock);
158 
159  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
160 }
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3107
NameData relname
Definition: pg_class.h:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:216
#define ERROR
Definition: elog.h:46
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3688
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909
Definition: c.h:621

◆ pgstatindex_impl()

static Datum pgstatindex_impl ( Relation  rel,
FunctionCallInfo  fcinfo 
)
static

Definition at line 216 of file pgstatindex.c.

References AccessShareLock, BAS_BULKREAD, BTMetaPageData::btm_level, BTMetaPageData::btm_root, BTMetaPageData::btm_version, BTPageGetMeta, BTPageOpaqueData::btpo_next, BUFFER_LOCK_SHARE, BUFFER_LOCK_UNLOCK, BufferGetPage, BuildTupleFromCStrings(), CHECK_FOR_INTERRUPTS, BTIndexStat::deleted_pages, elog, BTIndexStat::empty_pages, ereport, errcode(), errmsg(), ERROR, BTIndexStat::fragments, BTIndexStat::free_space, get_call_result_type(), GetAccessStrategy(), HeapTupleGetDatum, INT64_FORMAT, BTIndexStat::internal_pages, IS_BTREE, IS_INDEX, BTIndexStat::leaf_pages, BTIndexStat::level, LockBuffer(), MAIN_FORKNUM, BTIndexStat::max_avail, P_IGNORE, P_ISDELETED, P_ISLEAF, P_NONE, PageGetFreeSpace(), PageGetSpecialPointer, psprintf(), pstrdup(), RBM_NORMAL, ReadBufferExtended(), relation_close(), RELATION_IS_OTHER_TEMP, RelationGetNumberOfBlocks, RelationGetRelationName, ReleaseBuffer(), BTIndexStat::root_blkno, SizeOfPageHeaderData, TupleDescGetAttInMetadata(), TYPEFUNC_COMPOSITE, values, and BTIndexStat::version.

Referenced by pgstatindex(), pgstatindex_v1_5(), pgstatindexbyid(), and pgstatindexbyid_v1_5().

217 {
218  Datum result;
219  BlockNumber nblocks;
220  BlockNumber blkno;
221  BTIndexStat indexStat;
223 
224  if (!IS_INDEX(rel) || !IS_BTREE(rel))
225  ereport(ERROR,
226  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
227  errmsg("relation \"%s\" is not a btree index",
228  RelationGetRelationName(rel))));
229 
230  /*
231  * Reject attempts to read non-local temporary relations; we would be
232  * likely to get wrong data since we have no visibility into the owning
233  * session's local buffers.
234  */
235  if (RELATION_IS_OTHER_TEMP(rel))
236  ereport(ERROR,
237  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
238  errmsg("cannot access temporary tables of other sessions")));
239 
240  /*
241  * Read metapage
242  */
243  {
244  Buffer buffer = ReadBufferExtended(rel, MAIN_FORKNUM, 0, RBM_NORMAL, bstrategy);
245  Page page = BufferGetPage(buffer);
246  BTMetaPageData *metad = BTPageGetMeta(page);
247 
248  indexStat.version = metad->btm_version;
249  indexStat.level = metad->btm_level;
250  indexStat.root_blkno = metad->btm_root;
251 
252  ReleaseBuffer(buffer);
253  }
254 
255  /* -- init counters -- */
256  indexStat.internal_pages = 0;
257  indexStat.leaf_pages = 0;
258  indexStat.empty_pages = 0;
259  indexStat.deleted_pages = 0;
260 
261  indexStat.max_avail = 0;
262  indexStat.free_space = 0;
263 
264  indexStat.fragments = 0;
265 
266  /*
267  * Scan all blocks except the metapage
268  */
269  nblocks = RelationGetNumberOfBlocks(rel);
270 
271  for (blkno = 1; blkno < nblocks; blkno++)
272  {
273  Buffer buffer;
274  Page page;
275  BTPageOpaque opaque;
276 
278 
279  /* Read and lock buffer */
280  buffer = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
281  LockBuffer(buffer, BUFFER_LOCK_SHARE);
282 
283  page = BufferGetPage(buffer);
284  opaque = (BTPageOpaque) PageGetSpecialPointer(page);
285 
286  /*
287  * Determine page type, and update totals.
288  *
289  * Note that we arbitrarily bucket deleted pages together without
290  * considering if they're leaf pages or internal pages.
291  */
292  if (P_ISDELETED(opaque))
293  indexStat.deleted_pages++;
294  else if (P_IGNORE(opaque))
295  indexStat.empty_pages++; /* this is the "half dead" state */
296  else if (P_ISLEAF(opaque))
297  {
298  int max_avail;
299 
300  max_avail = BLCKSZ - (BLCKSZ - ((PageHeader) page)->pd_special + SizeOfPageHeaderData);
301  indexStat.max_avail += max_avail;
302  indexStat.free_space += PageGetFreeSpace(page);
303 
304  indexStat.leaf_pages++;
305 
306  /*
307  * If the next leaf is on an earlier block, it means a
308  * fragmentation.
309  */
310  if (opaque->btpo_next != P_NONE && opaque->btpo_next < blkno)
311  indexStat.fragments++;
312  }
313  else
314  indexStat.internal_pages++;
315 
316  /* Unlock and release buffer */
318  ReleaseBuffer(buffer);
319  }
320 
322 
323  /*----------------------------
324  * Build a result tuple
325  *----------------------------
326  */
327  {
328  TupleDesc tupleDesc;
329  int j;
330  char *values[10];
331  HeapTuple tuple;
332 
333  /* Build a tuple descriptor for our result type */
334  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
335  elog(ERROR, "return type must be a row type");
336 
337  j = 0;
338  values[j++] = psprintf("%d", indexStat.version);
339  values[j++] = psprintf("%d", indexStat.level);
340  values[j++] = psprintf(INT64_FORMAT,
341  (1 + /* include the metapage in index_size */
342  indexStat.leaf_pages +
343  indexStat.internal_pages +
344  indexStat.deleted_pages +
345  indexStat.empty_pages) * BLCKSZ);
346  values[j++] = psprintf("%u", indexStat.root_blkno);
347  values[j++] = psprintf(INT64_FORMAT, indexStat.internal_pages);
348  values[j++] = psprintf(INT64_FORMAT, indexStat.leaf_pages);
349  values[j++] = psprintf(INT64_FORMAT, indexStat.empty_pages);
350  values[j++] = psprintf(INT64_FORMAT, indexStat.deleted_pages);
351  if (indexStat.max_avail > 0)
352  values[j++] = psprintf("%.2f",
353  100.0 - (double) indexStat.free_space / (double) indexStat.max_avail * 100.0);
354  else
355  values[j++] = pstrdup("NaN");
356  if (indexStat.leaf_pages > 0)
357  values[j++] = psprintf("%.2f",
358  (double) indexStat.fragments / (double) indexStat.leaf_pages * 100.0);
359  else
360  values[j++] = pstrdup("NaN");
361 
363  values);
364 
365  result = HeapTupleGetDatum(tuple);
366  }
367 
368  return result;
369 }
uint64 empty_pages
Definition: pgstatindex.c:88
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:542
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:96
BlockNumber btpo_next
Definition: nbtree.h:65
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:207
#define P_IGNORE(opaque)
Definition: nbtree.h:224
uint64 fragments
Definition: pgstatindex.c:94
uint32 version
Definition: pgstatindex.c:82
uint32 btm_version
Definition: nbtree.h:104
BlockNumber root_blkno
Definition: pgstatindex.c:84
char * pstrdup(const char *in)
Definition: mcxt.c:1299
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:741
#define P_NONE
Definition: nbtree.h:211
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3768
#define IS_INDEX(r)
Definition: pgstatindex.c:70
#define SizeOfPageHeaderData
Definition: bufpage.h:216
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:71
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:900
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2146
#define IS_BTREE(r)
Definition: pgstatindex.c:71
#define ERROR
Definition: elog.h:46
uint64 internal_pages
Definition: pgstatindex.c:86
#define BTPageGetMeta(p)
Definition: nbtree.h:119
#define RelationGetRelationName(relation)
Definition: rel.h:511
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define P_ISDELETED(opaque)
Definition: nbtree.h:221
uintptr_t Datum
Definition: postgres.h:411
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2097
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4007
uint64 free_space
Definition: pgstatindex.c:92
BlockNumber btm_root
Definition: nbtree.h:105
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:212
#define ereport(elevel,...)
Definition: elog.h:157
PageHeaderData * PageHeader
Definition: bufpage.h:166
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:631
uint64 leaf_pages
Definition: pgstatindex.c:87
#define PageGetSpecialPointer(page)
Definition: bufpage.h:326
uint32 level
Definition: pgstatindex.c:83
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
#define INT64_FORMAT
Definition: c.h:483
static Datum values[MAXATTR]
Definition: bootstrap.c:156
int errmsg(const char *fmt,...)
Definition: elog.c:909
uint32 btm_level
Definition: nbtree.h:106
#define elog(elevel,...)
Definition: elog.h:232
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
uint64 deleted_pages
Definition: pgstatindex.c:89
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78
uint64 max_avail
Definition: pgstatindex.c:91
#define P_ISLEAF(opaque)
Definition: nbtree.h:219

◆ pgstatindex_v1_5()

Datum pgstatindex_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 170 of file pgstatindex.c.

References AccessShareLock, makeRangeVarFromNameList(), PG_GETARG_TEXT_PP, PG_RETURN_DATUM, pgstatindex_impl(), relation_openrv(), relname, and textToQualifiedNameList().

171 {
173  Relation rel;
174  RangeVar *relrv;
175 
177  rel = relation_openrv(relrv, AccessShareLock);
178 
179  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
180 }
#define AccessShareLock
Definition: lockdefs.h:36
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3107
NameData relname
Definition: pg_class.h:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:216
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3688
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
Definition: c.h:621

◆ pgstatindexbyid()

Datum pgstatindexbyid ( PG_FUNCTION_ARGS  )

Definition at line 188 of file pgstatindex.c.

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, PG_GETARG_OID, PG_RETURN_DATUM, pgstatindex_impl(), relation_open(), and superuser().

189 {
190  Oid relid = PG_GETARG_OID(0);
191  Relation rel;
192 
193  if (!superuser())
194  ereport(ERROR,
195  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
196  errmsg("must be superuser to use pgstattuple functions")));
197 
198  rel = relation_open(relid, AccessShareLock);
199 
200  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
201 }
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:216
#define ERROR
Definition: elog.h:46
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ pgstatindexbyid_v1_5()

Datum pgstatindexbyid_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 205 of file pgstatindex.c.

References AccessShareLock, PG_GETARG_OID, PG_RETURN_DATUM, pgstatindex_impl(), and relation_open().

206 {
207  Oid relid = PG_GETARG_OID(0);
208  Relation rel;
209 
210  rel = relation_open(relid, AccessShareLock);
211 
212  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
213 }
#define AccessShareLock
Definition: lockdefs.h:36
unsigned int Oid
Definition: postgres_ext.h:31
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:216
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353