PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pgstatindex.c File Reference
#include "postgres.h"
#include "access/gin_private.h"
#include "access/heapam.h"
#include "access/hash.h"
#include "access/htup_details.h"
#include "access/nbtree.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 void GetHashPageStats (Page page, HashIndexStat *stats)
 
static void check_relation_relkind (Relation rel)
 
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

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

Definition at line 70 of file pgstatindex.c.

Referenced by pgstatindex_impl().

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

Definition at line 71 of file pgstatindex.c.

Referenced by pgstatginindex_internal().

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

Definition at line 72 of file pgstatindex.c.

Referenced by pgstathashindex().

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

Definition at line 69 of file pgstatindex.c.

Referenced by pgstatginindex_internal(), and pgstatindex_impl().

Typedef Documentation

Function Documentation

static void check_relation_relkind ( Relation  rel)
static

Definition at line 758 of file pgstatindex.c.

References ereport, errcode(), errmsg(), ERROR, RelationData::rd_rel, RelationGetRelationName, RELKIND_INDEX, RELKIND_MATVIEW, RELKIND_RELATION, RELKIND_SEQUENCE, and RELKIND_TOASTVALUE.

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

759 {
760  if (rel->rd_rel->relkind != RELKIND_RELATION &&
761  rel->rd_rel->relkind != RELKIND_INDEX &&
762  rel->rd_rel->relkind != RELKIND_MATVIEW &&
763  rel->rd_rel->relkind != RELKIND_SEQUENCE &&
764  rel->rd_rel->relkind != RELKIND_TOASTVALUE)
765  ereport(ERROR,
766  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
767  errmsg("\"%s\" is not a table, index, materialized view, sequence, or TOAST table",
768  RelationGetRelationName(rel))));
769 }
#define RELKIND_MATVIEW
Definition: pg_class.h:165
int errcode(int sqlerrcode)
Definition: elog.c:575
Form_pg_class rd_rel
Definition: rel.h:114
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define ereport(elevel, rest)
Definition: elog.h:122
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define RELKIND_INDEX
Definition: pg_class.h:161
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
static void GetHashPageStats ( Page  page,
HashIndexStat stats 
)
static

Definition at line 735 of file pgstatindex.c.

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

Referenced by pgstathashindex().

736 {
737  OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
738  int off;
739 
740  /* count live and dead tuples, and free space */
741  for (off = FirstOffsetNumber; off <= maxoff; off++)
742  {
743  ItemId id = PageGetItemId(page, off);
744 
745  if (!ItemIdIsDead(id))
746  stats->live_items++;
747  else
748  stats->dead_items++;
749  }
750  stats->free_space += PageGetExactFreeSpace(page);
751 }
uint64 free_space
Definition: pgstatindex.c:126
#define ItemIdIsDead(itemId)
Definition: itemid.h:112
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
uint16 OffsetNumber
Definition: off.h:24
int64 dead_items
Definition: pgstatindex.c:125
#define FirstOffsetNumber
Definition: off.h:27
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:633
int64 live_items
Definition: pgstatindex.c:124
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 pg_relpages ( PG_FUNCTION_ARGS  )

Definition at line 378 of file pgstatindex.c.

References AccessShareLock, check_relation_relkind(), ereport, errcode(), errmsg(), ERROR, makeRangeVarFromNameList(), PG_GETARG_TEXT_PP, PG_RETURN_INT64, relation_close(), relation_openrv(), RelationGetNumberOfBlocks, superuser(), and textToQualifiedNameList().

379 {
380  text *relname = PG_GETARG_TEXT_PP(0);
381  int64 relpages;
382  Relation rel;
383  RangeVar *relrv;
384 
385  if (!superuser())
386  ereport(ERROR,
387  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
388  (errmsg("must be superuser to use pgstattuple functions"))));
389 
391  rel = relation_openrv(relrv, AccessShareLock);
392 
393  /* only some relkinds have storage */
395 
396  /* note: this will work OK on non-local temp tables */
397 
398  relpages = RelationGetNumberOfBlocks(rel);
399 
401 
402  PG_RETURN_INT64(relpages);
403 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1192
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define AccessShareLock
Definition: lockdefs.h:36
static void check_relation_relkind(Relation rel)
Definition: pgstatindex.c:758
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1260
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2913
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3182
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:199
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: c.h:439
Datum pg_relpages_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 407 of file pgstatindex.c.

