PostgreSQL Source Code  git master
btreefuncs.c File Reference
#include "postgres.h"
#include "access/nbtree.h"
#include "access/relation.h"
#include "catalog/namespace.h"
#include "catalog/pg_am.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pageinspect.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/rel.h"
#include "utils/varlena.h"
Include dependency graph for btreefuncs.c:

Go to the source code of this file.

Data Structures

struct  BTPageStat
 
struct  ua_page_stats
 
struct  ua_page_items
 

Macros

#define IS_INDEX(r)   ((r)->rd_rel->relkind == RELKIND_INDEX)
 
#define IS_BTREE(r)   ((r)->rd_rel->relam == BTREE_AM_OID)
 
#define BT_METAP_COLS_V1_8   9
 

Typedefs

typedef struct BTPageStat BTPageStat
 
typedef struct ua_page_stats ua_page_stats
 
typedef struct ua_page_items ua_page_items
 

Functions

 PG_FUNCTION_INFO_V1 (bt_metap)
 
 PG_FUNCTION_INFO_V1 (bt_page_items_1_9)
 
 PG_FUNCTION_INFO_V1 (bt_page_items)
 
 PG_FUNCTION_INFO_V1 (bt_page_items_bytea)
 
 PG_FUNCTION_INFO_V1 (bt_page_stats_1_9)
 
 PG_FUNCTION_INFO_V1 (bt_page_stats)
 
 PG_FUNCTION_INFO_V1 (bt_multi_page_stats)
 
static void GetBTPageStatistics (BlockNumber blkno, Buffer buffer, BTPageStat *stat)
 
static void check_relation_block_range (Relation rel, int64 blkno)
 
static void bt_index_block_validate (Relation rel, int64 blkno)
 
static Datum bt_page_stats_internal (PG_FUNCTION_ARGS, enum pageinspect_version ext_version)
 
Datum bt_page_stats_1_9 (PG_FUNCTION_ARGS)
 
Datum bt_page_stats (PG_FUNCTION_ARGS)
 
Datum bt_multi_page_stats (PG_FUNCTION_ARGS)
 
static Datum bt_page_print_tuples (ua_page_items *uargs)
 
static Datum bt_page_items_internal (PG_FUNCTION_ARGS, enum pageinspect_version ext_version)
 
Datum bt_page_items_1_9 (PG_FUNCTION_ARGS)
 
Datum bt_page_items (PG_FUNCTION_ARGS)
 
Datum bt_page_items_bytea (PG_FUNCTION_ARGS)
 
Datum bt_metap (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ BT_METAP_COLS_V1_8

#define BT_METAP_COLS_V1_8   9

Definition at line 829 of file btreefuncs.c.

◆ IS_BTREE

#define IS_BTREE (   r)    ((r)->rd_rel->relam == BTREE_AM_OID)

Definition at line 52 of file btreefuncs.c.

◆ IS_INDEX

#define IS_INDEX (   r)    ((r)->rd_rel->relkind == RELKIND_INDEX)

Definition at line 51 of file btreefuncs.c.

Typedef Documentation

◆ BTPageStat

typedef struct BTPageStat BTPageStat

◆ ua_page_items

typedef struct ua_page_items ua_page_items

◆ ua_page_stats

typedef struct ua_page_stats ua_page_stats

Function Documentation

◆ bt_index_block_validate()

static void bt_index_block_validate ( Relation  rel,
int64  blkno 
)
static

Definition at line 227 of file btreefuncs.c.

228 {
229  if (!IS_INDEX(rel) || !IS_BTREE(rel))
230  ereport(ERROR,
231  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
232  errmsg("\"%s\" is not a %s index",
233  RelationGetRelationName(rel), "btree")));
234 
235  /*
236  * Reject attempts to read non-local temporary relations; we would be
237  * likely to get wrong data since we have no visibility into the owning
238  * session's local buffers.
239  */
240  if (RELATION_IS_OTHER_TEMP(rel))
241  ereport(ERROR,
242  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
243  errmsg("cannot access temporary tables of other sessions")));
244 
245  if (blkno == 0)
246  ereport(ERROR,
247  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
248  errmsg("block 0 is a meta page")));
249 
250  check_relation_block_range(rel, blkno);
251 }
#define IS_BTREE(r)
Definition: btreefuncs.c:52
static void check_relation_block_range(Relation rel, int64 blkno)
Definition: btreefuncs.c:203
#define IS_INDEX(r)
Definition: btreefuncs.c:51
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define RelationGetRelationName(relation)
Definition: rel.h:541
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:660

References check_relation_block_range(), ereport, errcode(), errmsg(), ERROR, IS_BTREE, IS_INDEX, RELATION_IS_OTHER_TEMP, and RelationGetRelationName.

Referenced by bt_multi_page_stats(), bt_page_items_internal(), and bt_page_stats_internal().

◆ bt_metap()

Datum bt_metap ( PG_FUNCTION_ARGS  )

Definition at line 840 of file btreefuncs.c.

