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;
96 
97 /* ------------------------------------------------
98  * A structure for a whole GIN index statistics
99  * used by pgstatginindex().
100  * ------------------------------------------------
101  */
102 typedef struct GinIndexStat
103 {
105 
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;
129 
130 static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo);
131 static int64 pg_relpages_impl(Relation rel);
132 static void GetHashPageStats(Page page, HashIndexStat *stats);
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  * A !indisready index could lead to ERRCODE_DATA_CORRUPTED later, so exit
242  * early. We're capable of assessing an indisready&&!indisvalid index,
243  * but the results could be confusing. For example, the index's size
244  * could be too low for a valid index of the table.
245  */
246  if (!rel->rd_index->indisvalid)
247  ereport(ERROR,
248  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
249  errmsg("index \"%s\" is not valid",
250  RelationGetRelationName(rel))));
251 
252  /*
253  * Read metapage
254  */
255  {
256  Buffer buffer = ReadBufferExtended(rel, MAIN_FORKNUM, 0, RBM_NORMAL, bstrategy);
257  Page page = BufferGetPage(buffer);
258  BTMetaPageData *metad = BTPageGetMeta(page);
259 
260  indexStat.version = metad->btm_version;
261  indexStat.level = metad->btm_level;
262  indexStat.root_blkno = metad->btm_root;
263 
264  ReleaseBuffer(buffer);
265  }
266 
267  /* -- init counters -- */
268  indexStat.internal_pages = 0;
269  indexStat.leaf_pages = 0;
270  indexStat.empty_pages = 0;
271  indexStat.deleted_pages = 0;
272 
273  indexStat.max_avail = 0;
274  indexStat.free_space = 0;
275 
276  indexStat.fragments = 0;
277 
278  /*
279  * Scan all blocks except the metapage
280  */
281  nblocks = RelationGetNumberOfBlocks(rel);
282 
283  for (blkno = 1; blkno < nblocks; blkno++)
284  {
285  Buffer buffer;
286  Page page;
287  BTPageOpaque opaque;
288 
290 
291  /* Read and lock buffer */
292  buffer = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
293  LockBuffer(buffer, BUFFER_LOCK_SHARE);
294 
295  page = BufferGetPage(buffer);
296  opaque = BTPageGetOpaque(page);
297 
298  /*
299  * Determine page type, and update totals.
300  *
301  * Note that we arbitrarily bucket deleted pages together without
302  * considering if they're leaf pages or internal pages.
303  */
304  if (P_ISDELETED(opaque))
305  indexStat.deleted_pages++;
306  else if (P_IGNORE(opaque))
307  indexStat.empty_pages++; /* this is the "half dead" state */
308  else if (P_ISLEAF(opaque))
309  {
310  int max_avail;
311 
312  max_avail = BLCKSZ - (BLCKSZ - ((PageHeader) page)->pd_special + SizeOfPageHeaderData);
313  indexStat.max_avail += max_avail;
314  indexStat.free_space += PageGetFreeSpace(page);
315 
316  indexStat.leaf_pages++;
317 
318  /*
319  * If the next leaf is on an earlier block, it means a
320  * fragmentation.
321  */
322  if (opaque->btpo_next != P_NONE && opaque->btpo_next < blkno)
323  indexStat.fragments++;
324  }
325  else
326  indexStat.internal_pages++;
327 
328  /* Unlock and release buffer */
330  ReleaseBuffer(buffer);
331  }
332 
334 
335  /*----------------------------
336  * Build a result tuple
337  *----------------------------
338  */
339  {
340  TupleDesc tupleDesc;
341  int j;
342  char *values[10];
343  HeapTuple tuple;
344 
345  /* Build a tuple descriptor for our result type */
346  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
347  elog(ERROR, "return type must be a row type");
348 
349  j = 0;
350  values[j++] = psprintf("%d", indexStat.version);
351  values[j++] = psprintf("%d", indexStat.level);
353  (1 + /* include the metapage in index_size */
354  indexStat.leaf_pages +
355  indexStat.internal_pages +
356  indexStat.deleted_pages +
357  indexStat.empty_pages) * BLCKSZ);
358  values[j++] = psprintf("%u", indexStat.root_blkno);
359  values[j++] = psprintf(INT64_FORMAT, indexStat.internal_pages);
360  values[j++] = psprintf(INT64_FORMAT, indexStat.leaf_pages);
361  values[j++] = psprintf(INT64_FORMAT, indexStat.empty_pages);
362  values[j++] = psprintf(INT64_FORMAT, indexStat.deleted_pages);
363  if (indexStat.max_avail > 0)
364  values[j++] = psprintf("%.2f",
365  100.0 - (double) indexStat.free_space / (double) indexStat.max_avail * 100.0);
366  else
367  values[j++] = pstrdup("NaN");
368  if (indexStat.leaf_pages > 0)
369  values[j++] = psprintf("%.2f",
370  (double) indexStat.fragments / (double) indexStat.leaf_pages * 100.0);
371  else
372  values[j++] = pstrdup("NaN");
373 
375  values);
376 
377  result = HeapTupleGetDatum(tuple);
378  }
379 
380  return result;
381 }
382 
383 /* --------------------------------------------------------
384  * pg_relpages()
385  *
386  * Get the number of pages of the table/index.
387  *
388  * Usage: SELECT pg_relpages('t1');
389  * SELECT pg_relpages('t1_pkey');
390  *
391  * Must keep superuser() check, see above.
392  * --------------------------------------------------------
393  */
394 Datum
396 {
398  Relation rel;
399  RangeVar *relrv;
400 
401  if (!superuser())
402  ereport(ERROR,
403  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
404  errmsg("must be superuser to use pgstattuple functions")));
405 
407  rel = relation_openrv(relrv, AccessShareLock);
408 
410 }
411 
412 /* No need for superuser checks in v1.5, see above */
413 Datum
415 {
417  Relation rel;
418  RangeVar *relrv;
419 
421  rel = relation_openrv(relrv, AccessShareLock);
422 
424 }
425 
426 /* Must keep superuser() check, see above. */
427 Datum
429 {
430  Oid relid = PG_GETARG_OID(0);
431  Relation rel;
432 
433  if (!superuser())
434  ereport(ERROR,
435  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
436  errmsg("must be superuser to use pgstattuple functions")));
437 
438  rel = relation_open(relid, AccessShareLock);
439 
441 }
442 
443 /* No need for superuser checks in v1.5, see above */
444 Datum
446 {
447  Oid relid = PG_GETARG_OID(0);
448  Relation rel;
449 
450  rel = relation_open(relid, AccessShareLock);
451 
453 }
454 
455 static int64
457 {
458  int64 relpages;
459 
460  if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
461  ereport(ERROR,
462  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
463  errmsg("cannot get page count of relation \"%s\"",
465  errdetail_relkind_not_supported(rel->rd_rel->relkind)));
466 
467  /* note: this will work OK on non-local temp tables */
468 
469  relpages = RelationGetNumberOfBlocks(rel);
470 
472 
473  return relpages;
474 }
475 
476 /* ------------------------------------------------------
477  * pgstatginindex()
478  *
479  * Usage: SELECT * FROM pgstatginindex('ginindex');
480  *
481  * Must keep superuser() check, see above.
482  * ------------------------------------------------------
483  */
484 Datum
486 {
487  Oid relid = PG_GETARG_OID(0);
488 
489  if (!superuser())
490  ereport(ERROR,
491  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
492  errmsg("must be superuser to use pgstattuple functions")));
493 
495 }
496 
497 /* No need for superuser checks in v1.5, see above */
498 Datum
500 {
501  Oid relid = PG_GETARG_OID(0);
502 
504 }
505 
506 Datum
508 {
509  Relation rel;
510  Buffer buffer;
511  Page page;
512  GinMetaPageData *metadata;
513  GinIndexStat stats;
514  HeapTuple tuple;
515  TupleDesc tupleDesc;
516  Datum values[3];
517  bool nulls[3] = {false, false, false};
518  Datum result;
519 
520  rel = relation_open(relid, AccessShareLock);
521 
522  if (!IS_INDEX(rel) || !IS_GIN(rel))
523  ereport(ERROR,
524  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
525  errmsg("relation \"%s\" is not a GIN index",
526  RelationGetRelationName(rel))));
527 
528  /*
529  * Reject attempts to read non-local temporary relations; we would be
530  * likely to get wrong data since we have no visibility into the owning
531  * session's local buffers.
532  */
533  if (RELATION_IS_OTHER_TEMP(rel))
534  ereport(ERROR,
535  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
536  errmsg("cannot access temporary indexes of other sessions")));
537 
538  /* see pgstatindex_impl */
539  if (!rel->rd_index->indisvalid)
540  ereport(ERROR,
541  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
542  errmsg("index \"%s\" is not valid",
543  RelationGetRelationName(rel))));
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] = {0};
598  Buffer metabuf;
599  HashMetaPage metap;
600  float8 free_percent;
601  uint64 total_space;
602 
603  rel = relation_open(relid, AccessShareLock);
604 
605  if (!IS_INDEX(rel) || !IS_HASH(rel))
606  ereport(ERROR,
607  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
608  errmsg("relation \"%s\" is not a hash index",
609  RelationGetRelationName(rel))));
610 
611  /*
612  * Reject attempts to read non-local temporary relations; we would be
613  * likely to get wrong data since we have no visibility into the owning
614  * session's local buffers.
615  */
616  if (RELATION_IS_OTHER_TEMP(rel))
617  ereport(ERROR,
618  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
619  errmsg("cannot access temporary indexes of other sessions")));
620 
621  /* see pgstatindex_impl */
622  if (!rel->rd_index->indisvalid)
623  ereport(ERROR,
624  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
625  errmsg("index \"%s\" is not valid",
626  RelationGetRelationName(rel))));
627 
628  /* Get the information we need from the metapage. */
629  memset(&stats, 0, sizeof(stats));
631  metap = HashPageGetMeta(BufferGetPage(metabuf));
632  stats.version = metap->hashm_version;
633  stats.space_per_page = metap->hashm_bsize;
634  _hash_relbuf(rel, metabuf);
635 
636  /* Get the current relation length */
637  nblocks = RelationGetNumberOfBlocks(rel);
638 
639  /* prepare access strategy for this index */
640  bstrategy = GetAccessStrategy(BAS_BULKREAD);
641 
642  /* Start from blkno 1 as 0th block is metapage */
643  for (blkno = 1; blkno < nblocks; blkno++)
644  {
645  Buffer buf;
646  Page page;
647 
649 
651  bstrategy);
653  page = (Page) BufferGetPage(buf);
654 
655  if (PageIsNew(page))
656  stats.unused_pages++;
657  else if (PageGetSpecialSize(page) !=
658  MAXALIGN(sizeof(HashPageOpaqueData)))
659  ereport(ERROR,
660  (errcode(ERRCODE_INDEX_CORRUPTED),
661  errmsg("index \"%s\" contains corrupted page at block %u",
664  else
665  {
666  HashPageOpaque opaque;
667  int pagetype;
668 
669  opaque = HashPageGetOpaque(page);
670  pagetype = opaque->hasho_flag & LH_PAGE_TYPE;
671 
672  if (pagetype == LH_BUCKET_PAGE)
673  {
674  stats.bucket_pages++;
675  GetHashPageStats(page, &stats);
676  }
677  else if (pagetype == LH_OVERFLOW_PAGE)
678  {
679  stats.overflow_pages++;
680  GetHashPageStats(page, &stats);
681  }
682  else if (pagetype == LH_BITMAP_PAGE)
683  stats.bitmap_pages++;
684  else if (pagetype == LH_UNUSED_PAGE)
685  stats.unused_pages++;
686  else
687  ereport(ERROR,
688  (errcode(ERRCODE_INDEX_CORRUPTED),
689  errmsg("unexpected page type 0x%04X in HASH index \"%s\" block %u",
690  opaque->hasho_flag, RelationGetRelationName(rel),
692  }
694  }
695 
696  /* Done accessing the index */
698 
699  /* Count unused pages as free space. */
700  stats.free_space += (uint64) stats.unused_pages * stats.space_per_page;
701 
702  /*
703  * Total space available for tuples excludes the metapage and the bitmap
704  * pages.
705  */
706  total_space = (uint64) (nblocks - (stats.bitmap_pages + 1)) *
707  stats.space_per_page;
708 
709  if (total_space == 0)
710  free_percent = 0.0;
711  else
712  free_percent = 100.0 * stats.free_space / total_space;
713 
714  /*
715  * Build a tuple descriptor for our result type
716  */
717  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
718  elog(ERROR, "return type must be a row type");
719 
720  tupleDesc = BlessTupleDesc(tupleDesc);
721 
722  /*
723  * Build and return the tuple
724  */
725  values[0] = Int32GetDatum(stats.version);
726  values[1] = Int64GetDatum((int64) stats.bucket_pages);
727  values[2] = Int64GetDatum((int64) stats.overflow_pages);
728  values[3] = Int64GetDatum((int64) stats.bitmap_pages);
729  values[4] = Int64GetDatum((int64) stats.unused_pages);
730  values[5] = Int64GetDatum(stats.live_items);
731  values[6] = Int64GetDatum(stats.dead_items);
732  values[7] = Float8GetDatum(free_percent);
733  tuple = heap_form_tuple(tupleDesc, values, nulls);
734 
736 }
737 
738 /* -------------------------------------------------
739  * GetHashPageStats()
740  *
741  * Collect statistics of single hash page
742  * -------------------------------------------------
743  */
744 static void
746 {
747  OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
748  int off;
749 
750  /* count live and dead tuples, and free space */
751  for (off = FirstOffsetNumber; off <= maxoff; off++)
752  {
753  ItemId id = PageGetItemId(page, off);
754 
755  if (!ItemIdIsDead(id))
756  stats->live_items++;
757  else
758  stats->dead_items++;
759  }
760  stats->free_space += PageGetExactFreeSpace(page);
761 }
uint32 BlockNumber
Definition: block.h:31
static Datum values[MAXATTR]
Definition: bootstrap.c:152
int Buffer
Definition: buf.h:23
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:3667
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4850
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4867
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:5085
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:792
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:745
@ BAS_BULKREAD
Definition: bufmgr.h:36
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:197
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:198
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:281
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:408
@ RBM_NORMAL
Definition: bufmgr.h:45
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:958
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:907
PageHeaderData * PageHeader
Definition: bufpage.h:170
Pointer Page
Definition: bufpage.h:78
#define SizeOfPageHeaderData
Definition: bufpage.h:213
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:240
static bool PageIsNew(Page page)
Definition: bufpage.h:230
static OffsetNumber PageGetMaxOffsetNumber(Page page)
Definition: bufpage.h:369
static uint16 PageGetSpecialSize(Page page)
Definition: bufpage.h:313
unsigned int uint32
Definition: c.h:506
#define MAXALIGN(LEN)
Definition: c.h:811
signed int int32
Definition: c.h:494
#define INT64_FORMAT
Definition: c.h:548
double float8
Definition: c.h:630
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2158
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2222
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2173
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1816
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:541
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
#define GIN_SHARE
Definition: gin_private.h:50
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:51
#define GinPageGetMeta(p)
Definition: ginblock.h:104
#define HashPageGetOpaque(page)
Definition: hash.h:88
#define LH_BUCKET_PAGE
Definition: hash.h:55
#define LH_UNUSED_PAGE
Definition: hash.h:53
#define LH_META_PAGE
Definition: hash.h:57
#define HashPageGetMeta(page)
Definition: hash.h:323
#define HASH_READ
Definition: hash.h:339
#define HASH_METAPAGE
Definition: hash.h:198
#define LH_PAGE_TYPE
Definition: hash.h:63
#define LH_BITMAP_PAGE
Definition: hash.h:56
#define LH_OVERFLOW_PAGE
Definition: hash.h:54
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:266
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:70
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
int j
Definition: isn.c:74
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define AccessShareLock
Definition: lockdefs.h:36
char * pstrdup(const char *in)
Definition: mcxt.c:1695
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3539
#define BTPageGetMeta(p)
Definition: nbtree.h:121
#define P_ISLEAF(opaque)
Definition: nbtree.h:220
#define BTPageGetOpaque(page)
Definition: nbtree.h:73
#define P_ISDELETED(opaque)
Definition: nbtree.h:222
#define P_NONE
Definition: nbtree.h:212
#define P_IGNORE(opaque)
Definition: nbtree.h:225
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
NameData relname
Definition: pg_class.h:38
static char * buf
Definition: pg_test_fsync.c:73
Datum pgstatindexbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:188
Datum pgstatindexbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:205
Datum pgstatindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:170
#define IS_BTREE(r)
Definition: pgstatindex.c:71
#define IS_HASH(r)
Definition: pgstatindex.c:73
static void GetHashPageStats(Page page, HashIndexStat *stats)
Definition: pgstatindex.c:745
static int64 pg_relpages_impl(Relation rel)
Definition: pgstatindex.c:456
Datum pgstatginindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:499
Datum pg_relpagesbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:428
Datum pg_relpages(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:395
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:507
Datum pg_relpages_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:414
struct HashIndexStat HashIndexStat
#define IS_INDEX(r)
Definition: pgstatindex.c:70
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:216
Datum pg_relpagesbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:445
PG_FUNCTION_INFO_V1(pgstatindex)
Datum pgstatginindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:485
#define IS_GIN(r)
Definition: pgstatindex.c:72
struct GinIndexStat GinIndexStat
Datum pgstathashindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:586
struct BTIndexStat BTIndexStat
Datum pgstatindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:145
uintptr_t Datum
Definition: postgres.h:64
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:232
unsigned int Oid
Definition: postgres_ext.h:31
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define RelationGetRelationName(relation)
Definition: rel.h:539
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:658
@ MAIN_FORKNUM
Definition: relpath.h:50
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:137
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
uint64 max_avail
Definition: pgstatindex.c:91
uint32 level
Definition: pgstatindex.c:83
uint64 empty_pages
Definition: pgstatindex.c:88
uint64 deleted_pages
Definition: pgstatindex.c:89
uint64 internal_pages
Definition: pgstatindex.c:86
uint64 leaf_pages
Definition: pgstatindex.c:87
uint32 version
Definition: pgstatindex.c:82
uint64 fragments
Definition: pgstatindex.c:94
BlockNumber root_blkno
Definition: pgstatindex.c:84
uint64 free_space
Definition: pgstatindex.c:92
uint32 btm_level
Definition: nbtree.h:108
uint32 btm_version
Definition: nbtree.h:106
BlockNumber btm_root
Definition: nbtree.h:107
BlockNumber btpo_next
Definition: nbtree.h:65
BlockNumber pending_pages
Definition: pgstatindex.c:106
int64 pending_tuples
Definition: pgstatindex.c:107
int32 ginVersion
Definition: ginblock.h:99
BlockNumber nPendingPages
Definition: ginblock.h:73
int64 nPendingHeapTuples
Definition: ginblock.h:74
BlockNumber bitmap_pages
Definition: pgstatindex.c:122
BlockNumber overflow_pages
Definition: pgstatindex.c:121
BlockNumber bucket_pages
Definition: pgstatindex.c:120
BlockNumber unused_pages
Definition: pgstatindex.c:123
uint64 free_space
Definition: pgstatindex.c:127
int64 dead_items
Definition: pgstatindex.c:126
int32 space_per_page
Definition: pgstatindex.c:118
int64 live_items
Definition: pgstatindex.c:125
uint32 hashm_version
Definition: hash.h:247
uint16 hashm_bsize
Definition: hash.h:250
uint16 hasho_flag
Definition: hash.h:82
Form_pg_index rd_index
Definition: rel.h:192
Form_pg_class rd_rel
Definition: rel.h:111
Definition: c.h:687
bool superuser(void)
Definition: superuser.c:46
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3399