References AccessShareLock, check_relation_relkind(), makeRangeVarFromNameList(), PG_GETARG_TEXT_PP, PG_RETURN_INT64, relation_close(), relation_openrv(), RelationGetNumberOfBlocks, and textToQualifiedNameList().

408 {
409  text *relname = PG_GETARG_TEXT_PP(0);
410  int64 relpages;
411  Relation rel;
412  RangeVar *relrv;
413 
415  rel = relation_openrv(relrv, AccessShareLock);
416 
417  /* only some relkinds have storage */
419 
420  /* note: this will work OK on non-local temp tables */
421 
422  relpages = RelationGetNumberOfBlocks(rel);
423 
425 
426  PG_RETURN_INT64(relpages);
427 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1192
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define AccessShareLock
Definition: lockdefs.h:36
static void check_relation_relkind(Relation rel)
Definition: pgstatindex.c:758
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1260
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2913
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3182
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:199
Definition: c.h:439
Datum pg_relpagesbyid ( PG_FUNCTION_ARGS  )

Definition at line 431 of file pgstatindex.c.

References AccessShareLock, check_relation_relkind(), ereport, errcode(), errmsg(), ERROR, PG_GETARG_OID, PG_RETURN_INT64, relation_close(), relation_open(), RelationGetNumberOfBlocks, and superuser().

432 {
433  Oid relid = PG_GETARG_OID(0);
434  int64 relpages;
435  Relation rel;
436 
437  if (!superuser())
438  ereport(ERROR,
439  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
440  (errmsg("must be superuser to use pgstattuple functions"))));
441 
442  rel = relation_open(relid, AccessShareLock);
443 
444  /* only some relkinds have storage */
446 
447  /* note: this will work OK on non-local temp tables */
448 
449  relpages = RelationGetNumberOfBlocks(rel);
450 
452 
453  PG_RETURN_INT64(relpages);
454 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define AccessShareLock
Definition: lockdefs.h:36
static void check_relation_relkind(Relation rel)
Definition: pgstatindex.c:758
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1260
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define ereport(elevel, rest)
Definition: elog.h:122
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:199
int errmsg(const char *fmt,...)
Definition: elog.c:797
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1114
Datum pg_relpagesbyid_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 458 of file pgstatindex.c.

References AccessShareLock, check_relation_relkind(), PG_GETARG_OID, PG_RETURN_INT64, relation_close(), relation_open(), and RelationGetNumberOfBlocks.

459 {
460  Oid relid = PG_GETARG_OID(0);
461  int64 relpages;
462  Relation rel;
463 
464  rel = relation_open(relid, AccessShareLock);
465 
466  /* only some relkinds have storage */
468 
469  /* note: this will work OK on non-local temp tables */
470 
471  relpages = RelationGetNumberOfBlocks(rel);
472 
474 
475  PG_RETURN_INT64(relpages);
476 }
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define AccessShareLock
Definition: lockdefs.h:36
static void check_relation_relkind(Relation rel)
Definition: pgstatindex.c:758
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1260
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:199
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1114
Datum pgstatginindex ( PG_FUNCTION_ARGS  )

Definition at line 487 of file pgstatindex.c.

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

488 {
489  Oid relid = PG_GETARG_OID(0);
490 
491  if (!superuser())
492  ereport(ERROR,
493  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
494  (errmsg("must be superuser to use pgstattuple functions"))));
495 
497 }
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:509
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
int errmsg(const char *fmt,...)
Definition: elog.c:797
Datum pgstatginindex_internal ( Oid  relid,
FunctionCallInfo  fcinfo 
)

Definition at line 509 of file pgstatindex.c.

References AccessShareLock, buffer, 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, NULL, GinIndexStat::pending_pages, GinIndexStat::pending_tuples, ReadBuffer(), relation_close(), RELATION_IS_OTHER_TEMP, relation_open(), RelationGetRelationName, result, TYPEFUNC_COMPOSITE, UInt32GetDatum, UnlockReleaseBuffer(), values, and GinIndexStat::version.

Referenced by pgstatginindex(), and pgstatginindex_v1_5().

