PostgreSQL Source Code  git master
nbtdesc.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * nbtdesc.c
4  * rmgr descriptor routines for access/nbtree/nbtxlog.c
5  *
6  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/access/rmgrdesc/nbtdesc.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/nbtxlog.h"
18 #include "access/rmgrdesc_utils.h"
19 
20 static void delvacuum_desc(StringInfo buf, char *block_data,
21  uint16 ndeleted, uint16 nupdated);
22 
23 void
25 {
26  char *rec = XLogRecGetData(record);
27  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
28 
29  switch (info)
30  {
35  {
36  xl_btree_insert *xlrec = (xl_btree_insert *) rec;
37 
38  appendStringInfo(buf, "off: %u", xlrec->offnum);
39  break;
40  }
41  case XLOG_BTREE_SPLIT_L:
42  case XLOG_BTREE_SPLIT_R:
43  {
44  xl_btree_split *xlrec = (xl_btree_split *) rec;
45 
46  appendStringInfo(buf, "level: %u, firstrightoff: %d, newitemoff: %d, postingoff: %d",
47  xlrec->level, xlrec->firstrightoff,
48  xlrec->newitemoff, xlrec->postingoff);
49  break;
50  }
51  case XLOG_BTREE_DEDUP:
52  {
53  xl_btree_dedup *xlrec = (xl_btree_dedup *) rec;
54 
55  appendStringInfo(buf, "nintervals: %u", xlrec->nintervals);
56  break;
57  }
58  case XLOG_BTREE_VACUUM:
59  {
60  xl_btree_vacuum *xlrec = (xl_btree_vacuum *) rec;
61 
62  appendStringInfo(buf, "ndeleted: %u, nupdated: %u",
63  xlrec->ndeleted, xlrec->nupdated);
64 
65  if (XLogRecHasBlockData(record, 0))
66  delvacuum_desc(buf, XLogRecGetBlockData(record, 0, NULL),
67  xlrec->ndeleted, xlrec->nupdated);
68  break;
69  }
70  case XLOG_BTREE_DELETE:
71  {
72  xl_btree_delete *xlrec = (xl_btree_delete *) rec;
73 
74  appendStringInfo(buf, "snapshotConflictHorizon: %u, ndeleted: %u, nupdated: %u",
76  xlrec->ndeleted, xlrec->nupdated);
77 
78  if (XLogRecHasBlockData(record, 0))
79  delvacuum_desc(buf, XLogRecGetBlockData(record, 0, NULL),
80  xlrec->ndeleted, xlrec->nupdated);
81  break;
82  }
84  {
86 
87  appendStringInfo(buf, "topparent: %u, leaf: %u, left: %u, right: %u",
88  xlrec->topparent, xlrec->leafblk, xlrec->leftblk, xlrec->rightblk);
89  break;
90  }
93  {
95 
96  appendStringInfo(buf, "left: %u, right: %u, level: %u, safexid: %u:%u, ",
97  xlrec->leftsib, xlrec->rightsib, xlrec->level,
100  appendStringInfo(buf, "leafleft: %u, leafright: %u, leaftopparent: %u",
101  xlrec->leafleftsib, xlrec->leafrightsib,
102  xlrec->leaftopparent);
103  break;
104  }
105  case XLOG_BTREE_NEWROOT:
106  {
107  xl_btree_newroot *xlrec = (xl_btree_newroot *) rec;
108 
109  appendStringInfo(buf, "level: %u", xlrec->level);
110  break;
111  }
113  {
114  xl_btree_reuse_page *xlrec = (xl_btree_reuse_page *) rec;
115 
116  appendStringInfo(buf, "rel: %u/%u/%u, snapshotConflictHorizon: %u:%u",
117  xlrec->locator.spcOid, xlrec->locator.dbOid,
118  xlrec->locator.relNumber,
121  break;
122  }
124  {
125  xl_btree_metadata *xlrec;
126 
127  xlrec = (xl_btree_metadata *) XLogRecGetBlockData(record, 0,
128  NULL);
129  appendStringInfo(buf, "last_cleanup_num_delpages: %u",
131  break;
132  }
133  }
134 }
135 
136 const char *
138 {
139  const char *id = NULL;
140 
141  switch (info & ~XLR_INFO_MASK)
142  {
144  id = "INSERT_LEAF";
145  break;
147  id = "INSERT_UPPER";
148  break;
150  id = "INSERT_META";
151  break;
152  case XLOG_BTREE_SPLIT_L:
153  id = "SPLIT_L";
154  break;
155  case XLOG_BTREE_SPLIT_R:
156  id = "SPLIT_R";
157  break;
159  id = "INSERT_POST";
160  break;
161  case XLOG_BTREE_DEDUP:
162  id = "DEDUP";
163  break;
164  case XLOG_BTREE_VACUUM:
165  id = "VACUUM";
166  break;
167  case XLOG_BTREE_DELETE:
168  id = "DELETE";
169  break;
171  id = "MARK_PAGE_HALFDEAD";
172  break;
174  id = "UNLINK_PAGE";
175  break;
177  id = "UNLINK_PAGE_META";
178  break;
179  case XLOG_BTREE_NEWROOT:
180  id = "NEWROOT";
181  break;
183  id = "REUSE_PAGE";
184  break;
186  id = "META_CLEANUP";
187  break;
188  }
189 
190  return id;
191 }
192 
193 static void
194 delvacuum_desc(StringInfo buf, char *block_data,
195  uint16 ndeleted, uint16 nupdated)
196 {
197  OffsetNumber *deletedoffsets;
198  OffsetNumber *updatedoffsets;
199  xl_btree_update *updates;
200 
201  /* Output deleted page offset number array */
202  appendStringInfoString(buf, ", deleted:");
203  deletedoffsets = (OffsetNumber *) block_data;
204  array_desc(buf, deletedoffsets, sizeof(OffsetNumber), ndeleted,
205  &offset_elem_desc, NULL);
206 
207  /*
208  * Output updates as an array of "update objects", where each element
209  * contains a page offset number from updated array. (This is not the
210  * most literal representation of the underlying physical data structure
211  * that we could use. Readability seems more important here.)
212  */
213  appendStringInfoString(buf, ", updated: [");
214  updatedoffsets = (OffsetNumber *) (block_data + ndeleted *
215  sizeof(OffsetNumber));
216  updates = (xl_btree_update *) ((char *) updatedoffsets +
217  nupdated *
218  sizeof(OffsetNumber));
219  for (int i = 0; i < nupdated; i++)
220  {
221  OffsetNumber off = updatedoffsets[i];
222 
224  Assert(updates->ndeletedtids > 0);
225 
226  /*
227  * "ptid" is the symbol name used when building each xl_btree_update's
228  * array of offsets into a posting list tuple's ItemPointerData array.
229  * xl_btree_update describes a subset of the existing TIDs to delete.
230  */
231  appendStringInfo(buf, "{ off: %u, nptids: %u, ptids: [",
232  off, updates->ndeletedtids);
233  for (int p = 0; p < updates->ndeletedtids; p++)
234  {
235  uint16 *ptid;
236 
237  ptid = (uint16 *) ((char *) updates + SizeOfBtreeUpdate) + p;
238  appendStringInfo(buf, "%u", *ptid);
239 
240  if (p < updates->ndeletedtids - 1)
242  }
243  appendStringInfoString(buf, "] }");
244  if (i < nupdated - 1)
246 
247  updates = (xl_btree_update *)
248  ((char *) updates + SizeOfBtreeUpdate +
249  updates->ndeletedtids * sizeof(uint16));
250  }
252 }
unsigned short uint16
Definition: c.h:489
unsigned char uint8
Definition: c.h:488
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
const char * btree_identify(uint8 info)
Definition: nbtdesc.c:137
static void delvacuum_desc(StringInfo buf, char *block_data, uint16 ndeleted, uint16 nupdated)
Definition: nbtdesc.c:194
void btree_desc(StringInfo buf, XLogReaderState *record)
Definition: nbtdesc.c:24
#define XLOG_BTREE_META_CLEANUP
Definition: nbtxlog.h:41
#define XLOG_BTREE_INSERT_POST
Definition: nbtxlog.h:32
#define SizeOfBtreeUpdate
Definition: nbtxlog.h:268
#define XLOG_BTREE_VACUUM
Definition: nbtxlog.h:39
#define XLOG_BTREE_SPLIT_R
Definition: nbtxlog.h:31
#define XLOG_BTREE_INSERT_LEAF
Definition: nbtxlog.h:27
#define XLOG_BTREE_INSERT_UPPER
Definition: nbtxlog.h:28
#define XLOG_BTREE_DEDUP
Definition: nbtxlog.h:33
#define XLOG_BTREE_UNLINK_PAGE
Definition: nbtxlog.h:35
#define XLOG_BTREE_UNLINK_PAGE_META
Definition: nbtxlog.h:36
#define XLOG_BTREE_INSERT_META
Definition: nbtxlog.h:29
#define XLOG_BTREE_MARK_PAGE_HALFDEAD
Definition: nbtxlog.h:38
#define XLOG_BTREE_REUSE_PAGE
Definition: nbtxlog.h:40
#define XLOG_BTREE_SPLIT_L
Definition: nbtxlog.h:30
#define XLOG_BTREE_NEWROOT
Definition: nbtxlog.h:37
#define XLOG_BTREE_DELETE
Definition: nbtxlog.h:34
#define OffsetNumberIsValid(offsetNumber)
Definition: off.h:39
uint16 OffsetNumber
Definition: off.h:24
static char * buf
Definition: pg_test_fsync.c:67
void array_desc(StringInfo buf, void *array, size_t elem_size, int count, void(*elem_desc)(StringInfo buf, void *elem, void *data), void *data)
void offset_elem_desc(StringInfo buf, void *offset, void *data)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
RelFileNumber relNumber
uint16 nintervals
Definition: nbtxlog.h:169
TransactionId snapshotConflictHorizon
Definition: nbtxlog.h:238
uint16 ndeleted
Definition: nbtxlog.h:239
uint16 nupdated
Definition: nbtxlog.h:240
OffsetNumber offnum
Definition: nbtxlog.h:78
uint32 last_cleanup_num_delpages
Definition: nbtxlog.h:53
uint32 level
Definition: nbtxlog.h:344
FullTransactionId snapshotConflictHorizon
Definition: nbtxlog.h:187
RelFileLocator locator
Definition: nbtxlog.h:185
uint16 postingoff
Definition: nbtxlog.h:155
OffsetNumber firstrightoff
Definition: nbtxlog.h:153
uint32 level
Definition: nbtxlog.h:152
OffsetNumber newitemoff
Definition: nbtxlog.h:154
uint16 ndeletedtids
Definition: nbtxlog.h:263
uint16 ndeleted
Definition: nbtxlog.h:222
uint16 nupdated
Definition: nbtxlog.h:223
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define XidFromFullTransactionId(x)
Definition: transam.h:48
char * XLogRecGetBlockData(XLogReaderState *record, uint8 block_id, Size *len)
Definition: xlogreader.c:2015
#define XLogRecHasBlockData(decoder, block_id)
Definition: xlogreader.h:427
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415
#define XLR_INFO_MASK
Definition: xlogrecord.h:62