841 {
843  Datum result;
844  Relation rel;
845  RangeVar *relrv;
846  BTMetaPageData *metad;
847  TupleDesc tupleDesc;
848  int j;
849  char *values[9];
850  Buffer buffer;
851  Page page;
852  HeapTuple tuple;
853 
854  if (!superuser())
855  ereport(ERROR,
856  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
857  errmsg("must be superuser to use pageinspect functions")));
858 
860  rel = relation_openrv(relrv, AccessShareLock);
861 
862  if (!IS_INDEX(rel) || !IS_BTREE(rel))
863  ereport(ERROR,
864  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
865  errmsg("\"%s\" is not a %s index",
866  RelationGetRelationName(rel), "btree")));
867 
868  /*
869  * Reject attempts to read non-local temporary relations; we would be
870  * likely to get wrong data since we have no visibility into the owning
871  * session's local buffers.
872  */
873  if (RELATION_IS_OTHER_TEMP(rel))
874  ereport(ERROR,
875  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
876  errmsg("cannot access temporary tables of other sessions")));
877 
878  buffer = ReadBuffer(rel, 0);
879  LockBuffer(buffer, BUFFER_LOCK_SHARE);
880 
881  page = BufferGetPage(buffer);
882  metad = BTPageGetMeta(page);
883 
884  /* Build a tuple descriptor for our result type */
885  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
886  elog(ERROR, "return type must be a row type");
887 
888  /*
889  * We need a kluge here to detect API versions prior to 1.8. Earlier
890  * versions incorrectly used int4 for certain columns.
891  *
892  * There is no way to reliably avoid the problems created by the old
893  * function definition at this point, so insist that the user update the
894  * extension.
895  */
896  if (tupleDesc->natts < BT_METAP_COLS_V1_8)
897  ereport(ERROR,
898  (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
899  errmsg("function has wrong number of declared columns"),
900  errhint("To resolve the problem, update the \"pageinspect\" extension to the latest version.")));
901 
902  j = 0;
903  values[j++] = psprintf("%d", metad->btm_magic);
904  values[j++] = psprintf("%d", metad->btm_version);
905  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_root);
906  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_level);
907  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastroot);
908  values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastlevel);
909 
910  /*
911  * Get values of extended metadata if available, use default values
912  * otherwise. Note that we rely on the assumption that btm_allequalimage
913  * is initialized to zero with indexes that were built on versions prior
914  * to Postgres 13 (just like _bt_metaversion()).
915  */
916  if (metad->btm_version >= BTREE_NOVAC_VERSION)
917  {
919  (int64) metad->btm_last_cleanup_num_delpages);
921  values[j++] = metad->btm_allequalimage ? "t" : "f";
922  }
923  else
924  {
925  values[j++] = "0";
926  values[j++] = "-1";
927  values[j++] = "f";
928  }
929 
931  values);
932 
933  result = HeapTupleGetDatum(tuple);
934 
935  UnlockReleaseBuffer(buffer);
937 
938  PG_RETURN_DATUM(result);
939 }
static Datum values[MAXATTR]
Definition: bootstrap.c:152
#define BT_METAP_COLS_V1_8
Definition: btreefuncs.c:829
int Buffer
Definition: buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4577
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4795
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:734
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:158
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:350
Pointer Page
Definition: bufpage.h:78
#define INT64_FORMAT
Definition: c.h:535
int errhint(const char *fmt,...)
Definition: elog.c:1319
#define elog(elevel,...)
Definition: elog.h:224
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2222
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2173
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
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
int j
Definition: isn.c:74
#define AccessShareLock
Definition: lockdefs.h:36
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3539
#define BTPageGetMeta(p)
Definition: nbtree.h:121
#define BTREE_NOVAC_VERSION
Definition: nbtree.h:152
NameData relname
Definition: pg_class.h:38
uintptr_t Datum
Definition: postgres.h:64
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:137
uint32 btm_last_cleanup_num_delpages
Definition: nbtree.h:114
uint32 btm_level
Definition: nbtree.h:108
float8 btm_last_cleanup_num_heap_tuples
Definition: nbtree.h:116
BlockNumber btm_fastroot
Definition: nbtree.h:109
uint32 btm_version
Definition: nbtree.h:106
uint32 btm_magic
Definition: nbtree.h:105
BlockNumber btm_root
Definition: nbtree.h:107
bool btm_allequalimage
Definition: nbtree.h:118
uint32 btm_fastlevel
Definition: nbtree.h:110
Definition: c.h:674
bool superuser(void)
Definition: superuser.c:46
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3399

References AccessShareLock, BT_METAP_COLS_V1_8, BTMetaPageData::btm_allequalimage, BTMetaPageData::btm_fastlevel, BTMetaPageData::btm_fastroot, BTMetaPageData::btm_last_cleanup_num_delpages, BTMetaPageData::btm_last_cleanup_num_heap_tuples, BTMetaPageData::btm_level, BTMetaPageData::btm_magic, BTMetaPageData::btm_root, BTMetaPageData::btm_version, BTPageGetMeta, BTREE_NOVAC_VERSION, BUFFER_LOCK_SHARE, BufferGetPage(), BuildTupleFromCStrings(), elog, ereport, errcode(), errhint(), errmsg(), ERROR, get_call_result_type(), HeapTupleGetDatum(), INT64_FORMAT, IS_BTREE, IS_INDEX, j, LockBuffer(), makeRangeVarFromNameList(), TupleDescData::natts, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, psprintf(), ReadBuffer(), relation_close(), RELATION_IS_OTHER_TEMP, relation_openrv(), RelationGetRelationName, relname, superuser(), textToQualifiedNameList(), TupleDescGetAttInMetadata(), TYPEFUNC_COMPOSITE, UnlockReleaseBuffer(), and values.

◆ bt_multi_page_stats()

Datum bt_multi_page_stats ( PG_FUNCTION_ARGS  )

Definition at line 345 of file btreefuncs.c.