510 {
511  Relation rel;
512  Buffer buffer;
513  Page page;
514  GinMetaPageData *metadata;
515  GinIndexStat stats;
516  HeapTuple tuple;
518  Datum values[3];
519  bool nulls[3] = {false, false, false};
520  Datum result;
521 
522  rel = relation_open(relid, AccessShareLock);
523 
524  if (!IS_INDEX(rel) || !IS_GIN(rel))
525  ereport(ERROR,
526  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
527  errmsg("relation \"%s\" is not a GIN index",
528  RelationGetRelationName(rel))));
529 
530  /*
531  * Reject attempts to read non-local temporary relations; we would be
532  * likely to get wrong data since we have no visibility into the owning
533  * session's local buffers.
534  */
535  if (RELATION_IS_OTHER_TEMP(rel))
536  ereport(ERROR,
537  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
538  errmsg("cannot access temporary indexes of other sessions")));
539 
540  /*
541  * Read metapage
542  */
543  buffer = ReadBuffer(rel, GIN_METAPAGE_BLKNO);
544  LockBuffer(buffer, GIN_SHARE);
545  page = BufferGetPage(buffer);
546  metadata = GinPageGetMeta(page);
547 
548  stats.version = metadata->ginVersion;
549  stats.pending_pages = metadata->nPendingPages;
550  stats.pending_tuples = metadata->nPendingHeapTuples;
551 
552  UnlockReleaseBuffer(buffer);
554 
555  /*
556  * Build a tuple descriptor for our result type
557  */
558  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
559  elog(ERROR, "return type must be a row type");
560 
561  values[0] = Int32GetDatum(stats.version);
562  values[1] = UInt32GetDatum(stats.pending_pages);
563  values[2] = Int64GetDatum(stats.pending_tuples);
564 
565  /*
566  * Build and return the tuple
567  */
568  tuple = heap_form_tuple(tupleDesc, values, nulls);
569  result = HeapTupleGetDatum(tuple);
570 
571  return (result);
572 }
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
int64 pending_tuples
Definition: pgstatindex.c:106
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1260
return result
Definition: formatting.c:1618
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:50
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define IS_INDEX(r)
Definition: pgstatindex.c:69
int64 nPendingHeapTuples
Definition: ginblock.h:73
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define UInt32GetDatum(X)
Definition: postgres.h:499
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1791
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
#define GIN_SHARE
Definition: gin_private.h:44
BlockNumber pending_pages
Definition: pgstatindex.c:105
#define IS_GIN(r)
Definition: pgstatindex.c:71
uintptr_t Datum
Definition: postgres.h:372
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define NULL
Definition: c.h:229
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:534
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
int32 ginVersion
Definition: ginblock.h:98
static Datum values[MAXATTR]
Definition: bootstrap.c:163
#define Int32GetDatum(X)
Definition: postgres.h:485
int errmsg(const char *fmt,...)
Definition: elog.c:797
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1114
#define GinPageGetMeta(p)
Definition: ginblock.h:103
#define elog
Definition: elog.h:219
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:74
BlockNumber nPendingPages
Definition: ginblock.h:72
Datum pgstatginindex_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 501 of file pgstatindex.c.

References PG_GETARG_OID, PG_RETURN_DATUM, and pgstatginindex_internal().

502 {
503  Oid relid = PG_GETARG_OID(0);
504 
506 }
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:509
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
Datum pgstathashindex ( PG_FUNCTION_ARGS  )

Definition at line 581 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, NULL, 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.

