Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * nbtdesc.c
4 : : * rmgr descriptor routines for access/nbtree/nbtxlog.c
5 : : *
6 : : * Portions Copyright (c) 1996-2025, 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
3943 heikki.linnakangas@i 24 :CBC 39538 : btree_desc(StringInfo buf, XLogReaderState *record)
25 : : {
4102 26 : 39538 : char *rec = XLogRecGetData(record);
3943 27 : 39538 : uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
28 : :
4665 alvherre@alvh.no-ip. 29 [ + + + + : 39538 : switch (info)
+ + + + -
+ - ]
30 : : {
31 : 39052 : case XLOG_BTREE_INSERT_LEAF:
32 : : case XLOG_BTREE_INSERT_UPPER:
33 : : case XLOG_BTREE_INSERT_META:
34 : : case XLOG_BTREE_INSERT_POST:
35 : : {
36 : 39052 : xl_btree_insert *xlrec = (xl_btree_insert *) rec;
37 : :
883 pg@bowt.ie 38 : 39052 : appendStringInfo(buf, "off: %u", xlrec->offnum);
4665 alvherre@alvh.no-ip. 39 : 39052 : break;
40 : : }
41 : 129 : case XLOG_BTREE_SPLIT_L:
42 : : case XLOG_BTREE_SPLIT_R:
43 : : {
44 : 129 : xl_btree_split *xlrec = (xl_btree_split *) rec;
45 : :
883 pg@bowt.ie 46 : 129 : appendStringInfo(buf, "level: %u, firstrightoff: %d, newitemoff: %d, postingoff: %d",
1972 47 : 129 : xlrec->level, xlrec->firstrightoff,
2019 48 : 129 : xlrec->newitemoff, xlrec->postingoff);
49 : 129 : break;
50 : : }
51 : 98 : case XLOG_BTREE_DEDUP:
52 : : {
53 : 98 : xl_btree_dedup *xlrec = (xl_btree_dedup *) rec;
54 : :
883 55 : 98 : appendStringInfo(buf, "nintervals: %u", xlrec->nintervals);
4665 alvherre@alvh.no-ip. 56 : 98 : break;
57 : : }
58 : 134 : case XLOG_BTREE_VACUUM:
59 : : {
60 : 134 : xl_btree_vacuum *xlrec = (xl_btree_vacuum *) rec;
61 : :
883 pg@bowt.ie 62 : 134 : appendStringInfo(buf, "ndeleted: %u, nupdated: %u",
2019 63 : 134 : xlrec->ndeleted, xlrec->nupdated);
64 : :
871 65 [ + - ]: 134 : if (XLogRecHasBlockData(record, 0))
880 66 : 134 : delvacuum_desc(buf, XLogRecGetBlockData(record, 0, NULL),
883 67 : 134 : xlrec->ndeleted, xlrec->nupdated);
4665 alvherre@alvh.no-ip. 68 : 134 : break;
69 : : }
70 : 10 : case XLOG_BTREE_DELETE:
71 : : {
72 : 10 : xl_btree_delete *xlrec = (xl_btree_delete *) rec;
73 : :
625 msawada@postgresql.o 74 : 10 : appendStringInfo(buf, "snapshotConflictHorizon: %u, ndeleted: %u, nupdated: %u, isCatalogRel: %c",
75 : : xlrec->snapshotConflictHorizon,
76 : 10 : xlrec->ndeleted, xlrec->nupdated,
77 [ - + ]: 10 : xlrec->isCatalogRel ? 'T' : 'F');
78 : :
871 pg@bowt.ie 79 [ + - ]: 10 : if (XLogRecHasBlockData(record, 0))
880 80 : 10 : delvacuum_desc(buf, XLogRecGetBlockData(record, 0, NULL),
883 81 : 10 : xlrec->ndeleted, xlrec->nupdated);
4665 alvherre@alvh.no-ip. 82 : 10 : break;
83 : : }
4194 heikki.linnakangas@i 84 : 2 : case XLOG_BTREE_MARK_PAGE_HALFDEAD:
85 : : {
86 : 2 : xl_btree_mark_page_halfdead *xlrec = (xl_btree_mark_page_halfdead *) rec;
87 : :
880 pg@bowt.ie 88 : 2 : appendStringInfo(buf, "topparent: %u, leaf: %u, left: %u, right: %u",
89 : : xlrec->topparent, xlrec->leafblk, xlrec->leftblk, xlrec->rightblk);
4194 heikki.linnakangas@i 90 : 2 : break;
91 : : }
92 : 2 : case XLOG_BTREE_UNLINK_PAGE_META:
93 : : case XLOG_BTREE_UNLINK_PAGE:
94 : : {
95 : 2 : xl_btree_unlink_page *xlrec = (xl_btree_unlink_page *) rec;
96 : :
880 pg@bowt.ie 97 : 2 : appendStringInfo(buf, "left: %u, right: %u, level: %u, safexid: %u:%u, ",
98 : : xlrec->leftsib, xlrec->rightsib, xlrec->level,
1655 99 : 2 : EpochFromFullTransactionId(xlrec->safexid),
100 : 2 : XidFromFullTransactionId(xlrec->safexid));
880 101 : 2 : appendStringInfo(buf, "leafleft: %u, leafright: %u, leaftopparent: %u",
102 : : xlrec->leafleftsib, xlrec->leafrightsib,
103 : : xlrec->leaftopparent);
4665 alvherre@alvh.no-ip. 104 : 2 : break;
105 : : }
106 : 110 : case XLOG_BTREE_NEWROOT:
107 : : {
108 : 110 : xl_btree_newroot *xlrec = (xl_btree_newroot *) rec;
109 : :
871 pg@bowt.ie 110 : 110 : appendStringInfo(buf, "level: %u", xlrec->level);
4665 alvherre@alvh.no-ip. 111 : 110 : break;
112 : : }
4665 alvherre@alvh.no-ip. 113 :UBC 0 : case XLOG_BTREE_REUSE_PAGE:
114 : : {
115 : 0 : xl_btree_reuse_page *xlrec = (xl_btree_reuse_page *) rec;
116 : :
625 msawada@postgresql.o 117 : 0 : appendStringInfo(buf, "rel: %u/%u/%u, snapshotConflictHorizon: %u:%u, isCatalogRel: %c",
118 : : xlrec->locator.spcOid, xlrec->locator.dbOid,
119 : : xlrec->locator.relNumber,
1024 pg@bowt.ie 120 : 0 : EpochFromFullTransactionId(xlrec->snapshotConflictHorizon),
625 msawada@postgresql.o 121 : 0 : XidFromFullTransactionId(xlrec->snapshotConflictHorizon),
122 [ # # ]: 0 : xlrec->isCatalogRel ? 'T' : 'F');
4665 alvherre@alvh.no-ip. 123 : 0 : break;
124 : : }
2697 teodor@sigaev.ru 125 :CBC 1 : case XLOG_BTREE_META_CLEANUP:
126 : : {
127 : : xl_btree_metadata *xlrec;
128 : :
2271 michael@paquier.xyz 129 : 1 : xlrec = (xl_btree_metadata *) XLogRecGetBlockData(record, 0,
130 : : NULL);
883 pg@bowt.ie 131 : 1 : appendStringInfo(buf, "last_cleanup_num_delpages: %u",
132 : : xlrec->last_cleanup_num_delpages);
2697 teodor@sigaev.ru 133 : 1 : break;
134 : : }
135 : : }
4005 andres@anarazel.de 136 : 39538 : }
137 : :
138 : : const char *
139 : 39542 : btree_identify(uint8 info)
140 : : {
141 : 39542 : const char *id = NULL;
142 : :
4002 143 [ + + - + : 39542 : switch (info & ~XLR_INFO_MASK)
+ - + + +
+ + + + -
+ - ]
144 : : {
4005 145 : 38952 : case XLOG_BTREE_INSERT_LEAF:
146 : 38952 : id = "INSERT_LEAF";
147 : 38952 : break;
148 : 101 : case XLOG_BTREE_INSERT_UPPER:
149 : 101 : id = "INSERT_UPPER";
150 : 101 : break;
4005 andres@anarazel.de 151 :UBC 0 : case XLOG_BTREE_INSERT_META:
152 : 0 : id = "INSERT_META";
153 : 0 : break;
4005 andres@anarazel.de 154 :CBC 32 : case XLOG_BTREE_SPLIT_L:
155 : 32 : id = "SPLIT_L";
156 : 32 : break;
157 : 98 : case XLOG_BTREE_SPLIT_R:
158 : 98 : id = "SPLIT_R";
159 : 98 : break;
2019 pg@bowt.ie 160 :LBC (34) : case XLOG_BTREE_INSERT_POST:
161 : (34) : id = "INSERT_POST";
162 : (34) : break;
2019 pg@bowt.ie 163 :CBC 98 : case XLOG_BTREE_DEDUP:
164 : 98 : id = "DEDUP";
165 : 98 : break;
4005 andres@anarazel.de 166 : 135 : case XLOG_BTREE_VACUUM:
167 : 135 : id = "VACUUM";
168 : 135 : break;
169 : 10 : case XLOG_BTREE_DELETE:
170 : 10 : id = "DELETE";
171 : 10 : break;
172 : 2 : case XLOG_BTREE_MARK_PAGE_HALFDEAD:
173 : 2 : id = "MARK_PAGE_HALFDEAD";
174 : 2 : break;
175 : 1 : case XLOG_BTREE_UNLINK_PAGE:
176 : 1 : id = "UNLINK_PAGE";
177 : 1 : break;
178 : 1 : case XLOG_BTREE_UNLINK_PAGE_META:
179 : 1 : id = "UNLINK_PAGE_META";
180 : 1 : break;
181 : 111 : case XLOG_BTREE_NEWROOT:
182 : 111 : id = "NEWROOT";
183 : 111 : break;
4005 andres@anarazel.de 184 :UBC 0 : case XLOG_BTREE_REUSE_PAGE:
185 : 0 : id = "REUSE_PAGE";
4665 alvherre@alvh.no-ip. 186 : 0 : break;
2697 teodor@sigaev.ru 187 :CBC 1 : case XLOG_BTREE_META_CLEANUP:
188 : 1 : id = "META_CLEANUP";
189 : 1 : break;
190 : : }
191 : :
4005 andres@anarazel.de 192 : 39542 : return id;
193 : : }
194 : :
195 : : static void
880 pg@bowt.ie 196 : 144 : delvacuum_desc(StringInfo buf, char *block_data,
197 : : uint16 ndeleted, uint16 nupdated)
198 : : {
199 : : OffsetNumber *deletedoffsets;
200 : : OffsetNumber *updatedoffsets;
201 : : xl_btree_update *updates;
202 : :
203 : : /* Output deleted page offset number array */
204 : 144 : appendStringInfoString(buf, ", deleted:");
205 : 144 : deletedoffsets = (OffsetNumber *) block_data;
206 : 144 : array_desc(buf, deletedoffsets, sizeof(OffsetNumber), ndeleted,
207 : : &offset_elem_desc, NULL);
208 : :
209 : : /*
210 : : * Output updates as an array of "update objects", where each element
211 : : * contains a page offset number from updated array. (This is not the
212 : : * most literal representation of the underlying physical data structure
213 : : * that we could use. Readability seems more important here.)
214 : : */
215 : 144 : appendStringInfoString(buf, ", updated: [");
216 : 144 : updatedoffsets = (OffsetNumber *) (block_data + ndeleted *
217 : : sizeof(OffsetNumber));
218 : 144 : updates = (xl_btree_update *) ((char *) updatedoffsets +
219 : 144 : nupdated *
220 : : sizeof(OffsetNumber));
221 [ + + ]: 664 : for (int i = 0; i < nupdated; i++)
222 : : {
223 : 520 : OffsetNumber off = updatedoffsets[i];
224 : :
225 [ + - + - : 520 : Assert(OffsetNumberIsValid(off));
- + ]
226 [ - + ]: 520 : Assert(updates->ndeletedtids > 0);
227 : :
228 : : /*
229 : : * "ptid" is the symbol name used when building each xl_btree_update's
230 : : * array of offsets into a posting list tuple's ItemPointerData array.
231 : : * xl_btree_update describes a subset of the existing TIDs to delete.
232 : : */
233 : 520 : appendStringInfo(buf, "{ off: %u, nptids: %u, ptids: [",
234 : 520 : off, updates->ndeletedtids);
235 [ + + ]: 1196 : for (int p = 0; p < updates->ndeletedtids; p++)
236 : : {
237 : : uint16 *ptid;
238 : :
239 : 676 : ptid = (uint16 *) ((char *) updates + SizeOfBtreeUpdate) + p;
240 : 676 : appendStringInfo(buf, "%u", *ptid);
241 : :
242 [ + + ]: 676 : if (p < updates->ndeletedtids - 1)
243 : 156 : appendStringInfoString(buf, ", ");
244 : : }
245 : 520 : appendStringInfoString(buf, "] }");
246 [ + + ]: 520 : if (i < nupdated - 1)
247 : 498 : appendStringInfoString(buf, ", ");
248 : :
249 : 520 : updates = (xl_btree_update *)
250 : 520 : ((char *) updates + SizeOfBtreeUpdate +
251 : 520 : updates->ndeletedtids * sizeof(uint16));
252 : : }
704 drowley@postgresql.o 253 : 144 : appendStringInfoChar(buf, ']');
880 pg@bowt.ie 254 : 144 : }
|