346 {
347  Relation rel;
348  ua_page_stats *uargs;
349  FuncCallContext *fctx;
350  MemoryContext mctx;
351 
352  if (!superuser())
353  ereport(ERROR,
354  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
355  errmsg("must be superuser to use pageinspect functions")));
356 
357  if (SRF_IS_FIRSTCALL())
358  {
360  int64 blkno = PG_GETARG_INT64(1);
361  int64 blk_count = PG_GETARG_INT64(2);
362  RangeVar *relrv;
363 
364  fctx = SRF_FIRSTCALL_INIT();
365 
367  rel = relation_openrv(relrv, AccessShareLock);
368 
369  /* Check that rel is a valid btree index and 1st block number is OK */
370  bt_index_block_validate(rel, blkno);
371 
372  /*
373  * Check if upper bound of the specified range is valid. If only one
374  * page is requested, skip as we've already validated the page. (Also,
375  * it's important to skip this if blk_count is negative.)
376  */
377  if (blk_count > 1)
378  check_relation_block_range(rel, blkno + blk_count - 1);
379 
380  /* Save arguments for reuse */
382 
383  uargs = palloc(sizeof(ua_page_stats));
384 
385  uargs->relid = RelationGetRelid(rel);
386  uargs->blkno = blkno;
387  uargs->blk_count = blk_count;
388  uargs->allpages = (blk_count < 0);
389 
390  fctx->user_fctx = uargs;
391 
392  MemoryContextSwitchTo(mctx);
393 
394  /*
395  * To avoid possibly leaking a relcache reference if the SRF isn't run
396  * to completion, we close and re-open the index rel each time
397  * through, using the index's OID for re-opens to ensure we get the
398  * same rel. Keep the AccessShareLock though, to ensure it doesn't go
399  * away underneath us.
400  */
401  relation_close(rel, NoLock);
402  }
403 
404  fctx = SRF_PERCALL_SETUP();
405  uargs = fctx->user_fctx;
406 
407  /* We should have lock already */
408  rel = relation_open(uargs->relid, NoLock);
409 
410  /* In all-pages mode, recheck the index length each time */
411  if (uargs->allpages)
412  uargs->blk_count = RelationGetNumberOfBlocks(rel) - uargs->blkno;
413 
414  if (uargs->blk_count > 0)
415  {
416  /* We need to fetch next block statistics */
417  Buffer buffer;
418  Datum result;
419  HeapTuple tuple;
420  int j;
421  char *values[11];
423  TupleDesc tupleDesc;
424 
425  buffer = ReadBuffer(rel, uargs->blkno);
426  LockBuffer(buffer, BUFFER_LOCK_SHARE);
427 
428  /* keep compiler quiet */
429  stat.btpo_prev = stat.btpo_next = InvalidBlockNumber;
430  stat.btpo_flags = stat.free_size = stat.avg_item_size = 0;
431 
432  GetBTPageStatistics(uargs->blkno, buffer, &stat);
433 
434  UnlockReleaseBuffer(buffer);
435  relation_close(rel, NoLock);
436 
437  /* Build a tuple descriptor for our result type */
438  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
439  elog(ERROR, "return type must be a row type");
440 
441  j = 0;
442  values[j++] = psprintf("%u", stat.blkno);
443  values[j++] = psprintf("%c", stat.type);
444  values[j++] = psprintf("%u", stat.live_items);
445  values[j++] = psprintf("%u", stat.dead_items);
446  values[j++] = psprintf("%u", stat.avg_item_size);
447  values[j++] = psprintf("%u", stat.page_size);
448  values[j++] = psprintf("%u", stat.free_size);
449  values[j++] = psprintf("%u", stat.btpo_prev);
450  values[j++] = psprintf("%u", stat.btpo_next);
451  values[j++] = psprintf("%u", stat.btpo_level);
452  values[j++] = psprintf("%d", stat.btpo_flags);
453 
454  /* Construct tuple to be returned */
456  values);
457 
458  result = HeapTupleGetDatum(tuple);
459 
460  /*
461  * Move to the next block number and decrement the number of blocks
462  * still to be fetched
463  */
464  uargs->blkno++;
465  uargs->blk_count--;
466 
467  SRF_RETURN_NEXT(fctx, result);
468  }
469 
470  /* Done, so finally we can release the index lock */
472  SRF_RETURN_DONE(fctx);
473 }
#define InvalidBlockNumber
Definition: block.h:33
static void bt_index_block_validate(Relation rel, int64 blkno)
Definition: btreefuncs.c:227
static void GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat *stat)
Definition: btreefuncs.c:108
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:229
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:306
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:328
#define NoLock
Definition: lockdefs.h:34
void * palloc(Size size)
Definition: mcxt.c:1304
MemoryContextSwitchTo(old_ctx)
#define RelationGetRelid(relation)
Definition: rel.h:507
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
int64 blk_count
Definition: btreefuncs.c:84
#define stat
Definition: win32_port.h:284