582 {
583  Oid relid = PG_GETARG_OID(0);
584  BlockNumber nblocks;
585  BlockNumber blkno;
586  Relation rel;
587  HashIndexStat stats;
588  BufferAccessStrategy bstrategy;
589  HeapTuple tuple;
591  Datum values[8];
592  bool nulls[8];
593  Buffer metabuf;
594  HashMetaPage metap;
595  float8 free_percent;
596  uint64 total_space;
597 
598  rel = index_open(relid, AccessShareLock);
599 
600  /* index_open() checks that it's an index */
601  if (!IS_HASH(rel))
602  ereport(ERROR,
603  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
604  errmsg("relation \"%s\" is not a HASH index",
605  RelationGetRelationName(rel))));
606 
607 
608  /*
609  * Reject attempts to read non-local temporary relations; we would be
610  * likely to get wrong data since we have no visibility into the owning
611  * session's local buffers.
612  */
613  if (RELATION_IS_OTHER_TEMP(rel))
614  ereport(ERROR,
615  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
616  errmsg("cannot access temporary indexes of other sessions")));
617 
618  /* Get the information we need from the metapage. */
619  memset(&stats, 0, sizeof(stats));
621  metap = HashPageGetMeta(BufferGetPage(metabuf));
622  stats.version = metap->hashm_version;
623  stats.space_per_page = metap->hashm_bsize;
624  _hash_relbuf(rel, metabuf);
625 
626  /* Get the current relation length */
627  nblocks = RelationGetNumberOfBlocks(rel);
628 
629  /* prepare access strategy for this index */
630  bstrategy = GetAccessStrategy(BAS_BULKREAD);
631 
632  /* Start from blkno 1 as 0th block is metapage */
633  for (blkno = 1; blkno < nblocks; blkno++)
634  {
635  Buffer buf;
636  Page page;
637 
639 
640  buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL,
641  bstrategy);
643  page = (Page) BufferGetPage(buf);
644 
645  if (PageIsNew(page))
646  stats.unused_pages++;
647  else if (PageGetSpecialSize(page) !=
648  MAXALIGN(sizeof(HashPageOpaqueData)))
649  ereport(ERROR,
650  (errcode(ERRCODE_INDEX_CORRUPTED),
651  errmsg("index \"%s\" contains corrupted page at block %u",
653  BufferGetBlockNumber(buf))));
654  else
655  {
656  HashPageOpaque opaque;
657  int pagetype;
658 
659  opaque = (HashPageOpaque) PageGetSpecialPointer(page);
660  pagetype = opaque->hasho_flag & LH_PAGE_TYPE;
661 
662  if (pagetype == LH_BUCKET_PAGE)
663  {
664  stats.bucket_pages++;
665  GetHashPageStats(page, &stats);
666  }
667  else if (pagetype == LH_OVERFLOW_PAGE)
668  {
669  stats.overflow_pages++;
670  GetHashPageStats(page, &stats);
671  }
672  else if (pagetype == LH_BITMAP_PAGE)
673  stats.bitmap_pages++;
674  else if (pagetype == LH_UNUSED_PAGE)
675  stats.unused_pages++;
676  else
677  ereport(ERROR,
678  (errcode(ERRCODE_INDEX_CORRUPTED),
679  errmsg("unexpected page type 0x%04X in HASH index \"%s\" block %u",
680  opaque->hasho_flag, RelationGetRelationName(rel),
681  BufferGetBlockNumber(buf))));
682  }
683  UnlockReleaseBuffer(buf);
684  }
685 
686  /* Done accessing the index */
688 
689  /* Count unused pages as free space. */
690  stats.free_space += stats.unused_pages * stats.space_per_page;
691 
692  /*
693  * Total space available for tuples excludes the metapage and the bitmap
694  * pages.
695  */
696  total_space = (nblocks - (stats.bitmap_pages + 1)) * stats.space_per_page;
697 
698  if (total_space == 0)
699  free_percent = 0.0;
700  else
701  free_percent = 100.0 * stats.free_space / total_space;
702 
703  /*
704  * Build a tuple descriptor for our result type
705  */
706  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
707  elog(ERROR, "return type must be a row type");
708 
709  tupleDesc = BlessTupleDesc(tupleDesc);
710 
711  /*
712  * Build and return the tuple
713  */
714  MemSet(nulls, 0, sizeof(nulls));
715  values[0] = Int32GetDatum(stats.version);
716  values[1] = Int64GetDatum((int64) stats.bucket_pages);
717  values[2] = Int64GetDatum((int64) stats.overflow_pages);
718  values[3] = Int64GetDatum((int64) stats.bitmap_pages);
719  values[4] = Int64GetDatum((int64) stats.unused_pages);
720  values[5] = Int64GetDatum(stats.live_items);
721  values[6] = Int64GetDatum(stats.dead_items);
722  values[7] = Float8GetDatum(free_percent);
723  tuple = heap_form_tuple(tupleDesc, values, nulls);
724 
726 }
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:525
BlockNumber overflow_pages
Definition: pgstatindex.c:120
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
#define LH_BITMAP_PAGE
Definition: hash.h:55
#define LH_META_PAGE
Definition: hash.h:56
BlockNumber bitmap_pages
Definition: pgstatindex.c:121
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:640
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MemSet(start, val, len)
Definition: c.h:857
uint32 BlockNumber
Definition: block.h:31
uint64 free_space
Definition: pgstatindex.c:126
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:78
unsigned int Oid
Definition: postgres_ext.h:31
BlockNumber unused_pages
Definition: pgstatindex.c:122
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1815
int32 space_per_page
Definition: pgstatindex.c:117
#define LH_UNUSED_PAGE
Definition: hash.h:52
#define LH_PAGE_TYPE
Definition: hash.h:62
#define HASH_READ
Definition: hash.h:282
int64 dead_items
Definition: pgstatindex.c:125
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3332
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:381
static void GetHashPageStats(Page page, HashIndexStat *stats)
Definition: pgstatindex.c:735
uint32 hashm_version
Definition: hash.h:205
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
static char * buf
Definition: pg_test_fsync.c:66
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define IS_HASH(r)
Definition: pgstatindex.c:72
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1791
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
uint16 hashm_bsize
Definition: hash.h:208
#define HASH_METAPAGE
Definition: hash.h:158
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define LH_OVERFLOW_PAGE
Definition: hash.h:53
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:199
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:274
#define LH_BUCKET_PAGE
Definition: hash.h:54
#define NULL
Definition: c.h:229
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:534
#define PageGetSpecialPointer(page)
Definition: bufpage.h:323
HashPageOpaqueData * HashPageOpaque
Definition: hash.h:85
#define MAXALIGN(LEN)
Definition: c.h:588
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define PageGetSpecialSize(page)
Definition: bufpage.h:297
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:176
uint16 hasho_flag
Definition: hash.h:81
static Datum values[MAXATTR]
Definition: bootstrap.c:163
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2605
#define Int32GetDatum(X)
Definition: postgres.h:485
#define PageIsNew(page)
Definition: bufpage.h:226
#define HashPageGetMeta(page)
Definition: hash.h:266
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
#define elog
Definition: elog.h:219
int Buffer
Definition: buf.h:23
BlockNumber bucket_pages
Definition: pgstatindex.c:119
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:151
Pointer Page
Definition: bufpage.h:74
int64 live_items
Definition: pgstatindex.c:124
Datum pgstatindex ( PG_FUNCTION_ARGS  )

