PostgreSQL Source Code  git master
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/hash.h"
32 #include "access/htup_details.h"
33 #include "access/nbtree.h"
34 #include "access/relation.h"
35 #include "access/table.h"
36 #include "catalog/namespace.h"
37 #include "catalog/pg_am.h"
38 #include "funcapi.h"
39 #include "miscadmin.h"
40 #include "storage/bufmgr.h"
41 #include "storage/lmgr.h"
42 #include "utils/builtins.h"
43 #include "utils/rel.h"
44 #include "utils/varlena.h"
45 
46 
47 /*
48  * Because of backward-compatibility issue, we have decided to have
49  * two types of interfaces, with regclass-type input arg and text-type
50  * input arg, for each function.
51  *
52  * Those functions which have text-type input arg will be deprecated
53  * in the future release.
54  */
61 
67 
69 
70 #define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
71 #define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
72 #define IS_GIN(r) ((r)->rd_rel->relam == GIN_AM_OID)
73 #define IS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID)
74 
75 /* ------------------------------------------------
76  * A structure for a whole btree index statistics
77  * used by pgstatindex().
78  * ------------------------------------------------
79  */
80 typedef struct BTIndexStat
81 {
85 
87  uint64 leaf_pages;
88  uint64 empty_pages;
89  uint64 deleted_pages;
90 
91  uint64 max_avail;
92  uint64 free_space;
93 
94  uint64 fragments;
95 } BTIndexStat;
96 
97 /* ------------------------------------------------
98  * A structure for a whole GIN index statistics
99  * used by pgstatginindex().
100  * ------------------------------------------------
101  */
102 typedef struct GinIndexStat
103 {
105 
108 } GinIndexStat;
109 
110 /* ------------------------------------------------
111  * A structure for a whole HASH index statistics
112  * used by pgstathashindex().
113  * ------------------------------------------------
114  */
115 typedef struct HashIndexStat
116 {
119 
124 
125  int64 live_items;
126  int64 dead_items;
127  uint64 free_space;
128 } HashIndexStat;
129 
130 static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo);
131 static void GetHashPageStats(Page page, HashIndexStat *stats);
132 static void check_relation_relkind(Relation rel);
133 
134 /* ------------------------------------------------------
135  * pgstatindex()
136  *
137  * Usage: SELECT * FROM pgstatindex('t1_pkey');
138  *
139  * The superuser() check here must be kept as the library might be upgraded
140  * without the extension being upgraded, meaning that in pre-1.5 installations
141  * these functions could be called by any user.
142  * ------------------------------------------------------
143  */
144 Datum
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 }
161 
162 /*
163  * As of pgstattuple version 1.5, we no longer need to check if the user
164  * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
165  * Users can then grant access to it based on their policies.
166  *
167  * Otherwise identical to pgstatindex (above).
168  */
169 Datum
171 {
173  Relation rel;
174  RangeVar *relrv;
175 
177  rel = relation_openrv(relrv, AccessShareLock);
178 
179  PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
180 }
181 
182 /*
183  * The superuser() check here must be kept as the library might be upgraded
184  * without the extension being upgraded, meaning that in pre-1.5 installations
185  * these functions could be called by any user.
186  */
187 Datum
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 }
202 
203 /* No need for superuser checks in v1.5, see above */
204 Datum
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 }
214 
215 static Datum
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 }
370 
371 /* --------------------------------------------------------
372  * pg_relpages()
373  *
374  * Get the number of pages of the table/index.
375  *
376  * Usage: SELECT pg_relpages('t1');
377  * SELECT pg_relpages('t1_pkey');
378  *
379  * Must keep superuser() check, see above.
380  * --------------------------------------------------------
381  */
382 Datum
384 {
386  int64 relpages;
387  Relation rel;
388  RangeVar *relrv;
389 
390  if (!superuser())
391  ereport(ERROR,
392  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
393  errmsg("must be superuser to use pgstattuple functions")));
394 
396  rel = relation_openrv(relrv, AccessShareLock);
397 
398  /* only some relkinds have storage */
400 
401  /* note: this will work OK on non-local temp tables */
402 
403  relpages = RelationGetNumberOfBlocks(rel);
404 
406 
407  PG_RETURN_INT64(relpages);
408 }
409 
410 /* No need for superuser checks in v1.5, see above */
411 Datum
413 {
415  int64 relpages;
416  Relation rel;
417  RangeVar *relrv;
418 
420  rel = relation_openrv(relrv, AccessShareLock);
421 
422  /* only some relkinds have storage */
424 
425  /* note: this will work OK on non-local temp tables */
426 
427  relpages = RelationGetNumberOfBlocks(rel);
428 
430 
431  PG_RETURN_INT64(relpages);
432 }
433 
434 /* Must keep superuser() check, see above. */
435 Datum
437 {
438  Oid relid = PG_GETARG_OID(0);
439  int64 relpages;
440  Relation rel;
441 
442  if (!superuser())
443  ereport(ERROR,
444  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
445  errmsg("must be superuser to use pgstattuple functions")));
446 
447  rel = relation_open(relid, AccessShareLock);
448 
449  /* only some relkinds have storage */
451 
452  /* note: this will work OK on non-local temp tables */
453 
454  relpages = RelationGetNumberOfBlocks(rel);
455 
457 
458  PG_RETURN_INT64(relpages);
459 }
460 
461 /* No need for superuser checks in v1.5, see above */
462 Datum
464 {
465  Oid relid = PG_GETARG_OID(0);
466  int64 relpages;
467  Relation rel;
468 
469  rel = relation_open(relid, AccessShareLock);
470 
471  /* only some relkinds have storage */
473 
474  /* note: this will work OK on non-local temp tables */
475 
476  relpages = RelationGetNumberOfBlocks(rel);
477 
479 
480  PG_RETURN_INT64(relpages);
481 }
482 
483 /* ------------------------------------------------------
484  * pgstatginindex()
485  *
486  * Usage: SELECT * FROM pgstatginindex('ginindex');
487  *
488  * Must keep superuser() check, see above.
489  * ------------------------------------------------------
490  */
491 Datum
493 {
494  Oid relid = PG_GETARG_OID(0);
495 
496  if (!superuser())
497  ereport(ERROR,
498  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
499  errmsg("must be superuser to use pgstattuple functions")));
500 
502 }
503 
504 /* No need for superuser checks in v1.5, see above */
505 Datum
507 {
508  Oid relid = PG_GETARG_OID(0);
509 
511 }
512 
513 Datum
515 {
516  Relation rel;
517  Buffer buffer;
518  Page page;
519  GinMetaPageData *metadata;
520  GinIndexStat stats;
521  HeapTuple tuple;
522  TupleDesc tupleDesc;
523  Datum values[3];
524  bool nulls[3] = {false, false, false};
525  Datum result;
526 
527  rel = relation_open(relid, AccessShareLock);
528 
529  if (!IS_INDEX(rel) || !IS_GIN(rel))
530  ereport(ERROR,
531  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
532  errmsg("relation \"%s\" is not a GIN index",
533  RelationGetRelationName(rel))));
534 
535  /*
536  * Reject attempts to read non-local temporary relations; we would be
537  * likely to get wrong data since we have no visibility into the owning
538  * session's local buffers.
539  */
540  if (RELATION_IS_OTHER_TEMP(rel))
541  ereport(ERROR,
542  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
543  errmsg("cannot access temporary indexes of other sessions")));
544 
545  /*
546  * Read metapage
547  */
548  buffer = ReadBuffer(rel, GIN_METAPAGE_BLKNO);
549  LockBuffer(buffer, GIN_SHARE);
550  page = BufferGetPage(buffer);
551  metadata = GinPageGetMeta(page);
552 
553  stats.version = metadata->ginVersion;
554  stats.pending_pages = metadata->nPendingPages;
555  stats.pending_tuples = metadata->nPendingHeapTuples;
556 
557  UnlockReleaseBuffer(buffer);
559 
560  /*
561  * Build a tuple descriptor for our result type
562  */
563  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
564  elog(ERROR, "return type must be a row type");
565 
566  values[0] = Int32GetDatum(stats.version);
567  values[1] = UInt32GetDatum(stats.pending_pages);
568  values[2] = Int64GetDatum(stats.pending_tuples);
569 
570  /*
571  * Build and return the tuple
572  */
573  tuple = heap_form_tuple(tupleDesc, values, nulls);
574  result = HeapTupleGetDatum(tuple);
575 
576  return result;
577 }
578 
579 /* ------------------------------------------------------
580  * pgstathashindex()
581  *
582  * Usage: SELECT * FROM pgstathashindex('hashindex');
583  * ------------------------------------------------------
584  */
585 Datum
587 {
588  Oid relid = PG_GETARG_OID(0);
589  BlockNumber nblocks;
590  BlockNumber blkno;
591  Relation rel;
592  HashIndexStat stats;
593  BufferAccessStrategy bstrategy;
594  HeapTuple tuple;
595  TupleDesc tupleDesc;
596  Datum values[8];
597  bool nulls[8];
598  Buffer metabuf;
599  HashMetaPage metap;
600  float8 free_percent;
601  uint64 total_space;
602 
603  rel = index_open(relid, AccessShareLock);
604 
605  /* index_open() checks that it's an index */
606  if (!IS_HASH(rel))
607  ereport(ERROR,
608  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
609  errmsg("relation \"%s\" is not a hash index",
610  RelationGetRelationName(rel))));
611 
612  /*
613  * Reject attempts to read non-local temporary relations; we would be
614  * likely to get wrong data since we have no visibility into the owning
615  * session's local buffers.
616  */
617  if (RELATION_IS_OTHER_TEMP(rel))
618  ereport(ERROR,
619  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
620  errmsg("cannot access temporary indexes of other sessions")));
621 
622  /* Get the information we need from the metapage. */
623  memset(&stats, 0, sizeof(stats));
625  metap = HashPageGetMeta(BufferGetPage(metabuf));
626  stats.version = metap->hashm_version;
627  stats.space_per_page = metap->hashm_bsize;
628  _hash_relbuf(rel, metabuf);
629 
630  /* Get the current relation length */
631  nblocks = RelationGetNumberOfBlocks(rel);
632 
633  /* prepare access strategy for this index */
634  bstrategy = GetAccessStrategy(BAS_BULKREAD);
635 
636  /* Start from blkno 1 as 0th block is metapage */
637  for (blkno = 1; blkno < nblocks; blkno++)
638  {
639  Buffer buf;
640  Page page;
641 
643 
644  buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL,
645  bstrategy);
647  page = (Page) BufferGetPage(buf);
648 
649  if (PageIsNew(page))
650  stats.unused_pages++;
651  else if (PageGetSpecialSize(page) !=
652  MAXALIGN(sizeof(HashPageOpaqueData)))
653  ereport(ERROR,
654  (errcode(ERRCODE_INDEX_CORRUPTED),
655  errmsg("index \"%s\" contains corrupted page at block %u",
657  BufferGetBlockNumber(buf))));
658  else
659  {
660  HashPageOpaque opaque;
661  int pagetype;
662 
663  opaque = (HashPageOpaque) PageGetSpecialPointer(page);
664  pagetype = opaque->hasho_flag & LH_PAGE_TYPE;
665 
666  if (pagetype == LH_BUCKET_PAGE)
667  {
668  stats.bucket_pages++;
669  GetHashPageStats(page, &stats);
670  }
671  else if (pagetype == LH_OVERFLOW_PAGE)
672  {
673  stats.overflow_pages++;
674  GetHashPageStats(page, &stats);
675  }
676  else if (pagetype == LH_BITMAP_PAGE)
677  stats.bitmap_pages++;
678  else if (pagetype == LH_UNUSED_PAGE)
679  stats.unused_pages++;
680  else
681  ereport(ERROR,
682  (errcode(ERRCODE_INDEX_CORRUPTED),
683  errmsg("unexpected page type 0x%04X in HASH index \"%s\" block %u",
684  opaque->hasho_flag, RelationGetRelationName(rel),
685  BufferGetBlockNumber(buf))));
686  }
687  UnlockReleaseBuffer(buf);
688  }
689 
690  /* Done accessing the index */
692 
693  /* Count unused pages as free space. */
694  stats.free_space += (uint64) stats.unused_pages * stats.space_per_page;
695 
696  /*
697  * Total space available for tuples excludes the metapage and the bitmap
698  * pages.
699  */
700  total_space = (uint64) (nblocks - (stats.bitmap_pages + 1)) *
701  stats.space_per_page;
702 
703  if (total_space == 0)
704  free_percent = 0.0;
705  else
706  free_percent = 100.0 * stats.free_space / total_space;
707 
708  /*
709  * Build a tuple descriptor for our result type
710  */
711  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
712  elog(ERROR, "return type must be a row type");
713 
714  tupleDesc = BlessTupleDesc(tupleDesc);
715 
716  /*
717  * Build and return the tuple
718  */
719  MemSet(nulls, 0, sizeof(nulls));
720  values[0] = Int32GetDatum(stats.version);
721  values[1] = Int64GetDatum((int64) stats.bucket_pages);
722  values[2] = Int64GetDatum((int64) stats.overflow_pages);
723  values[3] = Int64GetDatum((int64) stats.bitmap_pages);
724  values[4] = Int64GetDatum((int64) stats.unused_pages);
725  values[5] = Int64GetDatum(stats.live_items);
726  values[6] = Int64GetDatum(stats.dead_items);
727  values[7] = Float8GetDatum(free_percent);
728  tuple = heap_form_tuple(tupleDesc, values, nulls);
729 
731 }
732 
733 /* -------------------------------------------------
734  * GetHashPageStats()
735  *
736  * Collect statistics of single hash page
737  * -------------------------------------------------
738  */
739 static void
741 {
742  OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
743  int off;
744 
745  /* count live and dead tuples, and free space */
746  for (off = FirstOffsetNumber; off <= maxoff; off++)
747  {
748  ItemId id = PageGetItemId(page, off);
749 
750  if (!ItemIdIsDead(id))
751  stats->live_items++;
752  else
753  stats->dead_items++;
754  }
755  stats->free_space += PageGetExactFreeSpace(page);
756 }
757 
758 /*
759  * check_relation_relkind - convenience routine to check that relation
760  * is of the relkind supported by the callers
761  */
762 static void
764 {
765  if (rel->rd_rel->relkind != RELKIND_RELATION &&
766  rel->rd_rel->relkind != RELKIND_INDEX &&
767  rel->rd_rel->relkind != RELKIND_MATVIEW &&
768  rel->rd_rel->relkind != RELKIND_SEQUENCE &&
769  rel->rd_rel->relkind != RELKIND_TOASTVALUE)
770  ereport(ERROR,
771  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
772  errmsg("\"%s\" is not a table, index, materialized view, sequence, or TOAST table",
773  RelationGetRelationName(rel))));
774 }
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
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 P_IGNORE(opaque)
Definition: nbtree.h:224
uint64 fragments
Definition: pgstatindex.c:94
int64 pending_tuples
Definition: pgstatindex.c:107
uint32 version
Definition: pgstatindex.c:82
uint32 btm_version
Definition: nbtree.h:104
BlockNumber root_blkno
Definition: pgstatindex.c:84
#define LH_META_PAGE
Definition: hash.h:57
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
BlockNumber bitmap_pages
Definition: pgstatindex.c:122
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:514
char * pstrdup(const char *in)
Definition: mcxt.c:1299
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:744
Datum pg_relpagesbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:463
#define P_NONE
Definition: nbtree.h:211
#define AccessShareLock
Definition: lockdefs.h:36
static void check_relation_relkind(Relation rel)
Definition: pgstatindex.c:763
Datum pgstatginindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:506
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
#define MemSet(start, val, len)
Definition: c.h:1008
uint32 BlockNumber
Definition: block.h:31
Datum pgstathashindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:586
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3784
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:52
uint64 free_space
Definition: pgstatindex.c:127
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
Datum pgstatindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:170
#define IS_INDEX(r)
Definition: pgstatindex.c:70
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:69
#define SizeOfPageHeaderData
Definition: bufpage.h:216
Form_pg_class rd_rel
Definition: rel.h:110
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
BlockNumber unused_pages
Definition: pgstatindex.c:123
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:71
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:900
signed int int32
Definition: c.h:429
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1706
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2146
int32 space_per_page
Definition: pgstatindex.c:118
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define LH_UNUSED_PAGE
Definition: hash.h:53
uint16 OffsetNumber
Definition: off.h:24
Datum pg_relpagesbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:436
Datum pgstatindexbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:188
#define LH_PAGE_TYPE
Definition: hash.h:63
#define HASH_READ
Definition: hash.h:337
int64 nPendingHeapTuples
Definition: ginblock.h:75
struct GinIndexStat GinIndexStat
#define IS_BTREE(r)
Definition: pgstatindex.c:71
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:216
int64 dead_items
Definition: pgstatindex.c:126
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3807
#define ERROR
Definition: elog.h:46
double float8
Definition: c.h:565
uint64 internal_pages
Definition: pgstatindex.c:86
struct HashIndexStat HashIndexStat
Datum pgstatindexbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
static void GetHashPageStats(Page page, HashIndexStat *stats)
Definition: pgstatindex.c:740
uint32 hashm_version
Definition: hash.h:245
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2082
#define BTPageGetMeta(p)
Definition: nbtree.h:119
static char * buf
Definition: pg_test_fsync.c:68
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define FirstOffsetNumber
Definition: off.h:27
#define RelationGetRelationName(relation)
Definition: rel.h:491
unsigned int uint32
Definition: c.h:441
#define UInt32GetDatum(X)
Definition: postgres.h:537
#define IS_HASH(r)
Definition: pgstatindex.c:73
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1697
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define P_ISDELETED(opaque)
Definition: nbtree.h:221
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3695
#define GIN_SHARE
Definition: gin_private.h:49
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
BlockNumber pending_pages
Definition: pgstatindex.c:106
Datum pgstatginindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:492
uint16 hashm_bsize
Definition: hash.h:248
Datum pgstatindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:145
#define IS_GIN(r)
Definition: pgstatindex.c:72
#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
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2097
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4023
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
uint64 free_space
Definition: pgstatindex.c:92
BlockNumber btm_root
Definition: nbtree.h:105
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:213
PG_FUNCTION_INFO_V1(pgstatindex)
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
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:600
uint64 leaf_pages
Definition: pgstatindex.c:87
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:697
#define PageGetSpecialPointer(page)
Definition: bufpage.h:326
HashPageOpaqueData * HashPageOpaque
Definition: hash.h:86
Datum pg_relpages_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:412
#define MAXALIGN(LEN)
Definition: c.h:757
uint32 level
Definition: pgstatindex.c:83
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
#define PageGetSpecialSize(page)
Definition: bufpage.h:300
int32 ginVersion
Definition: ginblock.h:100
#define INT64_FORMAT
Definition: c.h:483
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:951
uint16 hasho_flag
Definition: hash.h:82
static Datum values[MAXATTR]
Definition: bootstrap.c:166
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2758
#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
uint32 btm_level
Definition: nbtree.h:106
#define elog(elevel,...)
Definition: elog.h:232
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
Definition: c.h:621
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:102
uint64 deleted_pages
Definition: pgstatindex.c:89
#define GinPageGetMeta(p)
Definition: ginblock.h:105
Datum pg_relpages(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:383
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
uint64 max_avail
Definition: pgstatindex.c:91
int64 live_items
Definition: pgstatindex.c:125
BlockNumber nPendingPages
Definition: ginblock.h:74
#define P_ISLEAF(opaque)
Definition: nbtree.h:219