References AccessShareLock, ua_page_stats::allpages, ua_page_stats::blk_count, ua_page_stats::blkno, bt_index_block_validate(), BUFFER_LOCK_SHARE, BuildTupleFromCStrings(), check_relation_block_range(), elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), GetBTPageStatistics(), HeapTupleGetDatum(), InvalidBlockNumber, j, LockBuffer(), makeRangeVarFromNameList(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, NoLock, palloc(), PG_GETARG_INT64, PG_GETARG_TEXT_PP, psprintf(), ReadBuffer(), relation_close(), relation_open(), relation_openrv(), RelationGetNumberOfBlocks, RelationGetRelid, ua_page_stats::relid, relname, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, stat, superuser(), textToQualifiedNameList(), TupleDescGetAttInMetadata(), TYPEFUNC_COMPOSITE, UnlockReleaseBuffer(), FuncCallContext::user_fctx, and values.

◆ bt_page_items()

Datum bt_page_items ( PG_FUNCTION_ARGS  )

Definition at line 720 of file btreefuncs.c.

721 {
723 }
static Datum bt_page_items_internal(PG_FUNCTION_ARGS, enum pageinspect_version ext_version)
Definition: btreefuncs.c:625
@ PAGEINSPECT_V1_8
Definition: pageinspect.h:23

References bt_page_items_internal(), and PAGEINSPECT_V1_8.

◆ bt_page_items_1_9()

Datum bt_page_items_1_9 ( PG_FUNCTION_ARGS  )

Definition at line 713 of file btreefuncs.c.

714 {
716 }
@ PAGEINSPECT_V1_9
Definition: pageinspect.h:24

References bt_page_items_internal(), and PAGEINSPECT_V1_9.

◆ bt_page_items_bytea()

Datum bt_page_items_bytea ( PG_FUNCTION_ARGS  )

Definition at line 735 of file btreefuncs.c.

736 {
737  bytea *raw_page = PG_GETARG_BYTEA_P(0);
738  Datum result;
739  FuncCallContext *fctx;
740  ua_page_items *uargs;
741 
742  if (!superuser())
743  ereport(ERROR,
744  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
745  errmsg("must be superuser to use raw page functions")));
746 
747  if (SRF_IS_FIRSTCALL())
748  {
749  BTPageOpaque opaque;
750  MemoryContext mctx;
751  TupleDesc tupleDesc;
752 
753  fctx = SRF_FIRSTCALL_INIT();
755 
756  uargs = palloc(sizeof(ua_page_items));
757 
758  uargs->page = get_page_from_raw(raw_page);
759 
760  if (PageIsNew(uargs->page))
761  {
762  MemoryContextSwitchTo(mctx);
763  PG_RETURN_NULL();
764  }
765 
766  uargs->offset = FirstOffsetNumber;
767 
768  /* verify the special space has the expected size */
769  if (PageGetSpecialSize(uargs->page) != MAXALIGN(sizeof(BTPageOpaqueData)))
770  ereport(ERROR,
771  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
772  errmsg("input page is not a valid %s page", "btree"),
773  errdetail("Expected special size %d, got %d.",
774  (int) MAXALIGN(sizeof(BTPageOpaqueData)),
775  (int) PageGetSpecialSize(uargs->page))));
776 
777  opaque = BTPageGetOpaque(uargs->page);
778 
779  if (P_ISMETA(opaque))
780  ereport(ERROR,
781  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
782  errmsg("block is a meta page")));
783 
784  if (P_ISLEAF(opaque) && opaque->btpo_level != 0)
785  ereport(ERROR,
786  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
787  errmsg("block is not a valid btree leaf page")));
788 
789  if (P_ISDELETED(opaque))
790  elog(NOTICE, "page is deleted");
791 
792  if (!P_ISDELETED(opaque))
793  fctx->max_calls = PageGetMaxOffsetNumber(uargs->page);
794  else
795  {
796  /* Don't interpret BTDeletedPageData as index tuples */
797  elog(NOTICE, "page from block is deleted");
798  fctx->max_calls = 0;
799  }
800  uargs->leafpage = P_ISLEAF(opaque);
801  uargs->rightmost = P_RIGHTMOST(opaque);
802 
803  /* Build a tuple descriptor for our result type */
804  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
805  elog(ERROR, "return type must be a row type");
806  tupleDesc = BlessTupleDesc(tupleDesc);
807 
808  uargs->tupd = tupleDesc;
809 
810  fctx->user_fctx = uargs;
811 
812  MemoryContextSwitchTo(mctx);
813  }
814 
815  fctx = SRF_PERCALL_SETUP();
816  uargs = fctx->user_fctx;
817 
818  if (fctx->call_cntr < fctx->max_calls)
819  {
820  result = bt_page_print_tuples(uargs);
821  uargs->offset++;
822  SRF_RETURN_NEXT(fctx, result);
823  }
824 
825  SRF_RETURN_DONE(fctx);
826 }
static Datum bt_page_print_tuples(ua_page_items *uargs)
Definition: btreefuncs.c:482
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:798
int errdetail(const char *fmt,...)
Definition: elog.c:1205
#define NOTICE
Definition: elog.h:35
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2158
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_GETARG_BYTEA_P(n)
Definition: fmgr.h:335
#define P_ISLEAF(opaque)
Definition: nbtree.h:220
#define P_ISMETA(opaque)
Definition: nbtree.h:223
#define BTPageGetOpaque(page)
Definition: nbtree.h:73
#define P_ISDELETED(opaque)
Definition: nbtree.h:222
#define P_RIGHTMOST(opaque)
Definition: nbtree.h:219
#define FirstOffsetNumber
Definition: off.h:27
Page get_page_from_raw(bytea *raw_page)
Definition: rawpage.c:215
uint32 btpo_level
Definition: nbtree.h:66
uint64 max_calls
Definition: funcapi.h:74
uint64 call_cntr
Definition: funcapi.h:65
OffsetNumber offset
Definition: btreefuncs.c:94
TupleDesc tupd
Definition: btreefuncs.c:97
bool rightmost
Definition: btreefuncs.c:96

References BlessTupleDesc(), bt_page_print_tuples(), BTPageGetOpaque, BTPageOpaqueData::btpo_level, FuncCallContext::call_cntr, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, FirstOffsetNumber, get_call_result_type(), get_page_from_raw(), ua_page_items::leafpage, FuncCallContext::max_calls, MAXALIGN, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, NOTICE, ua_page_items::offset, P_ISDELETED, P_ISLEAF, P_ISMETA, P_RIGHTMOST, ua_page_items::page, PageGetMaxOffsetNumber(), PageGetSpecialSize(), PageIsNew(), palloc(), PG_GETARG_BYTEA_P, PG_RETURN_NULL, ua_page_items::rightmost, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, superuser(), ua_page_items::tupd, TYPEFUNC_COMPOSITE, and FuncCallContext::user_fctx.

◆ bt_page_items_internal()

static Datum bt_page_items_internal ( PG_FUNCTION_ARGS  ,
enum pageinspect_version  ext_version 
)
static

Definition at line 625 of file btreefuncs.c.