Definition at line 144 of file pgstatindex.c.

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

145 {
146  text *relname = PG_GETARG_TEXT_PP(0);
147  Relation rel;
148  RangeVar *relrv;
149 
150  if (!superuser())
151  ereport(ERROR,
152  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
153  (errmsg("must be superuser to use pgstattuple functions"))));
154 
156  rel = relation_openrv(relrv, AccessShareLock);
157 
158  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
159 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1192
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2913
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:215
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3182
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: c.h:439
static Datum pgstatindex_impl ( Relation  rel,
FunctionCallInfo  fcinfo 
)
static

Definition at line 215 of file pgstatindex.c.

References AccessShareLock, BAS_BULKREAD, BTMetaPageData::btm_level, BTMetaPageData::btm_root, BTMetaPageData::btm_version, BTPageGetMeta, BTPageOpaqueData::btpo_next, buffer, 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, NULL, P_IGNORE, P_ISDELETED, P_ISLEAF, P_NONE, PageGetFreeSpace(), PageGetSpecialPointer, psprintf(), pstrdup(), RBM_NORMAL, ReadBufferExtended(), relation_close(), RELATION_IS_OTHER_TEMP, RelationGetNumberOfBlocks, RelationGetRelationName, ReleaseBuffer(), result, BTIndexStat::root_blkno, SizeOfPageHeaderData, TupleDescGetAttInMetadata(), TYPEFUNC_COMPOSITE, values, and BTIndexStat::version.

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

