PostgreSQL Source Code  git master
pgstattuple.c
Go to the documentation of this file.
1 /*
2  * contrib/pgstattuple/pgstattuple.c
3  *
4  * Copyright (c) 2001,2002 Tatsuo Ishii
5  *
6  * Permission to use, copy, modify, and distribute this software and
7  * its documentation for any purpose, without fee, and without a
8  * written agreement is hereby granted, provided that the above
9  * copyright notice and this paragraph and the following two
10  * paragraphs appear in all copies.
11  *
12  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
13  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
14  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
15  * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
16  * OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
21  * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
22  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  */
24 
25 #include "postgres.h"
26 
27 #include "access/gist_private.h"
28 #include "access/hash.h"
29 #include "access/heapam.h"
30 #include "access/nbtree.h"
31 #include "access/relscan.h"
32 #include "access/tableam.h"
33 #include "catalog/namespace.h"
34 #include "catalog/pg_am_d.h"
35 #include "funcapi.h"
36 #include "miscadmin.h"
37 #include "storage/bufmgr.h"
38 #include "storage/lmgr.h"
39 #include "utils/builtins.h"
40 #include "utils/varlena.h"
41 
43 
48 
49 /*
50  * struct pgstattuple_type
51  *
52  * tuple_percent, dead_tuple_percent and free_percent are computable,
53  * so not defined here.
54  */
55 typedef struct pgstattuple_type
56 {
57  uint64 table_len;
58  uint64 tuple_count;
59  uint64 tuple_len;
62  uint64 free_space; /* free/reusable space in bytes */
64 
67 
69  FunctionCallInfo fcinfo);
71 static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo);
73  Relation rel, BlockNumber blkno,
74  BufferAccessStrategy bstrategy);
76  Relation rel, BlockNumber blkno,
77  BufferAccessStrategy bstrategy);
79  Relation rel, BlockNumber blkno,
80  BufferAccessStrategy bstrategy);
81 static Datum pgstat_index(Relation rel, BlockNumber start,
82  pgstat_page pagefn, FunctionCallInfo fcinfo);
83 static void pgstat_index_page(pgstattuple_type *stat, Page page,
84  OffsetNumber minoff, OffsetNumber maxoff);
85 
86 /*
87  * build_pgstattuple_type -- build a pgstattuple_type tuple
88  */
89 static Datum
91 {
92 #define NCOLUMNS 9
93 #define NCHARS 314
94 
95  HeapTuple tuple;
96  char *values[NCOLUMNS];
97  char values_buf[NCOLUMNS][NCHARS];
98  int i;
99  double tuple_percent;
100  double dead_tuple_percent;
101  double free_percent; /* free/reusable space in % */
102  TupleDesc tupdesc;
103  AttInMetadata *attinmeta;
104 
105  /* Build a tuple descriptor for our result type */
106  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
107  elog(ERROR, "return type must be a row type");
108 
109  /*
110  * Generate attribute metadata needed later to produce tuples from raw C
111  * strings
112  */
113  attinmeta = TupleDescGetAttInMetadata(tupdesc);
114 
115  if (stat->table_len == 0)
116  {
117  tuple_percent = 0.0;
118  dead_tuple_percent = 0.0;
119  free_percent = 0.0;
120  }
121  else
122  {
123  tuple_percent = 100.0 * stat->tuple_len / stat->table_len;
124  dead_tuple_percent = 100.0 * stat->dead_tuple_len / stat->table_len;
125  free_percent = 100.0 * stat->free_space / stat->table_len;
126  }
127 
128  /*
129  * Prepare a values array for constructing the tuple. This should be an
130  * array of C strings which will be processed later by the appropriate
131  * "in" functions.
132  */
133  for (i = 0; i < NCOLUMNS; i++)
134  values[i] = values_buf[i];
135  i = 0;
136  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->table_len);
137  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_count);
138  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_len);
139  snprintf(values[i++], NCHARS, "%.2f", tuple_percent);
140  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_count);
141  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_len);
142  snprintf(values[i++], NCHARS, "%.2f", dead_tuple_percent);
143  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->free_space);
144  snprintf(values[i++], NCHARS, "%.2f", free_percent);
145 
146  /* build a tuple */
147  tuple = BuildTupleFromCStrings(attinmeta, values);
148 
149  /* make the tuple into a datum */
150  return HeapTupleGetDatum(tuple);
151 }
152 
153 /* ----------
154  * pgstattuple:
155  * returns live/dead tuples info
156  *
157  * C FUNCTION definition
158  * pgstattuple(text) returns pgstattuple_type
159  *
160  * The superuser() check here must be kept as the library might be upgraded
161  * without the extension being upgraded, meaning that in pre-1.5 installations
162  * these functions could be called by any user.
163  * ----------
164  */
165 
166 Datum
168 {
170  RangeVar *relrv;
171  Relation rel;
172 
173  if (!superuser())
174  ereport(ERROR,
175  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
176  errmsg("must be superuser to use pgstattuple functions")));
177 
178  /* open relation */
180  rel = relation_openrv(relrv, AccessShareLock);
181 
182  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
183 }
184 
185 /*
186  * As of pgstattuple version 1.5, we no longer need to check if the user
187  * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
188  * Users can then grant access to it based on their policies.
189  *
190  * Otherwise identical to pgstattuple (above).
191  */
192 Datum
194 {
196  RangeVar *relrv;
197  Relation rel;
198 
199  /* open relation */
201  rel = relation_openrv(relrv, AccessShareLock);
202 
203  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
204 }
205 
206 /* Must keep superuser() check, see above. */
207 Datum
209 {
210  Oid relid = PG_GETARG_OID(0);
211  Relation rel;
212 
213  if (!superuser())
214  ereport(ERROR,
215  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
216  errmsg("must be superuser to use pgstattuple functions")));
217 
218  /* open relation */
219  rel = relation_open(relid, AccessShareLock);
220 
221  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
222 }
223 
224 /* Remove superuser() check for 1.5 version, see above */
225 Datum
227 {
228  Oid relid = PG_GETARG_OID(0);
229  Relation rel;
230 
231  /* open relation */
232  rel = relation_open(relid, AccessShareLock);
233 
234  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
235 }
236 
237 /*
238  * pgstat_relation
239  */
240 static Datum
242 {
243  const char *err;
244 
245  /*
246  * Reject attempts to read non-local temporary relations; we would be
247  * likely to get wrong data since we have no visibility into the owning
248  * session's local buffers.
249  */
250  if (RELATION_IS_OTHER_TEMP(rel))
251  ereport(ERROR,
252  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
253  errmsg("cannot access temporary tables of other sessions")));
254 
255  if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind) ||
256  rel->rd_rel->relkind == RELKIND_SEQUENCE)
257  {
258  return pgstat_heap(rel, fcinfo);
259  }
260  else if (rel->rd_rel->relkind == RELKIND_INDEX)
261  {
262  switch (rel->rd_rel->relam)
263  {
264  case BTREE_AM_OID:
265  return pgstat_index(rel, BTREE_METAPAGE + 1,
266  pgstat_btree_page, fcinfo);
267  case HASH_AM_OID:
268  return pgstat_index(rel, HASH_METAPAGE + 1,
269  pgstat_hash_page, fcinfo);
270  case GIST_AM_OID:
271  return pgstat_index(rel, GIST_ROOT_BLKNO + 1,
272  pgstat_gist_page, fcinfo);
273  case GIN_AM_OID:
274  err = "gin index";
275  break;
276  case SPGIST_AM_OID:
277  err = "spgist index";
278  break;
279  case BRIN_AM_OID:
280  err = "brin index";
281  break;
282  default:
283  err = "unknown index";
284  break;
285  }
286  ereport(ERROR,
287  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
288  errmsg("index \"%s\" (%s) is not supported",
289  RelationGetRelationName(rel), err)));
290  }
291  else
292  {
293  ereport(ERROR,
294  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
295  errmsg("cannot get tuple-level statistics for relation \"%s\"",
297  errdetail_relkind_not_supported(rel->rd_rel->relkind)));
298  }
299 
300  return 0; /* should not happen */
301 }
302 
303 /*
304  * pgstat_heap -- returns live/dead tuples info in a heap
305  */
306 static Datum
308 {
309  TableScanDesc scan;
310  HeapScanDesc hscan;
311  HeapTuple tuple;
312  BlockNumber nblocks;
313  BlockNumber block = 0; /* next block to count free space in */
314  BlockNumber tupblock;
315  Buffer buffer;
316  pgstattuple_type stat = {0};
317  SnapshotData SnapshotDirty;
318 
319  if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
320  ereport(ERROR,
321  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
322  errmsg("only heap AM is supported")));
323 
324  /* Disable syncscan because we assume we scan from block zero upwards */
325  scan = table_beginscan_strat(rel, SnapshotAny, 0, NULL, true, false);
326  hscan = (HeapScanDesc) scan;
327 
328  InitDirtySnapshot(SnapshotDirty);
329 
330  nblocks = hscan->rs_nblocks; /* # blocks to be scanned */
331 
332  /* scan the relation */
333  while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
334  {
336 
337  /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
339 
340  if (HeapTupleSatisfiesVisibility(tuple, &SnapshotDirty, hscan->rs_cbuf))
341  {
342  stat.tuple_len += tuple->t_len;
343  stat.tuple_count++;
344  }
345  else
346  {
347  stat.dead_tuple_len += tuple->t_len;
348  stat.dead_tuple_count++;
349  }
350 
352 
353  /*
354  * To avoid physically reading the table twice, try to do the
355  * free-space scan in parallel with the heap scan. However,
356  * heap_getnext may find no tuples on a given page, so we cannot
357  * simply examine the pages returned by the heap scan.
358  */
359  tupblock = ItemPointerGetBlockNumber(&tuple->t_self);
360 
361  while (block <= tupblock)
362  {
364 
365  buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
366  RBM_NORMAL, hscan->rs_strategy);
367  LockBuffer(buffer, BUFFER_LOCK_SHARE);
368  stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
369  UnlockReleaseBuffer(buffer);
370  block++;
371  }
372  }
373 
374  while (block < nblocks)
375  {
377 
378  buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
379  RBM_NORMAL, hscan->rs_strategy);
380  LockBuffer(buffer, BUFFER_LOCK_SHARE);
381  stat.free_space += PageGetHeapFreeSpace((Page) BufferGetPage(buffer));
382  UnlockReleaseBuffer(buffer);
383  block++;
384  }
385 
386  table_endscan(scan);
388 
389  stat.table_len = (uint64) nblocks * BLCKSZ;
390 
391  return build_pgstattuple_type(&stat, fcinfo);
392 }
393 
394 /*
395  * pgstat_btree_page -- check tuples in a btree page
396  */
397 static void
399  BufferAccessStrategy bstrategy)
400 {
401  Buffer buf;
402  Page page;
403 
404  buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
406  page = BufferGetPage(buf);
407 
408  /* Page is valid, see what to do with it */
409  if (PageIsNew(page))
410  {
411  /* fully empty page */
412  stat->free_space += BLCKSZ;
413  }
414  else
415  {
416  BTPageOpaque opaque;
417 
418  opaque = BTPageGetOpaque(page);
419  if (P_IGNORE(opaque))
420  {
421  /* deleted or half-dead page */
422  stat->free_space += BLCKSZ;
423  }
424  else if (P_ISLEAF(opaque))
425  {
426  pgstat_index_page(stat, page, P_FIRSTDATAKEY(opaque),
427  PageGetMaxOffsetNumber(page));
428  }
429  else
430  {
431  /* internal page */
432  }
433  }
434 
435  _bt_relbuf(rel, buf);
436 }
437 
438 /*
439  * pgstat_hash_page -- check tuples in a hash page
440  */
441 static void
443  BufferAccessStrategy bstrategy)
444 {
445  Buffer buf;
446  Page page;
447 
448  buf = _hash_getbuf_with_strategy(rel, blkno, HASH_READ, 0, bstrategy);
449  page = BufferGetPage(buf);
450 
451  if (PageGetSpecialSize(page) == MAXALIGN(sizeof(HashPageOpaqueData)))
452  {
453  HashPageOpaque opaque;
454 
455  opaque = HashPageGetOpaque(page);
456  switch (opaque->hasho_flag & LH_PAGE_TYPE)
457  {
458  case LH_UNUSED_PAGE:
459  stat->free_space += BLCKSZ;
460  break;
461  case LH_BUCKET_PAGE:
462  case LH_OVERFLOW_PAGE:
464  PageGetMaxOffsetNumber(page));
465  break;
466  case LH_BITMAP_PAGE:
467  case LH_META_PAGE:
468  default:
469  break;
470  }
471  }
472  else
473  {
474  /* maybe corrupted */
475  }
476 
477  _hash_relbuf(rel, buf);
478 }
479 
480 /*
481  * pgstat_gist_page -- check tuples in a gist page
482  */
483 static void
485  BufferAccessStrategy bstrategy)
486 {
487  Buffer buf;
488  Page page;
489 
490  buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
492  gistcheckpage(rel, buf);
493  page = BufferGetPage(buf);
494 
495  if (GistPageIsLeaf(page))
496  {
498  PageGetMaxOffsetNumber(page));
499  }
500  else
501  {
502  /* root or node */
503  }
504 
506 }
507 
508 /*
509  * pgstat_index -- returns live/dead tuples info in a generic index
510  */
511 static Datum
513  FunctionCallInfo fcinfo)
514 {
515  BlockNumber nblocks;
516  BlockNumber blkno;
517  BufferAccessStrategy bstrategy;
518  pgstattuple_type stat = {0};
519 
520  /* prepare access strategy for this index */
521  bstrategy = GetAccessStrategy(BAS_BULKREAD);
522 
523  blkno = start;
524  for (;;)
525  {
526  /* Get the current relation length */
528  nblocks = RelationGetNumberOfBlocks(rel);
530 
531  /* Quit if we've scanned the whole relation */
532  if (blkno >= nblocks)
533  {
534  stat.table_len = (uint64) nblocks * BLCKSZ;
535 
536  break;
537  }
538 
539  for (; blkno < nblocks; blkno++)
540  {
542 
543  pagefn(&stat, rel, blkno, bstrategy);
544  }
545  }
546 
548 
549  return build_pgstattuple_type(&stat, fcinfo);
550 }
551 
552 /*
553  * pgstat_index_page -- for generic index page
554  */
555 static void
557  OffsetNumber minoff, OffsetNumber maxoff)
558 {
559  OffsetNumber i;
560 
561  stat->free_space += PageGetFreeSpace(page);
562 
563  for (i = minoff; i <= maxoff; i = OffsetNumberNext(i))
564  {
565  ItemId itemid = PageGetItemId(page, i);
566 
567  if (ItemIdIsDead(itemid))
568  {
569  stat->dead_tuple_count++;
570  stat->dead_tuple_len += ItemIdGetLength(itemid);
571  }
572  else
573  {
574  stat->tuple_count++;
575  stat->tuple_len += ItemIdGetLength(itemid);
576  }
577  }
578 }
uint32 BlockNumber
Definition: block.h:31
static Datum values[MAXATTR]
Definition: bootstrap.c:156
int Buffer
Definition: buf.h:23
struct BufferAccessStrategyData * BufferAccessStrategy
Definition: buf.h:44
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4497
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4715
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:755
@ BAS_BULKREAD
Definition: bufmgr.h:35
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:157
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:158
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:227
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:350
@ RBM_NORMAL
Definition: bufmgr.h:44
Size PageGetHeapFreeSpace(Page page)
Definition: bufpage.c:991
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:907
Pointer Page
Definition: bufpage.h:78
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
#define MAXALIGN(LEN)
Definition: c.h:800
#define INT64_FORMAT
Definition: c.h:537
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
void err(int eval, const char *fmt,...)
Definition: err.c:43
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2136
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2087
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#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 GistPageIsLeaf(page)
Definition: gist.h:167
#define GIST_ROOT_BLKNO
Definition: gist_private.h:262
#define GIST_SHARE
Definition: gist_private.h:42
void gistcheckpage(Relation rel, Buffer buf)
Definition: gistutil.c:785
#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 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_with_strategy(Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy)
Definition: hashpage.c:239
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1086
struct HeapScanDescData * HeapScanDesc
Definition: heapam.h:80
bool HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot, Buffer buffer)
int i
Definition: isn.c:73
#define ItemIdGetLength(itemId)
Definition: itemid.h:59
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:431
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:481
#define AccessShareLock
Definition: lockdefs.h:36
#define ExclusiveLock
Definition: lockdefs.h:42
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3087
void _bt_relbuf(Relation rel, Buffer buf)
Definition: nbtpage.c:1023
#define P_ISLEAF(opaque)
Definition: nbtree.h:220
#define BTPageGetOpaque(page)
Definition: nbtree.h:73
#define P_FIRSTDATAKEY(opaque)
Definition: nbtree.h:369
#define BTREE_METAPAGE
Definition: nbtree.h:148
#define BT_READ
Definition: nbtree.h:719
#define P_IGNORE(opaque)
Definition: nbtree.h:225
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
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:67
Datum pgstattuplebyid(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:208
static Datum pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:241
#define NCHARS
static Datum pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:512
PG_MODULE_MAGIC
Definition: pgstattuple.c:42
static void pgstat_index_page(pgstattuple_type *stat, Page page, OffsetNumber minoff, OffsetNumber maxoff)
Definition: pgstattuple.c:556
Datum pgstattuple_v1_5(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:193
PG_FUNCTION_INFO_V1(pgstattuple)
static void pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:484
struct pgstattuple_type pgstattuple_type
void(* pgstat_page)(pgstattuple_type *, Relation, BlockNumber, BufferAccessStrategy)
Definition: pgstattuple.c:65
static Datum build_pgstattuple_type(pgstattuple_type *stat, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:90
#define NCOLUMNS
static void pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:398
Datum pgstattuplebyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:226
static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:307
Datum pgstattuple(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:167
static void pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:442
#define snprintf
Definition: port.h:238
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelationName(relation)
Definition: rel.h:538
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:659
struct RelationData * Relation
Definition: relcache.h:27
@ MAIN_FORKNUM
Definition: relpath.h:50
@ ForwardScanDirection
Definition: sdir.h:28
#define SnapshotAny
Definition: snapmgr.h:33
#define InitDirtySnapshot(snapshotdata)
Definition: snapmgr.h:40
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
uint16 hasho_flag
Definition: hash.h:82
BufferAccessStrategy rs_strategy
Definition: heapam.h:65
Buffer rs_cbuf
Definition: heapam.h:62
BlockNumber rs_nblocks
Definition: heapam.h:53
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
Form_pg_class rd_rel
Definition: rel.h:111
uint64 tuple_count
Definition: pgstattuple.c:58
uint64 dead_tuple_len
Definition: pgstattuple.c:61
uint64 dead_tuple_count
Definition: pgstattuple.c:60
Definition: c.h:676
bool superuser(void)
Definition: superuser.c:46
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1009
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
Definition: tableam.h:925
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3396