626 {
628  int64 blkno = (ext_version == PAGEINSPECT_V1_8 ? PG_GETARG_UINT32(1) : PG_GETARG_INT64(1));
629  Datum result;
630  FuncCallContext *fctx;
631  MemoryContext mctx;
632  ua_page_items *uargs;
633 
634  if (!superuser())
635  ereport(ERROR,
636  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
637  errmsg("must be superuser to use pageinspect functions")));
638 
639  if (SRF_IS_FIRSTCALL())
640  {
641  RangeVar *relrv;
642  Relation rel;
643  Buffer buffer;
644  BTPageOpaque opaque;
645  TupleDesc tupleDesc;
646 
647  fctx = SRF_FIRSTCALL_INIT();
648 
650  rel = relation_openrv(relrv, AccessShareLock);
651 
652  bt_index_block_validate(rel, blkno);
653 
654  buffer = ReadBuffer(rel, blkno);
655  LockBuffer(buffer, BUFFER_LOCK_SHARE);
656 
657  /*
658  * We copy the page into local storage to avoid holding pin on the
659  * buffer longer than we must, and possibly failing to release it at
660  * all if the calling query doesn't fetch all rows.
661  */
663 
664  uargs = palloc(sizeof(ua_page_items));
665 
666  uargs->page = palloc(BLCKSZ);
667  memcpy(uargs->page, BufferGetPage(buffer), BLCKSZ);
668 
669  UnlockReleaseBuffer(buffer);
671 
672  uargs->offset = FirstOffsetNumber;
673 
674  opaque = BTPageGetOpaque(uargs->page);
675 
676  if (!P_ISDELETED(opaque))
677  fctx->max_calls = PageGetMaxOffsetNumber(uargs->page);
678  else
679  {
680  /* Don't interpret BTDeletedPageData as index tuples */
681  elog(NOTICE, "page from block " INT64_FORMAT " is deleted", blkno);
682  fctx->max_calls = 0;
683  }
684  uargs->leafpage = P_ISLEAF(opaque);
685  uargs->rightmost = P_RIGHTMOST(opaque);
686 
687  /* Build a tuple descriptor for our result type */
688  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
689  elog(ERROR, "return type must be a row type");
690  tupleDesc = BlessTupleDesc(tupleDesc);
691 
692  uargs->tupd = tupleDesc;
693 
694  fctx->user_fctx = uargs;
695 
696  MemoryContextSwitchTo(mctx);
697  }
698 
699  fctx = SRF_PERCALL_SETUP();
700  uargs = fctx->user_fctx;
701 
702  if (fctx->call_cntr < fctx->max_calls)
703  {
704  result = bt_page_print_tuples(uargs);
705  uargs->offset++;
706  SRF_RETURN_NEXT(fctx, result);
707  }
708 
709  SRF_RETURN_DONE(fctx);
710 }
#define PG_GETARG_UINT32(n)
Definition: fmgr.h:270

References AccessShareLock, BlessTupleDesc(), bt_index_block_validate(), bt_page_print_tuples(), BTPageGetOpaque, BUFFER_LOCK_SHARE, BufferGetPage(), FuncCallContext::call_cntr, elog, ereport, errcode(), errmsg(), ERROR, FirstOffsetNumber, get_call_result_type(), INT64_FORMAT, ua_page_items::leafpage, LockBuffer(), makeRangeVarFromNameList(), FuncCallContext::max_calls, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, NOTICE, ua_page_items::offset, P_ISDELETED, P_ISLEAF, P_RIGHTMOST, ua_page_items::page, PageGetMaxOffsetNumber(), PAGEINSPECT_V1_8, palloc(), PG_GETARG_INT64, PG_GETARG_TEXT_PP, PG_GETARG_UINT32, ReadBuffer(), relation_close(), relation_openrv(), relname, ua_page_items::rightmost, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, superuser(), textToQualifiedNameList(), ua_page_items::tupd, TYPEFUNC_COMPOSITE, UnlockReleaseBuffer(), and FuncCallContext::user_fctx.

Referenced by bt_page_items(), and bt_page_items_1_9().

◆ bt_page_print_tuples()

static Datum bt_page_print_tuples ( ua_page_items uargs)
static

Definition at line 482 of file btreefuncs.c.