216 {
217  Datum result;
218  BlockNumber nblocks;
219  BlockNumber blkno;
220  BTIndexStat indexStat;
222 
223  if (!IS_INDEX(rel) || !IS_BTREE(rel))
224  ereport(ERROR,
225  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
226  errmsg("relation \"%s\" is not a btree index",
227  RelationGetRelationName(rel))));
228 
229  /*
230  * Reject attempts to read non-local temporary relations; we would be
231  * likely to get wrong data since we have no visibility into the owning
232  * session's local buffers.
233  */
234  if (RELATION_IS_OTHER_TEMP(rel))
235  ereport(ERROR,
236  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
237  errmsg("cannot access temporary tables of other sessions")));
238 
239  /*
240  * Read metapage
241  */
242  {
243  Buffer buffer = ReadBufferExtended(rel, MAIN_FORKNUM, 0, RBM_NORMAL, bstrategy);
244  Page page = BufferGetPage(buffer);
245  BTMetaPageData *metad = BTPageGetMeta(page);
246 
247  indexStat.version = metad->btm_version;
248  indexStat.level = metad->btm_level;
249  indexStat.root_blkno = metad->btm_root;
250 
251  ReleaseBuffer(buffer);
252  }
253 
254  /* -- init counters -- */
255  indexStat.internal_pages = 0;
256  indexStat.leaf_pages = 0;
257  indexStat.empty_pages = 0;
258  indexStat.deleted_pages = 0;
259 
260  indexStat.max_avail = 0;
261  indexStat.free_space = 0;
262 
263  indexStat.fragments = 0;
264 
265  /*
266  * Scan all blocks except the metapage
267  */
268  nblocks = RelationGetNumberOfBlocks(rel);
269 
270  for (blkno = 1; blkno < nblocks; blkno++)
271  {
272  Buffer buffer;
273  Page page;
274  BTPageOpaque opaque;
275 
277 
278  /* Read and lock buffer */
279  buffer = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
280  LockBuffer(buffer, BUFFER_LOCK_SHARE);
281 
282  page = BufferGetPage(buffer);
283  opaque = (BTPageOpaque) PageGetSpecialPointer(page);
284 
285  /* Determine page type, and update totals */
286 
287  if (P_ISDELETED(opaque))
288  indexStat.deleted_pages++;
289  else if (P_IGNORE(opaque))
290  indexStat.empty_pages++; /* this is the "half dead" state */
291  else if (P_ISLEAF(opaque))
292  {
293  int max_avail;
294 
295  max_avail = BLCKSZ - (BLCKSZ - ((PageHeader) page)->pd_special + SizeOfPageHeaderData);
296  indexStat.max_avail += max_avail;
297  indexStat.free_space += PageGetFreeSpace(page);
298 
299  indexStat.leaf_pages++;
300 
301  /*
302  * If the next leaf is on an earlier block, it means a
303  * fragmentation.
304  */
305  if (opaque->btpo_next != P_NONE && opaque->btpo_next < blkno)
306  indexStat.fragments++;
307  }
308  else
309  indexStat.internal_pages++;
310 
311  /* Unlock and release buffer */
313  ReleaseBuffer(buffer);
314  }
315 
317 
318  /*----------------------------
319  * Build a result tuple
320  *----------------------------
321  */
322  {
324  int j;
325  char *values[10];
326  HeapTuple tuple;
327 
328  /* Build a tuple descriptor for our result type */
329  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
330  elog(ERROR, "return type must be a row type");
331 
332  j = 0;
333  values[j++] = psprintf("%d", indexStat.version);
334  values[j++] = psprintf("%d", indexStat.level);
335  values[j++] = psprintf(INT64_FORMAT,
336  (1 + /* include the metapage in index_size */
337  indexStat.leaf_pages +
338  indexStat.internal_pages +
339  indexStat.deleted_pages +
340  indexStat.empty_pages) * BLCKSZ);
341  values[j++] = psprintf("%u", indexStat.root_blkno);
342  values[j++] = psprintf(INT64_FORMAT, indexStat.internal_pages);
343  values[j++] = psprintf(INT64_FORMAT, indexStat.leaf_pages);
344  values[j++] = psprintf(INT64_FORMAT, indexStat.empty_pages);
345  values[j++] = psprintf(INT64_FORMAT, indexStat.deleted_pages);
346  if (indexStat.max_avail > 0)
347  values[j++] = psprintf("%.2f",
348  100.0 - (double) indexStat.free_space / (double) indexStat.max_avail * 100.0);
349  else
350  values[j++] = pstrdup("NaN");
351  if (indexStat.leaf_pages > 0)
352  values[j++] = psprintf("%.2f",
353  (double) indexStat.fragments / (double) indexStat.leaf_pages * 100.0);
354  else
355  values[j++] = pstrdup("NaN");
356 
358  values);
359 
360  result = HeapTupleGetDatum(tuple);
361  }
362 
363  return result;
364 }
uint64 empty_pages
Definition: pgstatindex.c:87
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:525
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
BlockNumber btpo_next
Definition: nbtree.h:57
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:211
#define P_IGNORE(opaque)
Definition: nbtree.h:181
uint64 fragments
Definition: pgstatindex.c:93
uint32 version
Definition: pgstatindex.c:81
uint32 btm_version
Definition: nbtree.h:99
BlockNumber root_blkno
Definition: pgstatindex.c:83
char * pstrdup(const char *in)
Definition: mcxt.c:1077
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:640
#define P_NONE
Definition: nbtree.h:168
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1260
return result
Definition: formatting.c:1618
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
#define IS_INDEX(r)
Definition: pgstatindex.c:69
#define SizeOfPageHeaderData
Definition: bufpage.h:213
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:67
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:582
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:1115
#define IS_BTREE(r)
Definition: pgstatindex.c:70
#define ERROR
Definition: elog.h:43
uint64 internal_pages
Definition: pgstatindex.c:85
#define BTPageGetMeta(p)
Definition: nbtree.h:106
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define BufferGetPage(buffer)
Definition: bufmgr.h:160
#define ereport(elevel, rest)
Definition: elog.h:122
#define P_ISDELETED(opaque)
Definition: nbtree.h:178
uintptr_t Datum
Definition: postgres.h:372
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:1068
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3546
uint64 free_space
Definition: pgstatindex.c:91
BlockNumber btm_root
Definition: nbtree.h:100
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:199
PageHeaderData * PageHeader
Definition: bufpage.h:162
#define NULL
Definition: c.h:229
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:534
uint64 leaf_pages
Definition: pgstatindex.c:86
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:207
#define PageGetSpecialPointer(page)
Definition: bufpage.h:323
uint32 level
Definition: pgstatindex.c:82
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define INT64_FORMAT
Definition: c.h:315
static Datum values[MAXATTR]
Definition: bootstrap.c:163
int errmsg(const char *fmt,...)
Definition: elog.c:797
uint32 btm_level
Definition: nbtree.h:101
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
uint64 deleted_pages
Definition: pgstatindex.c:88
#define elog
Definition: elog.h:219
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:74
uint64 max_avail
Definition: pgstatindex.c:90
#define P_ISLEAF(opaque)
Definition: nbtree.h:176
Datum pgstatindex_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 169 of file pgstatindex.c.

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

