PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pgstatindex.c
Go to the documentation of this file.
1 /*
2  * contrib/pgstattuple/pgstatindex.c
3  *
4  *
5  * pgstatindex
6  *
7  * Copyright (c) 2006 Satoshi Nagayasu <nagayasus@nttdata.co.jp>
8  *
9  * Permission to use, copy, modify, and distribute this software and
10  * its documentation for any purpose, without fee, and without a
11  * written agreement is hereby granted, provided that the above
12  * copyright notice and this paragraph and the following two
13  * paragraphs appear in all copies.
14  *
15  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
16  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
17  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
18  * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
19  * OF THE POSSIBILITY OF SUCH DAMAGE.
20  *
21  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
24  * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
25  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
26  */
27 
28 #include "postgres.h"
29 
30 #include "access/gin_private.h"
31 #include "access/heapam.h"
32 #include "access/hash.h"
33 #include "access/htup_details.h"
34 #include "access/nbtree.h"
35 #include "catalog/namespace.h"
36 #include "catalog/pg_am.h"
37 #include "funcapi.h"
38 #include "miscadmin.h"
39 #include "storage/bufmgr.h"
40 #include "storage/lmgr.h"
41 #include "utils/builtins.h"
42 #include "utils/rel.h"
43 #include "utils/varlena.h"
44 
45 
46 /*
47  * Because of backward-compatibility issue, we have decided to have
48  * two types of interfaces, with regclass-type input arg and text-type
49  * input arg, for each function.
50  *
51  * Those functions which have text-type input arg will be deprecated
52  * in the future release.
53  */
60 
66 
68 
69 #define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
70 #define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
71 #define IS_GIN(r) ((r)->rd_rel->relam == GIN_AM_OID)
72 #define IS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID)
73 
74 /* ------------------------------------------------
75  * A structure for a whole btree index statistics
76  * used by pgstatindex().
77  * ------------------------------------------------
78  */
79 typedef struct BTIndexStat
80 {
84 
86  uint64 leaf_pages;
87  uint64 empty_pages;
88  uint64 deleted_pages;
89 
90  uint64 max_avail;
91  uint64 free_space;
92 
93  uint64 fragments;
94 } BTIndexStat;
95 
96 /* ------------------------------------------------
97  * A structure for a whole GIN index statistics
98  * used by pgstatginindex().
99  * ------------------------------------------------
100  */
101 typedef struct GinIndexStat
102 {
104 
107 } GinIndexStat;
108 
109 /* ------------------------------------------------
110  * A structure for a whole HASH index statistics
111  * used by pgstathashindex().
112  * ------------------------------------------------
113  */
114 typedef struct HashIndexStat
115 {
118 
123 
124  int64 live_items;
125  int64 dead_items;
126  uint64 free_space;
127 } HashIndexStat;
128 
129 static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo);
130 static void GetHashPageStats(Page page, HashIndexStat *stats);
131 static void check_relation_relkind(Relation rel);
132 
133 /* ------------------------------------------------------
134  * pgstatindex()
135  *
136  * Usage: SELECT * FROM pgstatindex('t1_pkey');
137  *
138  * The superuser() check here must be kept as the library might be upgraded
139  * without the extension being upgraded, meaning that in pre-1.5 installations
140  * these functions could be called by any user.
141  * ------------------------------------------------------
142  */
143 Datum
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 }
160 
161 /*
162  * As of pgstattuple version 1.5, we no longer need to check if the user
163  * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
164  * Users can then grant access to it based on their policies.
165  *
166  * Otherwise identical to pgstatindex (above).
167  */
168 Datum
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 }
180 
181 /*
182  * The superuser() check here must be kept as the library might be upgraded
183  * without the extension being upgraded, meaning that in pre-1.5 installations
184  * these functions could be called by any user.
185  */
186 Datum
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 }
201 
202 /* No need for superuser checks in v1.5, see above */
203 Datum
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 }
213 
214 static Datum
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 }
365 
366 /* --------------------------------------------------------
367  * pg_relpages()
368  *
369  * Get the number of pages of the table/index.
370  *
371  * Usage: SELECT pg_relpages('t1');
372  * SELECT pg_relpages('t1_pkey');
373  *
374  * Must keep superuser() check, see above.
375  * --------------------------------------------------------
376  */
377 Datum
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 }
404 
405 /* No need for superuser checks in v1.5, see above */
406 Datum
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 }
428 
429 /* Must keep superuser() check, see above. */
430 Datum
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 }
455 
456 /* No need for superuser checks in v1.5, see above */
457 Datum
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 }
477 
478 /* ------------------------------------------------------
479  * pgstatginindex()
480  *
481  * Usage: SELECT * FROM pgstatginindex('ginindex');
482  *
483  * Must keep superuser() check, see above.
484  * ------------------------------------------------------
485  */
486 Datum
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 }
498 
499 /* No need for superuser checks in v1.5, see above */
500 Datum
502 {
503  Oid relid = PG_GETARG_OID(0);
504 
506 }
507 
508 Datum
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 }
573 
574 /* ------------------------------------------------------
575  * pgstathashindex()
576  *
577  * Usage: SELECT * FROM pgstathashindex('hashindex');
578  * ------------------------------------------------------
579  */
580 Datum
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 }
727 
728 /* -------------------------------------------------
729  * GetHashPageStatis()
730  *
731  * Collect statistics of single hash page
732  * -------------------------------------------------
733  */
734 static void
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 }
752 
753 /*
754  * check_relation_relkind - convenience routine to check that relation
755  * is of the relkind supported by the callers
756  */
757 static void
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 }
uint64 empty_pages
Definition: pgstatindex.c:87
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:525
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1192
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:87
BlockNumber btpo_next
Definition: nbtree.h:57
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 P_IGNORE(opaque)
Definition: nbtree.h:181
uint64 fragments
Definition: pgstatindex.c:93
int64 pending_tuples
Definition: pgstatindex.c:106
uint32 version
Definition: pgstatindex.c:81
uint32 btm_version
Definition: nbtree.h:99
BlockNumber root_blkno
Definition: pgstatindex.c:83
#define LH_META_PAGE
Definition: hash.h:56
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
BlockNumber bitmap_pages
Definition: pgstatindex.c:121
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:509
char * pstrdup(const char *in)
Definition: mcxt.c:1077
struct BTIndexStat BTIndexStat
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
Datum pg_relpagesbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:458
#define RELKIND_MATVIEW
Definition: pg_class.h:165
#define P_NONE
Definition: nbtree.h:168
#define AccessShareLock
Definition: lockdefs.h:36
static void check_relation_relkind(Relation rel)
Definition: pgstatindex.c:758
Datum pgstatginindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:501
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
#define MemSet(start, val, len)
Definition: c.h:857
return result
Definition: formatting.c:1632
uint32 BlockNumber
Definition: block.h:31
Datum pgstathashindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:581
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:50
uint64 free_space
Definition: pgstatindex.c:126
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2980
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
Datum pgstatindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:169
#define IS_INDEX(r)
Definition: pgstatindex.c:69
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:78
#define SizeOfPageHeaderData
Definition: bufpage.h:213
Form_pg_class rd_rel
Definition: rel.h:114
unsigned int Oid
Definition: postgres_ext.h:31
#define ItemIdIsDead(itemId)
Definition: itemid.h:112
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:354
BlockNumber unused_pages
Definition: pgstatindex.c:122
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:67
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:582
signed int int32
Definition: c.h:256
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1815
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:1115
int32 space_per_page
Definition: pgstatindex.c:117
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define LH_UNUSED_PAGE
Definition: hash.h:52
uint16 OffsetNumber
Definition: off.h:24
Datum pg_relpagesbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:431
Datum pgstatindexbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:187
#define LH_PAGE_TYPE
Definition: hash.h:62
#define HASH_READ
Definition: hash.h:283
int64 nPendingHeapTuples
Definition: ginblock.h:73
struct GinIndexStat GinIndexStat
#define IS_BTREE(r)
Definition: pgstatindex.c:70
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:215
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
uint64 internal_pages
Definition: pgstatindex.c:85
struct HashIndexStat HashIndexStat
Datum pgstatindexbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:204
static void GetHashPageStats(Page page, HashIndexStat *stats)
Definition: pgstatindex.c:735
uint32 hashm_version
Definition: hash.h:206
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
#define BTPageGetMeta(p)
Definition: nbtree.h:106
static char * buf
Definition: pg_test_fsync.c:66
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define FirstOffsetNumber
Definition: off.h:27
#define RelationGetRelationName(relation)
Definition: rel.h:437
unsigned int uint32
Definition: c.h:268
#define UInt32GetDatum(X)
Definition: postgres.h:499
#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
#define P_ISDELETED(opaque)
Definition: nbtree.h:178
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3189
#define GIN_SHARE
Definition: gin_private.h:44
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:232
BlockNumber pending_pages
Definition: pgstatindex.c:105
Datum pgstatginindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:487
uint16 hashm_bsize
Definition: hash.h:209
Datum pgstatindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:144
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
#define IS_GIN(r)
Definition: pgstatindex.c:71
#define HASH_METAPAGE
Definition: hash.h:159
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
#define LH_OVERFLOW_PAGE
Definition: hash.h:53
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
PG_FUNCTION_INFO_V1(pgstatindex)
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:274
#define LH_BUCKET_PAGE
Definition: hash.h:54
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:211
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:594
#define PageGetSpecialPointer(page)
Definition: bufpage.h:323
HashPageOpaqueData * HashPageOpaque
Definition: hash.h:85
Datum pg_relpages_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:407
#define MAXALIGN(LEN)
Definition: c.h:588
uint32 level
Definition: pgstatindex.c:82
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define PageGetSpecialSize(page)
Definition: bufpage.h:297
int32 ginVersion
Definition: ginblock.h:98
#define INT64_FORMAT
Definition: c.h:315
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:176
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:633
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:267
int errmsg(const char *fmt,...)
Definition: elog.c:797
uint32 btm_level
Definition: nbtree.h:101
#define RELKIND_INDEX
Definition: pg_class.h:161
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:88
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1114
Definition: c.h:439
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
uint64 deleted_pages
Definition: pgstatindex.c:88
#define GinPageGetMeta(p)
Definition: ginblock.h:103
#define elog
Definition: elog.h:219
Datum pg_relpages(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:378
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
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
uint64 max_avail
Definition: pgstatindex.c:90
int64 live_items
Definition: pgstatindex.c:124
BlockNumber nPendingPages
Definition: ginblock.h:72
#define P_ISLEAF(opaque)
Definition: nbtree.h:176