PostgreSQL Source Code  git master
btreefuncs.c
Go to the documentation of this file.
1 /*
2  * contrib/pageinspect/btreefuncs.c
3  *
4  *
5  * btreefuncs.c
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/nbtree.h"
31 #include "access/relation.h"
32 #include "catalog/namespace.h"
33 #include "catalog/pg_am.h"
34 #include "funcapi.h"
35 #include "miscadmin.h"
36 #include "pageinspect.h"
37 #include "utils/builtins.h"
38 #include "utils/rel.h"
39 #include "utils/varlena.h"
40 
45 
46 #define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
47 #define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
48 
49 /* note: BlockNumber is unsigned, hence can't be negative */
50 #define CHECK_RELATION_BLOCK_RANGE(rel, blkno) { \
51  if ( RelationGetNumberOfBlocks(rel) <= (BlockNumber) (blkno) ) \
52  elog(ERROR, "block number out of range"); }
53 
54 /* ------------------------------------------------
55  * structure for single btree page statistics
56  * ------------------------------------------------
57  */
58 typedef struct BTPageStat
59 {
67  char type;
68 
69  /* opaque data */
72  union
73  {
76  } btpo;
79 } BTPageStat;
80 
81 
82 /* -------------------------------------------------
83  * GetBTPageStatistics()
84  *
85  * Collect statistics of single b-tree page
86  * -------------------------------------------------
87  */
88 static void
90 {
91  Page page = BufferGetPage(buffer);
92  PageHeader phdr = (PageHeader) page;
93  OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
95  int item_size = 0;
96  int off;
97 
98  stat->blkno = blkno;
99 
100  stat->max_avail = BLCKSZ - (BLCKSZ - phdr->pd_special + SizeOfPageHeaderData);
101 
102  stat->dead_items = stat->live_items = 0;
103 
104  stat->page_size = PageGetPageSize(page);
105 
106  /* page type (flags) */
107  if (P_ISDELETED(opaque))
108  {
109  stat->type = 'd';
110  stat->btpo.xact = opaque->btpo.xact;
111  return;
112  }
113  else if (P_IGNORE(opaque))
114  stat->type = 'e';
115  else if (P_ISLEAF(opaque))
116  stat->type = 'l';
117  else if (P_ISROOT(opaque))
118  stat->type = 'r';
119  else
120  stat->type = 'i';
121 
122  /* btpage opaque data */
123  stat->btpo_prev = opaque->btpo_prev;
124  stat->btpo_next = opaque->btpo_next;
125  stat->btpo.level = opaque->btpo.level;
126  stat->btpo_flags = opaque->btpo_flags;
127  stat->btpo_cycleid = opaque->btpo_cycleid;
128 
129  /* count live and dead tuples, and free space */
130  for (off = FirstOffsetNumber; off <= maxoff; off++)
131  {
132  IndexTuple itup;
133 
134  ItemId id = PageGetItemId(page, off);
135 
136  itup = (IndexTuple) PageGetItem(page, id);
137 
138  item_size += IndexTupleSize(itup);
139 
140  if (!ItemIdIsDead(id))
141  stat->live_items++;
142  else
143  stat->dead_items++;
144  }
145  stat->free_size = PageGetFreeSpace(page);
146 
147  if ((stat->live_items + stat->dead_items) > 0)
148  stat->avg_item_size = item_size / (stat->live_items + stat->dead_items);
149  else
150  stat->avg_item_size = 0;
151 }
152 
153 /* -----------------------------------------------
154  * bt_page_stats()
155  *
156  * Usage: SELECT * FROM bt_page_stats('t1_pkey', 1);
157  * -----------------------------------------------
158  */
159 Datum
161 {
164  Buffer buffer;
165  Relation rel;
166  RangeVar *relrv;
167  Datum result;
168  HeapTuple tuple;
169  TupleDesc tupleDesc;
170  int j;
171  char *values[11];
173 
174  if (!superuser())
175  ereport(ERROR,
176  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
177  (errmsg("must be superuser to use pageinspect functions"))));
178 
180  rel = relation_openrv(relrv, AccessShareLock);
181 
182  if (!IS_INDEX(rel) || !IS_BTREE(rel))
183  elog(ERROR, "relation \"%s\" is not a btree index",
185 
186  /*
187  * Reject attempts to read non-local temporary relations; we would be
188  * likely to get wrong data since we have no visibility into the owning
189  * session's local buffers.
190  */
191  if (RELATION_IS_OTHER_TEMP(rel))
192  ereport(ERROR,
193  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
194  errmsg("cannot access temporary tables of other sessions")));
195 
196  if (blkno == 0)
197  elog(ERROR, "block 0 is a meta page");
198 
199  CHECK_RELATION_BLOCK_RANGE(rel, blkno);
200 
201  buffer = ReadBuffer(rel, blkno);
202  LockBuffer(buffer, BUFFER_LOCK_SHARE);
203 
204  /* keep compiler quiet */
205  stat.btpo_prev = stat.btpo_next = InvalidBlockNumber;
206  stat.btpo_flags = stat.free_size = stat.avg_item_size = 0;
207 
208  GetBTPageStatistics(blkno, buffer, &stat);
209 
210  UnlockReleaseBuffer(buffer);
212 
213  /* Build a tuple descriptor for our result type */
214  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
215  elog(ERROR, "return type must be a row type");
216 
217  j = 0;
218  values[j++] = psprintf("%d", stat.blkno);
219  values[j++] = psprintf("%c", stat.type);
220  values[j++] = psprintf("%d", stat.live_items);
221  values[j++] = psprintf("%d", stat.dead_items);
222  values[j++] = psprintf("%d", stat.avg_item_size);
223  values[j++] = psprintf("%d", stat.page_size);
224  values[j++] = psprintf("%d", stat.free_size);
225  values[j++] = psprintf("%d", stat.btpo_prev);
226  values[j++] = psprintf("%d", stat.btpo_next);
227  values[j++] = psprintf("%d", (stat.type == 'd') ? stat.btpo.xact : stat.btpo.level);
228  values[j++] = psprintf("%d", stat.btpo_flags);
229 
231  values);
232 
233  result = HeapTupleGetDatum(tuple);
234 
235  PG_RETURN_DATUM(result);
236 }
237 
238 
239 /*
240  * cross-call data structure for SRF
241  */
242 struct user_args
243 {
246 };
247 
248 /*-------------------------------------------------------
249  * bt_page_print_tuples()
250  *
251  * Form a tuple describing index tuple at a given offset
252  * ------------------------------------------------------
253  */
254 static Datum
256 {
257  char *values[6];
258  HeapTuple tuple;
259  ItemId id;
260  IndexTuple itup;
261  int j;
262  int off;
263  int dlen;
264  char *dump;
265  char *ptr;
266 
267  id = PageGetItemId(page, offset);
268 
269  if (!ItemIdIsValid(id))
270  elog(ERROR, "invalid ItemId");
271 
272  itup = (IndexTuple) PageGetItem(page, id);
273 
274  j = 0;
275  values[j++] = psprintf("%d", offset);
276  values[j++] = psprintf("(%u,%u)",
279  values[j++] = psprintf("%d", (int) IndexTupleSize(itup));
280  values[j++] = psprintf("%c", IndexTupleHasNulls(itup) ? 't' : 'f');
281  values[j++] = psprintf("%c", IndexTupleHasVarwidths(itup) ? 't' : 'f');
282 
283  ptr = (char *) itup + IndexInfoFindDataOffset(itup->t_info);
284  dlen = IndexTupleSize(itup) - IndexInfoFindDataOffset(itup->t_info);
285  dump = palloc0(dlen * 3 + 1);
286  values[j] = dump;
287  for (off = 0; off < dlen; off++)
288  {
289  if (off > 0)
290  *dump++ = ' ';
291  sprintf(dump, "%02x", *(ptr + off) & 0xff);
292  dump += 2;
293  }
294 
295  tuple = BuildTupleFromCStrings(fctx->attinmeta, values);
296 
297  return HeapTupleGetDatum(tuple);
298 }
299 
300 /*-------------------------------------------------------
301  * bt_page_items()
302  *
303  * Get IndexTupleData set in a btree page
304  *
305  * Usage: SELECT * FROM bt_page_items('t1_pkey', 1);
306  *-------------------------------------------------------
307  */
308 Datum
310 {
313  Datum result;
314  FuncCallContext *fctx;
315  MemoryContext mctx;
316  struct user_args *uargs;
317 
318  if (!superuser())
319  ereport(ERROR,
320  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
321  (errmsg("must be superuser to use pageinspect functions"))));
322 
323  if (SRF_IS_FIRSTCALL())
324  {
325  RangeVar *relrv;
326  Relation rel;
327  Buffer buffer;
328  BTPageOpaque opaque;
329  TupleDesc tupleDesc;
330 
331  fctx = SRF_FIRSTCALL_INIT();
332 
334  rel = relation_openrv(relrv, AccessShareLock);
335 
336  if (!IS_INDEX(rel) || !IS_BTREE(rel))
337  elog(ERROR, "relation \"%s\" is not a btree index",
339 
340  /*
341  * Reject attempts to read non-local temporary relations; we would be
342  * likely to get wrong data since we have no visibility into the
343  * owning session's local buffers.
344  */
345  if (RELATION_IS_OTHER_TEMP(rel))
346  ereport(ERROR,
347  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
348  errmsg("cannot access temporary tables of other sessions")));
349 
350  if (blkno == 0)
351  elog(ERROR, "block 0 is a meta page");
352 
353  CHECK_RELATION_BLOCK_RANGE(rel, blkno);
354 
355  buffer = ReadBuffer(rel, blkno);
356  LockBuffer(buffer, BUFFER_LOCK_SHARE);
357 
358  /*
359  * We copy the page into local storage to avoid holding pin on the
360  * buffer longer than we must, and possibly failing to release it at
361  * all if the calling query doesn't fetch all rows.
362  */
364 
365  uargs = palloc(sizeof(struct user_args));
366 
367  uargs->page = palloc(BLCKSZ);
368  memcpy(uargs->page, BufferGetPage(buffer), BLCKSZ);
369 
370  UnlockReleaseBuffer(buffer);
372 
373  uargs->offset = FirstOffsetNumber;
374 
375  opaque = (BTPageOpaque) PageGetSpecialPointer(uargs->page);
376 
377  if (P_ISDELETED(opaque))
378  elog(NOTICE, "page is deleted");
379 
380  fctx->max_calls = PageGetMaxOffsetNumber(uargs->page);
381 
382  /* Build a tuple descriptor for our result type */
383  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
384  elog(ERROR, "return type must be a row type");
385 
386  fctx->attinmeta = TupleDescGetAttInMetadata(tupleDesc);
387 
388  fctx->user_fctx = uargs;
389 
390  MemoryContextSwitchTo(mctx);
391  }
392 
393  fctx = SRF_PERCALL_SETUP();
394  uargs = fctx->user_fctx;
395 
396  if (fctx->call_cntr < fctx->max_calls)
397  {
398  result = bt_page_print_tuples(fctx, uargs->page, uargs->offset);
399  uargs->offset++;
400  SRF_RETURN_NEXT(fctx, result);
401  }
402  else
403  {
404  pfree(uargs->page);
405  pfree(uargs);
406  SRF_RETURN_DONE(fctx);
407  }
408 }
409 
410 /*-------------------------------------------------------
411  * bt_page_items_bytea()
412  *
413  * Get IndexTupleData set in a btree page
414  *
415  * Usage: SELECT * FROM bt_page_items(get_raw_page('t1_pkey', 1));
416  *-------------------------------------------------------
417  */
418 
419 Datum
421 {
422  bytea *raw_page = PG_GETARG_BYTEA_P(0);
423  Datum result;
424  FuncCallContext *fctx;
425  struct user_args *uargs;
426  int raw_page_size;
427 
428  if (!superuser())
429  ereport(ERROR,
430  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
431  (errmsg("must be superuser to use raw page functions"))));
432 
433  if (SRF_IS_FIRSTCALL())
434  {
435  BTPageOpaque opaque;
436  MemoryContext mctx;
437  TupleDesc tupleDesc;
438 
439  raw_page_size = VARSIZE(raw_page) - VARHDRSZ;
440 
441  if (raw_page_size < SizeOfPageHeaderData)
442  ereport(ERROR,
443  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
444  errmsg("input page too small (%d bytes)", raw_page_size)));
445 
446  fctx = SRF_FIRSTCALL_INIT();
448 
449  uargs = palloc(sizeof(struct user_args));
450 
451  uargs->page = VARDATA(raw_page);
452 
453  uargs->offset = FirstOffsetNumber;
454 
455  opaque = (BTPageOpaque) PageGetSpecialPointer(uargs->page);
456 
457  if (P_ISMETA(opaque))
458  ereport(ERROR,
459  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
460  errmsg("block is a meta page")));
461 
462  if (P_ISDELETED(opaque))
463  elog(NOTICE, "page is deleted");
464 
465  fctx->max_calls = PageGetMaxOffsetNumber(uargs->page);
466 
467  /* Build a tuple descriptor for our result type */
468  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
469  elog(ERROR, "return type must be a row type");
470 
471  fctx->attinmeta = TupleDescGetAttInMetadata(tupleDesc);
472 
473  fctx->user_fctx = uargs;
474 
475  MemoryContextSwitchTo(mctx);
476  }
477 
478  fctx = SRF_PERCALL_SETUP();
479  uargs = fctx->user_fctx;
480 
481  if (fctx->call_cntr < fctx->max_calls)
482  {
483  result = bt_page_print_tuples(fctx, uargs->page, uargs->offset);
484  uargs->offset++;
485  SRF_RETURN_NEXT(fctx, result);
486  }
487  else
488  {
489  pfree(uargs);
490  SRF_RETURN_DONE(fctx);
491  }
492 }
493 
494 
495 /* ------------------------------------------------
496  * bt_metap()
497  *
498  * Get a btree's meta-page information
499  *
500  * Usage: SELECT * FROM bt_metap('t1_pkey')
501  * ------------------------------------------------
502  */
503 Datum
505 {
507  Datum result;
508  Relation rel;
509  RangeVar *relrv;
510  BTMetaPageData *metad;
511  TupleDesc tupleDesc;
512  int j;
513  char *values[8];
514  Buffer buffer;
515  Page page;
516  HeapTuple tuple;
517 
518  if (!superuser())
519  ereport(ERROR,
520  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
521  (errmsg("must be superuser to use pageinspect functions"))));
522 
524  rel = relation_openrv(relrv, AccessShareLock);
525 
526  if (!IS_INDEX(rel) || !IS_BTREE(rel))
527  elog(ERROR, "relation \"%s\" is not a btree index",
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 tables of other sessions")));
539 
540  buffer = ReadBuffer(rel, 0);
541  LockBuffer(buffer, BUFFER_LOCK_SHARE);
542 
543  page = BufferGetPage(buffer);
544  metad = BTPageGetMeta(page);
545 
546  /* Build a tuple descriptor for our result type */
547  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
548  elog(ERROR, "return type must be a row type");
549 
550  j = 0;
551  values[j++] = psprintf("%d", metad->btm_magic);
552  values[j++] = psprintf("%d", metad->btm_version);
553  values[j++] = psprintf("%d", metad->btm_root);
554  values[j++] = psprintf("%d", metad->btm_level);
555  values[j++] = psprintf("%d", metad->btm_fastroot);
556  values[j++] = psprintf("%d", metad->btm_fastlevel);
557 
558  /*
559  * Get values of extended metadata if available, use default values
560  * otherwise.
561  */
562  if (metad->btm_version >= BTREE_NOVAC_VERSION)
563  {
564  values[j++] = psprintf("%u", metad->btm_oldest_btpo_xact);
565  values[j++] = psprintf("%f", metad->btm_last_cleanup_num_heap_tuples);
566  }
567  else
568  {
569  values[j++] = "0";
570  values[j++] = "-1";
571  }
572 
574  values);
575 
576  result = HeapTupleGetDatum(tuple);
577 
578  UnlockReleaseBuffer(buffer);
580 
581  PG_RETURN_DATUM(result);
582 }
uint32 avg_item_size
Definition: btreefuncs.c:66
struct BTPageStat BTPageStat
uint64 call_cntr
Definition: funcapi.h:66
#define PG_GETARG_UINT32(n)
Definition: fmgr.h:265
union BTPageStat::@1 btpo
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:108
#define IndexInfoFindDataOffset(t_info)
Definition: itup.h:80
BlockNumber btpo_next
Definition: nbtree.h:58
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:196
#define VARDATA(PTR)
Definition: postgres.h:302
uint32 dead_items
Definition: btreefuncs.c:62
#define CHECK_RELATION_BLOCK_RANGE(rel, blkno)
Definition: btreefuncs.c:50
Datum bt_page_items(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:309
#define P_IGNORE(opaque)
Definition: nbtree.h:194
Datum bt_page_stats(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:160
uint32 TransactionId
Definition: c.h:508
uint32 btm_version
Definition: nbtree.h:100
#define VARSIZE(PTR)
Definition: postgres.h:303
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:283
#define VARHDRSZ
Definition: c.h:556
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
uint32 btm_magic
Definition: nbtree.h:99
ItemPointerData t_tid
Definition: itup.h:37
union BTPageOpaqueData::@46 btpo
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define AccessShareLock
Definition: lockdefs.h:36
uint32 blkno
Definition: btreefuncs.c:60
int errcode(int sqlerrcode)
Definition: elog.c:608
#define IS_BTREE(r)
Definition: btreefuncs.c:47
bool superuser(void)
Definition: superuser.c:46
uint32 BlockNumber
Definition: block.h:31
char type
Definition: btreefuncs.c:67
#define IndexTupleHasNulls(itup)
Definition: itup.h:72
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
#define SizeOfPageHeaderData
Definition: bufpage.h:216
NameData relname
Definition: pg_class.h:35
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:287
TransactionId xact
Definition: nbtree.h:62
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:68
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:581
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2116
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
uint16 OffsetNumber
Definition: off.h:24
#define P_ISMETA(opaque)
Definition: nbtree.h:192
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:289
#define PG_GETARG_BYTEA_P(n)
Definition: fmgr.h:329
#define sprintf
Definition: port.h:194
BlockNumber btm_fastroot
Definition: nbtree.h:103
unsigned short uint16
Definition: c.h:358
void pfree(void *pointer)
Definition: mcxt.c:1056
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3388
#define ERROR
Definition: elog.h:43
OffsetNumber offset
Definition: btreefuncs.c:245
uint16 BTCycleId
Definition: nbtree.h:27
BlockNumber btpo_next
Definition: btreefuncs.c:71
BTCycleId btpo_cycleid
Definition: nbtree.h:65
#define BTPageGetMeta(p)
Definition: nbtree.h:112
BlockNumber btpo_prev
Definition: nbtree.h:57
Datum bt_metap(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:504
#define FirstOffsetNumber
Definition: off.h:27
AttInMetadata * attinmeta
Definition: funcapi.h:92
IndexTupleData * IndexTuple
Definition: itup.h:53
#define PageGetPageSize(page)
Definition: bufpage.h:268
#define RelationGetRelationName(relation)
Definition: rel.h:457
unsigned int uint32
Definition: c.h:359
#define BTREE_NOVAC_VERSION
Definition: nbtree.h:135
Datum bt_page_items_bytea(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:420
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
#define ereport(elevel, rest)
Definition: elog.h:141
#define P_ISDELETED(opaque)
Definition: nbtree.h:191
#define P_ISROOT(opaque)
Definition: nbtree.h:190
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3594
uint32 live_items
Definition: btreefuncs.c:61
TransactionId xact
Definition: btreefuncs.c:75
LocationIndex pd_special
Definition: bufpage.h:160
#define stat(a, b)
Definition: win32_port.h:255
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
uint32 btm_fastlevel
Definition: nbtree.h:104
uint32 level
Definition: nbtree.h:61
void * palloc0(Size size)
Definition: mcxt.c:980
BlockNumber btpo_prev
Definition: btreefuncs.c:70
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
uint32 free_size
Definition: btreefuncs.c:65
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2067
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3602
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
BlockNumber btm_root
Definition: nbtree.h:101
Page page
Definition: btreefuncs.c:244
#define ItemIdIsValid(itemId)
Definition: itemid.h:86
#define NOTICE
Definition: elog.h:37
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:553
uint32 max_avail
Definition: btreefuncs.c:64
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:102
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:596
#define PageGetSpecialPointer(page)
Definition: bufpage.h:326
#define InvalidBlockNumber
Definition: block.h:33
float8 btm_last_cleanup_num_heap_tuples
Definition: nbtree.h:108
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
BTCycleId btpo_cycleid
Definition: btreefuncs.c:78
uint16 btpo_flags
Definition: btreefuncs.c:77
#define IndexTupleHasVarwidths(itup)
Definition: itup.h:73
static void GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat)
Definition: btreefuncs.c:89
static Datum values[MAXATTR]
Definition: bootstrap.c:167
PG_FUNCTION_INFO_V1(bt_metap)
void * user_fctx
Definition: funcapi.h:83
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89
static Datum bt_page_print_tuples(FuncCallContext *fctx, Page page, OffsetNumber offset)
Definition: btreefuncs.c:255
uint32 btm_level
Definition: nbtree.h:102
uint32 page_size
Definition: btreefuncs.c:63
#define elog(elevel,...)
Definition: elog.h:228
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:87
Definition: c.h:550
#define PG_FUNCTION_ARGS
Definition: fmgr.h:188
TransactionId btm_oldest_btpo_xact
Definition: nbtree.h:106
unsigned short t_info
Definition: itup.h:49
uint32 level
Definition: btreefuncs.c:74
uint16 btpo_flags
Definition: nbtree.h:64
int Buffer
Definition: buf.h:23
uint64 max_calls
Definition: funcapi.h:75
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
Pointer Page
Definition: bufpage.h:78
#define IndexTupleSize(itup)
Definition: itup.h:71
#define IS_INDEX(r)
Definition: btreefuncs.c:46
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:307
#define P_ISLEAF(opaque)
Definition: nbtree.h:189
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:285