170 {
171  text *relname = PG_GETARG_TEXT_PP(0);
172  Relation rel;
173  RangeVar *relrv;
174 
176  rel = relation_openrv(relrv, AccessShareLock);
177 
178  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
179 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1192
#define AccessShareLock
Definition: lockdefs.h:36
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2913
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:215
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3182
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
Definition: c.h:439
Datum pgstatindexbyid ( PG_FUNCTION_ARGS  )

Definition at line 187 of file pgstatindex.c.

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

188 {
189  Oid relid = PG_GETARG_OID(0);
190  Relation rel;
191 
192  if (!superuser())
193  ereport(ERROR,
194  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
195  (errmsg("must be superuser to use pgstattuple functions"))));
196 
197  rel = relation_open(relid, AccessShareLock);
198 
199  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
200 }
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
unsigned int Oid
Definition: postgres_ext.h:31
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:215
#define ERROR
Definition: elog.h:43
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
int errmsg(const char *fmt,...)
Definition: elog.c:797
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1114
Datum pgstatindexbyid_v1_5 ( PG_FUNCTION_ARGS  )

Definition at line 204 of file pgstatindex.c.

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

205 {
206  Oid relid = PG_GETARG_OID(0);
207  Relation rel;
208 
209  rel = relation_open(relid, AccessShareLock);
210 
211  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
212 }
#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:215
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1114