483 {
484  Page page = uargs->page;
485  OffsetNumber offset = uargs->offset;
486  bool leafpage = uargs->leafpage;
487  bool rightmost = uargs->rightmost;
488  bool ispivottuple;
489  Datum values[9];
490  bool nulls[9];
491  HeapTuple tuple;
492  ItemId id;
493  IndexTuple itup;
494  int j;
495  int off;
496  int dlen;
497  char *dump,
498  *datacstring;
499  char *ptr;
500  ItemPointer htid;
501 
502  id = PageGetItemId(page, offset);
503 
504  if (!ItemIdIsValid(id))
505  elog(ERROR, "invalid ItemId");
506 
507  itup = (IndexTuple) PageGetItem(page, id);
508 
509  j = 0;
510  memset(nulls, 0, sizeof(nulls));
511  values[j++] = DatumGetInt16(offset);
512  values[j++] = ItemPointerGetDatum(&itup->t_tid);
513  values[j++] = Int32GetDatum((int) IndexTupleSize(itup));
516 
517  ptr = (char *) itup + IndexInfoFindDataOffset(itup->t_info);
518  dlen = IndexTupleSize(itup) - IndexInfoFindDataOffset(itup->t_info);
519 
520  /*
521  * Make sure that "data" column does not include posting list or pivot
522  * tuple representation of heap TID(s).
523  *
524  * Note: BTreeTupleIsPivot() won't work reliably on !heapkeyspace indexes
525  * (those built before BTREE_VERSION 4), but we have no way of determining
526  * if this page came from a !heapkeyspace index. We may only have a bytea
527  * nbtree page image to go on, so in general there is no metapage that we
528  * can check.
529  *
530  * That's okay here because BTreeTupleIsPivot() can only return false for
531  * a !heapkeyspace pivot, never true for a !heapkeyspace non-pivot. Since
532  * heap TID isn't part of the keyspace in a !heapkeyspace index anyway,
533  * there cannot possibly be a pivot tuple heap TID representation that we
534  * fail to make an adjustment for. A !heapkeyspace index can have
535  * BTreeTupleIsPivot() return true (due to things like suffix truncation
536  * for INCLUDE indexes in Postgres v11), but when that happens
537  * BTreeTupleGetHeapTID() can be trusted to work reliably (i.e. return
538  * NULL).
539  *
540  * Note: BTreeTupleIsPosting() always works reliably, even with
541  * !heapkeyspace indexes.
542  */
543  if (BTreeTupleIsPosting(itup))
544  dlen -= IndexTupleSize(itup) - BTreeTupleGetPostingOffset(itup);
545  else if (BTreeTupleIsPivot(itup) && BTreeTupleGetHeapTID(itup) != NULL)
546  dlen -= MAXALIGN(sizeof(ItemPointerData));
547 
548  if (dlen < 0 || dlen > INDEX_SIZE_MASK)
549  elog(ERROR, "invalid tuple length %d for tuple at offset number %u",
550  dlen, offset);
551  dump = palloc0(dlen * 3 + 1);
552  datacstring = dump;
553  for (off = 0; off < dlen; off++)
554  {
555  if (off > 0)
556  *dump++ = ' ';
557  sprintf(dump, "%02x", *(ptr + off) & 0xff);
558  dump += 2;
559  }
560  values[j++] = CStringGetTextDatum(datacstring);
561  pfree(datacstring);
562 
563  /*
564  * We need to work around the BTreeTupleIsPivot() !heapkeyspace limitation
565  * again. Deduce whether or not tuple must be a pivot tuple based on
566  * whether or not the page is a leaf page, as well as the page offset
567  * number of the tuple.
568  */
569  ispivottuple = (!leafpage || (!rightmost && offset == P_HIKEY));
570 
571  /* LP_DEAD bit can never be set for pivot tuples, so show a NULL there */
572  if (!ispivottuple)
573  values[j++] = BoolGetDatum(ItemIdIsDead(id));
574  else
575  {
576  Assert(!ItemIdIsDead(id));
577  nulls[j++] = true;
578  }
579 
580  htid = BTreeTupleGetHeapTID(itup);
581  if (ispivottuple && !BTreeTupleIsPivot(itup))
582  {
583  /* Don't show bogus heap TID in !heapkeyspace pivot tuple */
584  htid = NULL;
585  }
586 
587  if (htid)
588  values[j++] = ItemPointerGetDatum(htid);
589  else
590  nulls[j++] = true;
591 
592  if (BTreeTupleIsPosting(itup))
593  {
594  /* Build an array of item pointers */
595  ItemPointer tids;
596  Datum *tids_datum;
597  int nposting;
598 
599  tids = BTreeTupleGetPosting(itup);
600  nposting = BTreeTupleGetNPosting(itup);
601  tids_datum = (Datum *) palloc(nposting * sizeof(Datum));
602  for (int i = 0; i < nposting; i++)
603  tids_datum[i] = ItemPointerGetDatum(&tids[i]);
604  values[j++] = PointerGetDatum(construct_array_builtin(tids_datum, nposting, TIDOID));
605  pfree(tids_datum);
606  }
607  else
608  nulls[j++] = true;
609 
610  /* Build and return the result tuple */
611  tuple = heap_form_tuple(uargs->tupd, values, nulls);
612 
613  return HeapTupleGetDatum(tuple);
614 }
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3374
static Item PageGetItem(Page page, ItemId itemId)
Definition: bufpage.h:351
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:240
#define CStringGetTextDatum(s)
Definition: builtins.h:97
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
int i
Definition: isn.c:73
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define ItemIdIsValid(itemId)
Definition: itemid.h:86
static Datum ItemPointerGetDatum(const ItemPointerData *X)
Definition: itemptr.h:237
#define IndexTupleHasVarwidths(itup)
Definition: itup.h:72
#define IndexTupleHasNulls(itup)
Definition: itup.h:71
IndexTupleData * IndexTuple
Definition: itup.h:53
#define IndexTupleSize(itup)
Definition: itup.h:70
static Size IndexInfoFindDataOffset(unsigned short t_info)
Definition: itup.h:98
#define INDEX_SIZE_MASK
Definition: itup.h:65
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
Definition: mcxt.c:1508
void * palloc0(Size size)
Definition: mcxt.c:1334
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
Definition: nbtree.h:518
static bool BTreeTupleIsPivot(IndexTuple itup)
Definition: nbtree.h:480
#define P_HIKEY
Definition: nbtree.h:367
static ItemPointer BTreeTupleGetPosting(IndexTuple posting)
Definition: nbtree.h:537
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
Definition: nbtree.h:529
static bool BTreeTupleIsPosting(IndexTuple itup)
Definition: nbtree.h:492
static ItemPointer BTreeTupleGetHeapTID(IndexTuple itup)
Definition: nbtree.h:638
uint16 OffsetNumber
Definition: off.h:24
#define sprintf
Definition: port.h:240
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static int16 DatumGetInt16(Datum X)
Definition: postgres.h:162
ItemPointerData t_tid
Definition: itup.h:37
unsigned short t_info
Definition: itup.h:49

