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 "catalog/pg_type.h"
35 #include "funcapi.h"
36 #include "miscadmin.h"
37 #include "pageinspect.h"
38 #include "utils/array.h"
39 #include "utils/builtins.h"
40 #include "utils/rel.h"
41 #include "utils/varlena.h"
42 
47 
48 #define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
49 #define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
50 #define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X))
51 #define ItemPointerGetDatum(X) PointerGetDatum(X)
52 
53 /* note: BlockNumber is unsigned, hence can't be negative */
54 #define CHECK_RELATION_BLOCK_RANGE(rel, blkno) { \
55  if ( RelationGetNumberOfBlocks(rel) <= (BlockNumber) (blkno) ) \
56  elog(ERROR, "block number out of range"); }
57 
58 /* ------------------------------------------------
59  * structure for single btree page statistics
60  * ------------------------------------------------
61  */
62 typedef struct BTPageStat
63 {
71  char type;
72 
73  /* opaque data */
76  union
77  {
80  } btpo;
83 } BTPageStat;
84 
85 
86 /* -------------------------------------------------
87  * GetBTPageStatistics()
88  *
89  * Collect statistics of single b-tree page
90  * -------------------------------------------------
91  */
92 static void
94 {
95  Page page = BufferGetPage(buffer);
96  PageHeader phdr = (PageHeader) page;
97  OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
99  int item_size = 0;
100  int off;
101 
102  stat->blkno = blkno;
103 
104  stat->max_avail = BLCKSZ - (BLCKSZ - phdr->pd_special + SizeOfPageHeaderData);
105 
106  stat->dead_items = stat->live_items = 0;
107 
108  stat->page_size = PageGetPageSize(page);
109 
110  /* page type (flags) */
111  if (P_ISDELETED(opaque))
112  {
113  stat->type = 'd';
114  stat->btpo.xact = opaque->btpo.xact;
115  return;
116  }
117  else if (P_IGNORE(opaque))
118  stat->type = 'e';
119  else if (P_ISLEAF(opaque))
120  stat->type = 'l';
121  else if (P_ISROOT(opaque))
122  stat->type = 'r';
123  else
124  stat->type = 'i';
125 
126  /* btpage opaque data */
127  stat->btpo_prev = opaque->btpo_prev;
128  stat->btpo_next = opaque->btpo_next;
129  stat->btpo.level = opaque->btpo.level;
130  stat->btpo_flags = opaque->btpo_flags;
131  stat->btpo_cycleid = opaque->btpo_cycleid;
132 
133  /* count live and dead tuples, and free space */
134  for (off = FirstOffsetNumber; off <= maxoff; off++)
135  {
136  IndexTuple itup;
137 
138  ItemId id = PageGetItemId(page, off);
139 
140  itup = (IndexTuple) PageGetItem(page, id);
141 
142  item_size += IndexTupleSize(itup);
143 
144  if (!ItemIdIsDead(id))
145  stat->live_items++;
146  else
147  stat->dead_items++;
148  }
149  stat->free_size = PageGetFreeSpace(page);
150 
151  if ((stat->live_items + stat->dead_items) > 0)
152  stat->avg_item_size = item_size / (stat->live_items + stat->dead_items);
153  else
154  stat->avg_item_size = 0;
155 }
156 
157 /* -----------------------------------------------
158  * bt_page_stats()
159  *
160  * Usage: SELECT * FROM bt_page_stats('t1_pkey', 1);
161  * -----------------------------------------------
162  */
163 Datum
165 {
168  Buffer buffer;
169  Relation rel;
170  RangeVar *relrv;
171  Datum result;
172  HeapTuple tuple;
173  TupleDesc tupleDesc;
174  int j;
175  char *values[11];
177 
178  if (!superuser())
179  ereport(ERROR,
180  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
181  errmsg("must be superuser to use pageinspect functions")));
182 
184  rel = relation_openrv(relrv, AccessShareLock);
185 
186  if (!IS_INDEX(rel) || !IS_BTREE(rel))
187  elog(ERROR, "relation \"%s\" is not a btree index",
189 
190  /*
191  * Reject attempts to read non-local temporary relations; we would be
192  * likely to get wrong data since we have no visibility into the owning
193  * session's local buffers.
194  */
195  if (RELATION_IS_OTHER_TEMP(rel))
196  ereport(ERROR,
197  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
198  errmsg("cannot access temporary tables of other sessions")));
199 
200  if (blkno == 0)
201  elog(ERROR, "block 0 is a meta page");
202 
203  CHECK_RELATION_BLOCK_RANGE(rel, blkno);
204 
205  buffer = ReadBuffer(rel, blkno);
206  LockBuffer(buffer, BUFFER_LOCK_SHARE);
207 
208  /* keep compiler quiet */
209  stat.btpo_prev = stat.btpo_next = InvalidBlockNumber;
210  stat.btpo_flags = stat.free_size = stat.avg_item_size = 0;
211 
212  GetBTPageStatistics(blkno, buffer, &stat);
213 
214  UnlockReleaseBuffer(buffer);
216 
217  /* Build a tuple descriptor for our result type */
218  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
219  elog(ERROR, "return type must be a row type");
220 
221  j = 0;
222  values[j++] = psprintf("%d", stat.blkno);
223  values[j++] = psprintf("%c", stat.type);
224  values[j++] = psprintf("%d", stat.live_items);
225  values[j++] = psprintf("%d", stat.dead_items);
226  values[j++] = psprintf("%d", stat.avg_item_size);
227  values[j++] = psprintf("%d", stat.page_size);
228  values[j++] = psprintf("%d", stat.free_size);
229  values[j++] = psprintf("%d", stat.btpo_prev);
230  values[j++] = psprintf("%d", stat.btpo_next);
231  values[j++] = psprintf("%d", (stat.type == 'd') ? stat.btpo.xact : stat.btpo.level);
232  values[j++] = psprintf("%d", stat.btpo_flags);
233 
235  values);
236 
237  result = HeapTupleGetDatum(tuple);
238 
239  PG_RETURN_DATUM(result);
240 }
241 
242 
243 /*
244  * cross-call data structure for SRF
245  */
246 struct user_args
247 {
250  bool leafpage;
251  bool rightmost;
253 };
254 
255 /*-------------------------------------------------------
256  * bt_page_print_tuples()
257  *
258  * Form a tuple describing index tuple at a given offset
259  * ------------------------------------------------------
260  */
261 static Datum
263 {
264  Page page = uargs->page;
265  OffsetNumber offset = uargs->offset;
266  bool leafpage = uargs->leafpage;
267  bool rightmost = uargs->rightmost;
268  bool ispivottuple;
269  Datum values[9];
270  bool nulls[9];
271  HeapTuple tuple;
272  ItemId id;
273  IndexTuple itup;
274  int j;
275  int off;
276  int dlen;
277  char *dump,
278  *datacstring;
279  char *ptr;
280  ItemPointer htid;
281 
282  id = PageGetItemId(page, offset);
283 
284  if (!ItemIdIsValid(id))
285  elog(ERROR, "invalid ItemId");
286 
287  itup = (IndexTuple) PageGetItem(page, id);
288 
289  j = 0;
290  memset(nulls, 0, sizeof(nulls));
291  values[j++] = DatumGetInt16(offset);
292  values[j++] = ItemPointerGetDatum(&itup->t_tid);
293  values[j++] = Int32GetDatum((int) IndexTupleSize(itup));
294  values[j++] = BoolGetDatum(IndexTupleHasNulls(itup));
295  values[j++] = BoolGetDatum(IndexTupleHasVarwidths(itup));
296 
297  ptr = (char *) itup + IndexInfoFindDataOffset(itup->t_info);
298  dlen = IndexTupleSize(itup) - IndexInfoFindDataOffset(itup->t_info);
299 
300  /*
301  * Make sure that "data" column does not include posting list or pivot
302  * tuple representation of heap TID(s).
303  *
304  * Note: BTreeTupleIsPivot() won't work reliably on !heapkeyspace indexes
305  * (those built before BTREE_VERSION 4), but we have no way of determining
306  * if this page came from a !heapkeyspace index. We may only have a bytea
307  * nbtree page image to go on, so in general there is no metapage that we
308  * can check.
309  *
310  * That's okay here because BTreeTupleIsPivot() can only return false for
311  * a !heapkeyspace pivot, never true for a !heapkeyspace non-pivot. Since
312  * heap TID isn't part of the keyspace in a !heapkeyspace index anyway,
313  * there cannot possibly be a pivot tuple heap TID representation that we
314  * fail to make an adjustment for. A !heapkeyspace index can have
315  * BTreeTupleIsPivot() return true (due to things like suffix truncation
316  * for INCLUDE indexes in Postgres v11), but when that happens
317  * BTreeTupleGetHeapTID() can be trusted to work reliably (i.e. return
318  * NULL).
319  *
320  * Note: BTreeTupleIsPosting() always works reliably, even with
321  * !heapkeyspace indexes.
322  */
323  if (BTreeTupleIsPosting(itup))
324  dlen -= IndexTupleSize(itup) - BTreeTupleGetPostingOffset(itup);
325  else if (BTreeTupleIsPivot(itup) && BTreeTupleGetHeapTID(itup) != NULL)
326  dlen -= MAXALIGN(sizeof(ItemPointerData));
327 
328  if (dlen < 0 || dlen > INDEX_SIZE_MASK)
329  elog(ERROR, "invalid tuple length %d for tuple at offset number %u",
330  dlen, offset);
331  dump = palloc0(dlen * 3 + 1);
332  datacstring = dump;
333  for (off = 0; off < dlen; off++)
334  {
335  if (off > 0)
336  *dump++ = ' ';
337  sprintf(dump, "%02x", *(ptr + off) & 0xff);
338  dump += 2;
339  }
340  values[j++] = CStringGetTextDatum(datacstring);
341  pfree(datacstring);
342 
343  /*
344  * We need to work around the BTreeTupleIsPivot() !heapkeyspace limitation
345  * again. Deduce whether or not tuple must be a pivot tuple based on
346  * whether or not the page is a leaf page, as well as the page offset
347  * number of the tuple.
348  */
349  ispivottuple = (!leafpage || (!rightmost && offset == P_HIKEY));
350 
351  /* LP_DEAD bit can never be set for pivot tuples, so show a NULL there */
352  if (!ispivottuple)
353  values[j++] = BoolGetDatum(ItemIdIsDead(id));
354  else
355  {
356  Assert(!ItemIdIsDead(id));
357  nulls[j++] = true;
358  }
359 
360  htid = BTreeTupleGetHeapTID(itup);
361  if (ispivottuple && !BTreeTupleIsPivot(itup))
362  {
363  /* Don't show bogus heap TID in !heapkeyspace pivot tuple */
364  htid = NULL;
365  }
366 
367  if (htid)
368  values[j++] = ItemPointerGetDatum(htid);
369  else
370  nulls[j++] = true;
371 
372  if (BTreeTupleIsPosting(itup))
373  {
374  /* Build an array of item pointers */
375  ItemPointer tids;
376  Datum *tids_datum;
377  int nposting;
378 
379  tids = BTreeTupleGetPosting(itup);
380  nposting = BTreeTupleGetNPosting(itup);
381  tids_datum = (Datum *) palloc(nposting * sizeof(Datum));
382  for (int i = 0; i < nposting; i++)
383  tids_datum[i] = ItemPointerGetDatum(&tids[i]);
384  values[j++] = PointerGetDatum(construct_array(tids_datum,
385  nposting,
386  TIDOID,
387  sizeof(ItemPointerData),
388  false, TYPALIGN_SHORT));
389  pfree(tids_datum);
390  }
391  else
392  nulls[j++] = true;
393 
394  /* Build and return the result tuple */
395  tuple = heap_form_tuple(uargs->tupd, values, nulls);
396 
397  return HeapTupleGetDatum(tuple);
398 }
399 
400 /*-------------------------------------------------------
401  * bt_page_items()
402  *
403  * Get IndexTupleData set in a btree page
404  *
405  * Usage: SELECT * FROM bt_page_items('t1_pkey', 1);
406  *-------------------------------------------------------
407  */
408 Datum
410 {
413  Datum result;
414  FuncCallContext *fctx;
415  MemoryContext mctx;
416  struct user_args *uargs;
417 
418  if (!superuser())
419  ereport(ERROR,
420  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
421  errmsg("must be superuser to use pageinspect functions")));
422 
423  if (SRF_IS_FIRSTCALL())
424  {
425  RangeVar *relrv;
426  Relation rel;
427  Buffer buffer;
428  BTPageOpaque opaque;
429  TupleDesc tupleDesc;
430 
431  fctx = SRF_FIRSTCALL_INIT();
432 
434  rel = relation_openrv(relrv, AccessShareLock);
435 
436  if (!IS_INDEX(rel) || !IS_BTREE(rel))
437  elog(ERROR, "relation \"%s\" is not a btree index",
439 
440  /*
441  * Reject attempts to read non-local temporary relations; we would be
442  * likely to get wrong data since we have no visibility into the
443  * owning session's local buffers.
444  */
445  if (RELATION_IS_OTHER_TEMP(rel))
446  ereport(ERROR,
447  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
448  errmsg("cannot access temporary tables of other sessions")));
449 
450  if (blkno == 0)
451  elog(ERROR, "block 0 is a meta page");
452 
453  CHECK_RELATION_BLOCK_RANGE(rel, blkno);
454 
455  buffer = ReadBuffer(rel, blkno);
456  LockBuffer(buffer, BUFFER_LOCK_SHARE);
457 
458  /*
459  * We copy the page into local storage to avoid holding pin on the
460  * buffer longer than we must, and possibly failing to release it at
461  * all if the calling query doesn't fetch all rows.
462  */
464 
465  uargs = palloc(sizeof(struct user_args));
466 
467  uargs->page = palloc(BLCKSZ);
468  memcpy(uargs->page, BufferGetPage(buffer), BLCKSZ);
469 
470  UnlockReleaseBuffer(buffer);
472 
473  uargs->offset = FirstOffsetNumber;
474 
475  opaque = (BTPageOpaque) PageGetSpecialPointer(uargs->page);
476 
477  if (P_ISDELETED(opaque))
478  elog(NOTICE, "page is deleted");
479 
480  fctx->max_calls = PageGetMaxOffsetNumber(uargs->page);
481  uargs->leafpage = P_ISLEAF(opaque);
482  uargs->rightmost = P_RIGHTMOST(opaque);
483 
484  /* Build a tuple descriptor for our result type */
485  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
486  elog(ERROR, "return type must be a row type");
487  tupleDesc = BlessTupleDesc(tupleDesc);
488 
489  uargs->tupd = tupleDesc;
490 
491  fctx->user_fctx = uargs;
492 
493  MemoryContextSwitchTo(mctx);
494  }
495 
496  fctx = SRF_PERCALL_SETUP();
497  uargs = fctx->user_fctx;
498 
499  if (fctx->call_cntr < fctx->max_calls)
500  {
501  result = bt_page_print_tuples(uargs);
502  uargs->offset++;
503  SRF_RETURN_NEXT(fctx, result);
504  }
505 
506  SRF_RETURN_DONE(fctx);
507 }
508 
509 /*-------------------------------------------------------
510  * bt_page_items_bytea()
511  *
512  * Get IndexTupleData set in a btree page
513  *
514  * Usage: SELECT * FROM bt_page_items(get_raw_page('t1_pkey', 1));
515  *-------------------------------------------------------
516  */
517 
518 Datum
520 {
521  bytea *raw_page = PG_GETARG_BYTEA_P(0);
522  Datum result;
523  FuncCallContext *fctx;
524  struct user_args *uargs;
525  int raw_page_size;
526 
527  if (!superuser())
528  ereport(ERROR,
529  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
530  errmsg("must be superuser to use raw page functions")));
531 
532  if (SRF_IS_FIRSTCALL())
533  {
534  BTPageOpaque opaque;
535  MemoryContext mctx;
536  TupleDesc tupleDesc;
537 
538  raw_page_size = VARSIZE(raw_page) - VARHDRSZ;
539 
540  if (raw_page_size < SizeOfPageHeaderData)
541  ereport(ERROR,
542  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
543  errmsg("input page too small (%d bytes)", raw_page_size)));
544 
545  fctx = SRF_FIRSTCALL_INIT();
547 
548  uargs = palloc(sizeof(struct user_args));
549 
550  uargs->page = VARDATA(raw_page);
551 
552  uargs->offset = FirstOffsetNumber;
553 
554  opaque = (BTPageOpaque) PageGetSpecialPointer(uargs->page);
555 
556  if (P_ISMETA(opaque))
557  ereport(ERROR,
558  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
559  errmsg("block is a meta page")));
560 
561  if (P_ISDELETED(opaque))
562  elog(NOTICE, "page is deleted");
563 
564  fctx->max_calls = PageGetMaxOffsetNumber(uargs->page);
565  uargs->leafpage = P_ISLEAF(opaque);
566  uargs->rightmost = P_RIGHTMOST(opaque);
567 
568  /* Build a tuple descriptor for our result type */
569  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
570  elog(ERROR, "return type must be a row type");
571  tupleDesc = BlessTupleDesc(tupleDesc);
572 
573  uargs->tupd = tupleDesc;
574 
575  fctx->user_fctx = uargs;
576 
577  MemoryContextSwitchTo(mctx);
578  }
579 
580  fctx = SRF_PERCALL_SETUP();
581  uargs = fctx->user_fctx;
582 
583  if (fctx->call_cntr < fctx->max_calls)
584  {
585  result = bt_page_print_tuples(uargs);
586  uargs->offset++;
587  SRF_RETURN_NEXT(fctx, result);
588  }
589 
590  SRF_RETURN_DONE(fctx);
591 }
592 
593 /* Number of output arguments (columns) for bt_metap() */
594 #define BT_METAP_COLS_V1_8 9
595 
596 /* ------------------------------------------------
597  * bt_metap()
598  *
599  * Get a btree's meta-page information
600  *
601  * Usage: SELECT * FROM bt_metap('t1_pkey')
602  * ------------------------------------------------
603  */
604 Datum
606 {
608  Datum result;
609  Relation rel;
610  RangeVar *relrv;
611  BTMetaPageData *metad;
612  TupleDesc tupleDesc;
613  int j;
614  char *values[9];
615  Buffer buffer;
616  Page page;
617  HeapTuple tuple;
618 
619  if (!superuser())
620  ereport(ERROR,
621  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
622  errmsg("must be superuser to use pageinspect functions")));
623 
625  rel = relation_openrv(relrv, AccessShareLock);
626 
627  if (!IS_INDEX(rel) || !IS_BTREE(rel))
628  elog(ERROR, "relation \"%s\" is not a btree index",
630 
631  /*
632  * Reject attempts to read non-local temporary relations; we would be
633  * likely to get wrong data since we have no visibility into the owning
634  * session's local buffers.
635  */
636  if (RELATION_IS_OTHER_TEMP(rel))
637  ereport(ERROR,
638  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
639  errmsg("cannot access temporary tables of other sessions")));
640 
641  buffer = ReadBuffer(rel, 0);
642  LockBuffer(buffer, BUFFER_LOCK_SHARE);
643 
644  page = BufferGetPage(buffer);
645  metad = BTPageGetMeta(page);
646 
647  /* Build a tuple descriptor for our result type */
648  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
649  elog(ERROR, "return type must be a row type");
650 
651  /*
652  * We need a kluge here to detect API versions prior to 1.8. Earlier
653  * versions incorrectly used int4 for certain columns. This caused
654  * various problems. For example, an int4 version of the "oldest_xact"
655  * column would not work with TransactionId values that happened to exceed
656  * PG_INT32_MAX.
657  *
658  * There is no way to reliably avoid the problems created by the old
659  * function definition at this point, so insist that the user update the
660  * extension.
661  */
662  if (tupleDesc->natts < BT_METAP_COLS_V1_8)
663  ereport(ERROR,
664  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
665  errmsg("function has wrong number of declared columns"),
666  errhint("To resolve the problem, update the \"pageinspect\" extension to the latest version.")));
667 
668  j = 0;
669  values[j++] = psprintf("%d", metad->btm_magic);
670  values[j++] = psprintf("%d", metad->btm_version);
671  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_root);
672  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_level);
673  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastroot);
674  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastlevel);
675 
676  /*
677  * Get values of extended metadata if available, use default values
678  * otherwise. Note that we rely on the assumption that btm_allequalimage
679  * is initialized to zero with indexes that were built on versions prior
680  * to Postgres 13 (just like _bt_metaversion()).
681  */
682  if (metad->btm_version >= BTREE_NOVAC_VERSION)
683  {
684  values[j++] = psprintf("%u", metad->btm_oldest_btpo_xact);
685  values[j++] = psprintf("%f", metad->btm_last_cleanup_num_heap_tuples);
686  values[j++] = metad->btm_allequalimage ? "t" : "f";
687  }
688  else
689  {
690  values[j++] = "0";
691  values[j++] = "-1";
692  values[j++] = "f";
693  }
694 
696  values);
697 
698  result = HeapTupleGetDatum(tuple);
699 
700  UnlockReleaseBuffer(buffer);
702 
703  PG_RETURN_DATUM(result);
704 }
uint32 avg_item_size
Definition: btreefuncs.c:70
struct BTPageStat BTPageStat
uint64 call_cntr
Definition: funcapi.h:65
#define PG_GETARG_UINT32(n)
Definition: fmgr.h:270
#define IndexInfoFindDataOffset(t_info)
Definition: itup.h:80
static Datum bt_page_print_tuples(struct user_args *uargs)
Definition: btreefuncs.c:262
BlockNumber btpo_next
Definition: nbtree.h:59
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:205
int errhint(const char *fmt,...)
Definition: elog.c:1149
#define VARDATA(PTR)
Definition: postgres.h:302
uint32 dead_items
Definition: btreefuncs.c:66
#define CHECK_RELATION_BLOCK_RANGE(rel, blkno)
Definition: btreefuncs.c:54
Datum bt_page_items(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:409
#define P_IGNORE(opaque)
Definition: nbtree.h:219
static bool BTreeTupleIsPivot(IndexTuple itup)
Definition: nbtree.h:348
Datum bt_page_stats(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:164
uint32 TransactionId
Definition: c.h:575
uint32 btm_version
Definition: nbtree.h:101
static ItemPointer BTreeTupleGetHeapTID(IndexTuple itup)
Definition: nbtree.h:506
#define VARSIZE(PTR)
Definition: postgres.h:303
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:294
#define PointerGetDatum(X)
Definition: postgres.h:556
static ItemPointer BTreeTupleGetPosting(IndexTuple posting)
Definition: nbtree.h:405
#define VARHDRSZ
Definition: c.h:623
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
uint32 btm_magic
Definition: nbtree.h:100
ItemPointerData t_tid
Definition: itup.h:37
union BTPageOpaqueData::@45 btpo
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3313
#define AccessShareLock
Definition: lockdefs.h:36
uint32 blkno
Definition: btreefuncs.c:64
#define INDEX_SIZE_MASK
Definition: itup.h:65
int errcode(int sqlerrcode)
Definition: elog.c:691
#define IS_BTREE(r)
Definition: btreefuncs.c:49
bool superuser(void)
Definition: superuser.c:46
uint32 BlockNumber
Definition: block.h:31
char type
Definition: btreefuncs.c:71
#define IndexTupleHasNulls(itup)
Definition: itup.h:72
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define SizeOfPageHeaderData
Definition: bufpage.h:216
NameData relname
Definition: pg_class.h:38
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:298
TransactionId xact
Definition: nbtree.h:63
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:69
union BTPageStat::@0 btpo
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:790
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2116
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
uint16 OffsetNumber
Definition: off.h:24
#define P_ISMETA(opaque)
Definition: nbtree.h:217
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:300
#define PG_GETARG_BYTEA_P(n)
Definition: fmgr.h:335
#define sprintf
Definition: port.h:217
BlockNumber btm_fastroot
Definition: nbtree.h:104
unsigned short uint16
Definition: c.h:428
void pfree(void *pointer)
Definition: mcxt.c:1057
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3536
#define ERROR
Definition: elog.h:43
OffsetNumber offset
Definition: btreefuncs.c:249
uint16 BTCycleId
Definition: nbtree.h:28
BlockNumber btpo_next
Definition: btreefuncs.c:75
BTCycleId btpo_cycleid
Definition: nbtree.h:66
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2052
#define BTPageGetMeta(p)
Definition: nbtree.h:114
bool btm_allequalimage
Definition: nbtree.h:111
BlockNumber btpo_prev
Definition: nbtree.h:58
Datum bt_metap(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:605
#define FirstOffsetNumber
Definition: off.h:27
IndexTupleData * IndexTuple
Definition: itup.h:53
#define DatumGetInt16(X)
Definition: postgres.h:444
#define PageGetPageSize(page)
Definition: bufpage.h:268
#define RelationGetRelationName(relation)
Definition: rel.h:491
unsigned int uint32
Definition: c.h:429
#define BTREE_NOVAC_VERSION
Definition: nbtree.h:145
Datum bt_page_items_bytea(PG_FUNCTION_ARGS)
Definition: btreefuncs.c:519
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define P_ISDELETED(opaque)
Definition: nbtree.h:216
#define P_ISROOT(opaque)
Definition: nbtree.h:215
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3658
uint32 live_items
Definition: btreefuncs.c:65
TransactionId xact
Definition: btreefuncs.c:79
LocationIndex pd_special
Definition: bufpage.h:160
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
uint32 btm_fastlevel
Definition: nbtree.h:105
uint32 level
Definition: nbtree.h:62
#define BT_METAP_COLS_V1_8
Definition: btreefuncs.c:594
void * palloc0(Size size)
Definition: mcxt.c:981
BlockNumber btpo_prev
Definition: btreefuncs.c:74
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
uint32 free_size
Definition: btreefuncs.c:69
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2067
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3752
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
BlockNumber btm_root
Definition: nbtree.h:102
Page page
Definition: btreefuncs.c:248
#define BoolGetDatum(X)
Definition: postgres.h:402
#define ereport(elevel,...)
Definition: elog.h:155
#define ItemIdIsValid(itemId)
Definition: itemid.h:86
#define NOTICE
Definition: elog.h:37
static bool BTreeTupleIsPosting(IndexTuple itup)
Definition: nbtree.h:360
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
Definition: nbtree.h:397
bool leafpage
Definition: btreefuncs.c:250
PageHeaderData * PageHeader
Definition: bufpage.h:166
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define Assert(condition)
Definition: c.h:800
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:594
uint32 max_avail
Definition: btreefuncs.c:68
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:607
#define PageGetSpecialPointer(page)
Definition: bufpage.h:326
#define InvalidBlockNumber
Definition: block.h:33
float8 btm_last_cleanup_num_heap_tuples
Definition: nbtree.h:109
#define MAXALIGN(LEN)
Definition: c.h:753
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
BTCycleId btpo_cycleid
Definition: btreefuncs.c:82
uint16 btpo_flags
Definition: btreefuncs.c:81
#define IndexTupleHasVarwidths(itup)
Definition: itup.h:73
#define INT64_FORMAT
Definition: c.h:471
static void GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat)
Definition: btreefuncs.c:93
#define P_HIKEY
Definition: nbtree.h:242
static Datum values[MAXATTR]
Definition: bootstrap.c:165
PG_FUNCTION_INFO_V1(bt_metap)
#define Int32GetDatum(X)
Definition: postgres.h:479
void * user_fctx
Definition: funcapi.h:82
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:902
uint32 btm_level
Definition: nbtree.h:103
uint32 page_size
Definition: btreefuncs.c:67
#define elog(elevel,...)
Definition: elog.h:228
int i
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
#define CStringGetTextDatum(s)
Definition: builtins.h:86
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
Definition: nbtree.h:386
Definition: c.h:617
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
TupleDesc tupd
Definition: btreefuncs.c:252
#define ItemPointerGetDatum(X)
Definition: btreefuncs.c:51
TransactionId btm_oldest_btpo_xact
Definition: nbtree.h:107
unsigned short t_info
Definition: itup.h:49
uint32 level
Definition: btreefuncs.c:78
uint16 btpo_flags
Definition: nbtree.h:65
int Buffer
Definition: buf.h:23
#define P_RIGHTMOST(opaque)
Definition: nbtree.h:213
uint64 max_calls
Definition: funcapi.h:74
#define PageGetItem(page, itemId)
Definition: bufpage.h:340
Pointer Page
Definition: bufpage.h:78
#define stat
Definition: win32_port.h:275
#define IndexTupleSize(itup)
Definition: itup.h:71
#define IS_INDEX(r)
Definition: btreefuncs.c:48
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:318
#define P_ISLEAF(opaque)
Definition: nbtree.h:214
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:296
bool rightmost
Definition: btreefuncs.c:251