References Assert(), BoolGetDatum(), BTreeTupleGetHeapTID(), BTreeTupleGetNPosting(), BTreeTupleGetPosting(), BTreeTupleGetPostingOffset(), BTreeTupleIsPivot(), BTreeTupleIsPosting(), construct_array_builtin(), CStringGetTextDatum, DatumGetInt16(), elog, ERROR, heap_form_tuple(), HeapTupleGetDatum(), i, INDEX_SIZE_MASK, IndexInfoFindDataOffset(), IndexTupleHasNulls, IndexTupleHasVarwidths, IndexTupleSize, Int32GetDatum(), ItemIdIsDead, ItemIdIsValid, ItemPointerGetDatum(), j, ua_page_items::leafpage, MAXALIGN, ua_page_items::offset, P_HIKEY, ua_page_items::page, PageGetItem(), PageGetItemId(), palloc(), palloc0(), pfree(), PointerGetDatum(), ua_page_items::rightmost, sprintf, IndexTupleData::t_info, IndexTupleData::t_tid, ua_page_items::tupd, and values.

Referenced by bt_page_items_bytea(), and bt_page_items_internal().

◆ bt_page_stats()

Datum bt_page_stats ( PG_FUNCTION_ARGS  )

Definition at line 330 of file btreefuncs.c.

331 {
333 }
static Datum bt_page_stats_internal(PG_FUNCTION_ARGS, enum pageinspect_version ext_version)
Definition: btreefuncs.c:261

References bt_page_stats_internal(), and PAGEINSPECT_V1_8.

◆ bt_page_stats_1_9()

Datum bt_page_stats_1_9 ( PG_FUNCTION_ARGS  )

Definition at line 323 of file btreefuncs.c.

324 {
326 }

References bt_page_stats_internal(), and PAGEINSPECT_V1_9.

◆ bt_page_stats_internal()

static Datum bt_page_stats_internal ( PG_FUNCTION_ARGS  ,
enum pageinspect_version  ext_version 
)
static

Definition at line 261 of file btreefuncs.c.

262 {
264  int64 blkno = (ext_version == PAGEINSPECT_V1_8 ? PG_GETARG_UINT32(1) : PG_GETARG_INT64(1));
265  Buffer buffer;
266  Relation rel;
267  RangeVar *relrv;
268  Datum result;
269  HeapTuple tuple;
270  TupleDesc tupleDesc;
271  int j;
272  char *values[11];
274 
275  if (!superuser())
276  ereport(ERROR,
277  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
278  errmsg("must be superuser to use pageinspect functions")));
279 
281  rel = relation_openrv(relrv, AccessShareLock);
282 
283  bt_index_block_validate(rel, blkno);
284 
285  buffer = ReadBuffer(rel, blkno);
286  LockBuffer(buffer, BUFFER_LOCK_SHARE);
287 
288  /* keep compiler quiet */
289  stat.btpo_prev = stat.btpo_next = InvalidBlockNumber;
290  stat.btpo_flags = stat.free_size = stat.avg_item_size = 0;
291 
292  GetBTPageStatistics(blkno, buffer, &stat);
293 
294  UnlockReleaseBuffer(buffer);
296 
297  /* Build a tuple descriptor for our result type */
298  if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
299  elog(ERROR, "return type must be a row type");
300 
301  j = 0;
302  values[j++] = psprintf("%u", stat.blkno);
303  values[j++] = psprintf("%c", stat.type);
304  values[j++] = psprintf("%u", stat.live_items);
305  values[j++] = psprintf("%u", stat.dead_items);
306  values[j++] = psprintf("%u", stat.avg_item_size);
307  values[j++] = psprintf("%u", stat.page_size);
308  values[j++] = psprintf("%u", stat.free_size);
309  values[j++] = psprintf("%u", stat.btpo_prev);
310  values[j++] = psprintf("%u", stat.btpo_next);
311  values[j++] = psprintf("%u", stat.btpo_level);
312  values[j++] = psprintf("%d", stat.btpo_flags);
313 
315  values);
316 
317  result = HeapTupleGetDatum(tuple);
318 
319  PG_RETURN_DATUM(result);
320 }

References AccessShareLock, bt_index_block_validate(), BUFFER_LOCK_SHARE, BuildTupleFromCStrings(), elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), GetBTPageStatistics(), HeapTupleGetDatum(), InvalidBlockNumber, j, LockBuffer(), makeRangeVarFromNameList(), PAGEINSPECT_V1_8, PG_GETARG_INT64, PG_GETARG_TEXT_PP, PG_GETARG_UINT32, PG_RETURN_DATUM, psprintf(), ReadBuffer(), relation_close(), relation_openrv(), relname, stat, superuser(), textToQualifiedNameList(), TupleDescGetAttInMetadata(), TYPEFUNC_COMPOSITE, UnlockReleaseBuffer(), and values.

Referenced by bt_page_stats(), and bt_page_stats_1_9().

◆ check_relation_block_range()

static void check_relation_block_range ( Relation  rel,
int64  blkno 
)
static

Definition at line 203 of file btreefuncs.c.

204 {
205  /* Ensure we can cast to BlockNumber */
206  if (blkno < 0 || blkno > MaxBlockNumber)
207  ereport(ERROR,
208  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
209  errmsg("invalid block number %lld",
210  (long long) blkno)));
211 
212  if ((BlockNumber) (blkno) >= RelationGetNumberOfBlocks(rel))
213  ereport(ERROR,
214  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
215  errmsg("block number %lld is out of range",
216  (long long) blkno)));
217 }
uint32 BlockNumber
Definition: block.h:31
#define MaxBlockNumber
Definition: block.h:35

References ereport, errcode(), errmsg(), ERROR, MaxBlockNumber, and RelationGetNumberOfBlocks.

Referenced by bt_index_block_validate(), and bt_multi_page_stats().

◆ GetBTPageStatistics()

static void GetBTPageStatistics ( BlockNumber  blkno,
Buffer  buffer,
BTPageStat stat 
)
static

Definition at line 108 of file btreefuncs.c.

109 {
110  Page page = BufferGetPage(buffer);
111  PageHeader phdr = (PageHeader) page;
112  OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
113  BTPageOpaque opaque = BTPageGetOpaque(page);
114  int item_size = 0;
115  int off;
116 
117  stat->blkno = blkno;
118 
119  stat->max_avail = BLCKSZ - (BLCKSZ - phdr->pd_special + SizeOfPageHeaderData);
120 
121  stat->dead_items = stat->live_items = 0;
122 
123  stat->page_size = PageGetPageSize(page);
124 
125  /* page type (flags) */
126  if (P_ISDELETED(opaque))
127  {
128  /* We divide deleted pages into leaf ('d') or internal ('D') */
129  if (P_ISLEAF(opaque) || !P_HAS_FULLXID(opaque))
130  stat->type = 'd';
131  else
132  stat->type = 'D';
133 
134  /*
135  * Report safexid in a deleted page.
136  *
137  * Handle pg_upgrade'd deleted pages that used the previous safexid
138  * representation in btpo_level field (this used to be a union type
139  * called "bpto").
140  */
141  if (P_HAS_FULLXID(opaque))
142  {
143  FullTransactionId safexid = BTPageGetDeleteXid(page);
144 
145  elog(DEBUG2, "deleted page from block %u has safexid %u:%u",
146  blkno, EpochFromFullTransactionId(safexid),
147  XidFromFullTransactionId(safexid));
148  }
149  else
150  elog(DEBUG2, "deleted page from block %u has safexid %u",
151  blkno, opaque->btpo_level);
152 
153  /* Don't interpret BTDeletedPageData as index tuples */
154  maxoff = InvalidOffsetNumber;
155  }
156  else if (P_IGNORE(opaque))
157  stat->type = 'e';
158  else if (P_ISLEAF(opaque))
159  stat->type = 'l';
160  else if (P_ISROOT(opaque))
161  stat->type = 'r';
162  else
163  stat->type = 'i';
164 
165  /* btpage opaque data */
166  stat->btpo_prev = opaque->btpo_prev;
167  stat->btpo_next = opaque->btpo_next;
168  stat->btpo_level = opaque->btpo_level;
169  stat->btpo_flags = opaque->btpo_flags;
170  stat->btpo_cycleid = opaque->btpo_cycleid;
171 
172  /* count live and dead tuples, and free space */
173  for (off = FirstOffsetNumber; off <= maxoff; off++)
174  {
175  IndexTuple itup;
176 
177  ItemId id = PageGetItemId(page, off);
178 
179  itup = (IndexTuple) PageGetItem(page, id);
180 
181  item_size += IndexTupleSize(itup);
182 
183  if (!ItemIdIsDead(id))
184  stat->live_items++;
185  else
186  stat->dead_items++;
187  }
188  stat->free_size = PageGetFreeSpace(page);
189 
190  if ((stat->live_items + stat->dead_items) > 0)
191  stat->avg_item_size = item_size / (stat->live_items + stat->dead_items);
192  else
193  stat->avg_item_size = 0;
194 }
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:907
PageHeaderData * PageHeader
Definition: bufpage.h:170
static Size PageGetPageSize(Page page)
Definition: bufpage.h:273
#define SizeOfPageHeaderData
Definition: bufpage.h:213
#define DEBUG2
Definition: elog.h:29
#define P_HAS_FULLXID(opaque)
Definition: nbtree.h:228
static FullTransactionId BTPageGetDeleteXid(Page page)
Definition: nbtree.h:260
#define P_ISROOT(opaque)
Definition: nbtree.h:221
#define P_IGNORE(opaque)
Definition: nbtree.h:225
#define InvalidOffsetNumber
Definition: off.h:26
BlockNumber btpo_next
Definition: nbtree.h:65
BlockNumber btpo_prev
Definition: nbtree.h:64
uint16 btpo_flags
Definition: nbtree.h:67
BTCycleId btpo_cycleid
Definition: nbtree.h:68
LocationIndex pd_special
Definition: bufpage.h:164
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define XidFromFullTransactionId(x)
Definition: transam.h:48

References BTPageGetDeleteXid(), BTPageGetOpaque, BTPageOpaqueData::btpo_cycleid, BTPageOpaqueData::btpo_flags, BTPageOpaqueData::btpo_level, BTPageOpaqueData::btpo_next, BTPageOpaqueData::btpo_prev, BufferGetPage(), DEBUG2, elog, EpochFromFullTransactionId, FirstOffsetNumber, IndexTupleSize, InvalidOffsetNumber, ItemIdIsDead, P_HAS_FULLXID, P_IGNORE, P_ISDELETED, P_ISLEAF, P_ISROOT, PageGetFreeSpace(), PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), PageGetPageSize(), PageHeaderData::pd_special, SizeOfPageHeaderData, and XidFromFullTransactionId.

Referenced by bt_multi_page_stats(), and bt_page_stats_internal().

◆ PG_FUNCTION_INFO_V1() [1/7]

PG_FUNCTION_INFO_V1 ( bt_metap  )

◆ PG_FUNCTION_INFO_V1() [2/7]

PG_FUNCTION_INFO_V1 ( bt_multi_page_stats  )

◆ PG_FUNCTION_INFO_V1() [3/7]

PG_FUNCTION_INFO_V1 ( bt_page_items  )

◆ PG_FUNCTION_INFO_V1() [4/7]

PG_FUNCTION_INFO_V1 ( bt_page_items_1_9  )

◆ PG_FUNCTION_INFO_V1() [5/7]

PG_FUNCTION_INFO_V1 ( bt_page_items_bytea  )

◆ PG_FUNCTION_INFO_V1() [6/7]

PG_FUNCTION_INFO_V1 ( bt_page_stats  )

◆ PG_FUNCTION_INFO_V1() [7/7]

PG_FUNCTION_INFO_V1 ( bt_page_stats_1_9  )