Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * gindesc.c
4 : : * rmgr descriptor routines for access/transam/gin/ginxlog.c
5 : : *
6 : : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 : : * Portions Copyright (c) 1994, Regents of the University of California
8 : : *
9 : : *
10 : : * IDENTIFICATION
11 : : * src/backend/access/rmgrdesc/gindesc.c
12 : : *
13 : : *-------------------------------------------------------------------------
14 : : */
15 : : #include "postgres.h"
16 : :
17 : : #include "access/ginxlog.h"
18 : : #include "lib/stringinfo.h"
19 : :
20 : : static void
4418 heikki.linnakangas@i 21 :UBC 0 : desc_recompress_leaf(StringInfo buf, ginxlogRecompressDataLeaf *insertData)
22 : : {
23 : : int i;
24 : 0 : char *walbuf = ((char *) insertData) + sizeof(ginxlogRecompressDataLeaf);
25 : :
147 peter@eisentraut.org 26 :UNC 0 : appendStringInfo(buf, " %d segments:", insertData->nactions);
27 : :
4418 heikki.linnakangas@i 28 [ # # ]:UBC 0 : for (i = 0; i < insertData->nactions; i++)
29 : : {
30 : 0 : uint8 a_segno = *((uint8 *) (walbuf++));
31 : 0 : uint8 a_action = *((uint8 *) (walbuf++));
32 : 0 : uint16 nitems = 0;
33 : 0 : int newsegsize = 0;
34 : :
35 [ # # # # ]: 0 : if (a_action == GIN_SEGMENT_INSERT ||
36 : : a_action == GIN_SEGMENT_REPLACE)
37 : : {
38 : 0 : newsegsize = SizeOfGinPostingList((GinPostingList *) walbuf);
39 : 0 : walbuf += SHORTALIGN(newsegsize);
40 : : }
41 : :
42 [ # # ]: 0 : if (a_action == GIN_SEGMENT_ADDITEMS)
43 : : {
44 : 0 : memcpy(&nitems, walbuf, sizeof(uint16));
45 : 0 : walbuf += sizeof(uint16);
46 : 0 : walbuf += nitems * sizeof(ItemPointerData);
47 : : }
48 : :
4382 bruce@momjian.us 49 [ # # # # : 0 : switch (a_action)
# ]
50 : : {
4418 heikki.linnakangas@i 51 : 0 : case GIN_SEGMENT_ADDITEMS:
52 : 0 : appendStringInfo(buf, " %d (add %d items)", a_segno, nitems);
53 : 0 : break;
54 : 0 : case GIN_SEGMENT_DELETE:
55 : 0 : appendStringInfo(buf, " %d (delete)", a_segno);
56 : 0 : break;
57 : 0 : case GIN_SEGMENT_INSERT:
58 : 0 : appendStringInfo(buf, " %d (insert)", a_segno);
59 : 0 : break;
60 : 0 : case GIN_SEGMENT_REPLACE:
61 : 0 : appendStringInfo(buf, " %d (replace)", a_segno);
62 : 0 : break;
63 : 0 : default:
64 : 0 : appendStringInfo(buf, " %d unknown action %d ???", a_segno, a_action);
65 : : /* cannot decode unrecognized actions further */
66 : 0 : return;
67 : : }
68 : : }
69 : : }
70 : :
71 : : void
4184 heikki.linnakangas@i 72 :CBC 7224 : gin_desc(StringInfo buf, XLogReaderState *record)
73 : : {
4343 74 : 7224 : char *rec = XLogRecGetData(record);
4184 75 : 7224 : uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
76 : :
4906 alvherre@alvh.no-ip. 77 [ - + - - : 7224 : switch (info)
- - + + +
- ]
78 : : {
4906 alvherre@alvh.no-ip. 79 :UBC 0 : case XLOG_GIN_CREATE_PTREE:
80 : : /* no further information */
81 : 0 : break;
4906 alvherre@alvh.no-ip. 82 :CBC 84 : case XLOG_GIN_INSERT:
83 : : {
4542 heikki.linnakangas@i 84 : 84 : ginxlogInsert *xlrec = (ginxlogInsert *) rec;
85 : :
4184 86 : 168 : appendStringInfo(buf, "isdata: %c isleaf: %c",
3240 tgl@sss.pgh.pa.us 87 [ - + ]: 84 : (xlrec->flags & GIN_INSERT_ISDATA) ? 'T' : 'F',
88 [ + - ]: 84 : (xlrec->flags & GIN_INSERT_ISLEAF) ? 'T' : 'F');
4542 heikki.linnakangas@i 89 [ - + ]: 84 : if (!(xlrec->flags & GIN_INSERT_ISLEAF))
90 : : {
3438 fujii@postgresql.org 91 :UBC 0 : char *payload = rec + sizeof(ginxlogInsert);
92 : : BlockNumber leftChildBlkno;
93 : : BlockNumber rightChildBlkno;
94 : :
4541 heikki.linnakangas@i 95 : 0 : leftChildBlkno = BlockIdGetBlockNumber((BlockId) payload);
96 : 0 : payload += sizeof(BlockIdData);
97 : 0 : rightChildBlkno = BlockIdGetBlockNumber((BlockId) payload);
4542 98 : 0 : payload += sizeof(BlockNumber);
99 : 0 : appendStringInfo(buf, " children: %u/%u",
100 : : leftChildBlkno, rightChildBlkno);
101 : : }
211 michael@paquier.xyz 102 [ + - ]:GNC 84 : if (!XLogRecHasBlockImage(record, 0))
103 : : {
3438 fujii@postgresql.org 104 :CBC 84 : char *payload = XLogRecGetBlockData(record, 0, NULL);
105 : :
106 [ + - ]: 84 : if (!(xlrec->flags & GIN_INSERT_ISDATA))
107 : 84 : appendStringInfo(buf, " isdelete: %c",
3275 bruce@momjian.us 108 [ - + ]: 84 : (((ginxlogInsertEntry *) payload)->isDelete) ? 'T' : 'F');
3438 fujii@postgresql.org 109 [ # # ]:UBC 0 : else if (xlrec->flags & GIN_INSERT_ISLEAF)
110 : 0 : desc_recompress_leaf(buf, (ginxlogRecompressDataLeaf *) payload);
111 : : else
112 : : {
113 : 0 : ginxlogInsertDataInternal *insertData =
114 : : (ginxlogInsertDataInternal *) payload;
115 : :
116 : 0 : appendStringInfo(buf, " pitem: %u-%u/%u",
3240 tgl@sss.pgh.pa.us 117 : 0 : PostingItemGetBlockNumber(&insertData->newitem),
118 : 0 : ItemPointerGetBlockNumber(&insertData->newitem.key),
119 : 0 : ItemPointerGetOffsetNumber(&insertData->newitem.key));
120 : : }
121 : : }
122 : : }
4906 alvherre@alvh.no-ip. 123 :CBC 84 : break;
4906 alvherre@alvh.no-ip. 124 :UBC 0 : case XLOG_GIN_SPLIT:
125 : : {
4486 heikki.linnakangas@i 126 : 0 : ginxlogSplit *xlrec = (ginxlogSplit *) rec;
127 : :
4184 128 : 0 : appendStringInfo(buf, "isrootsplit: %c",
14 michael@paquier.xyz 129 [ # # ]:UNC 0 : (xlrec->flags & GIN_SPLIT_ROOT) ? 'T' : 'F');
4486 heikki.linnakangas@i 130 :UBC 0 : appendStringInfo(buf, " isdata: %c isleaf: %c",
3240 tgl@sss.pgh.pa.us 131 [ # # ]: 0 : (xlrec->flags & GIN_INSERT_ISDATA) ? 'T' : 'F',
132 [ # # ]: 0 : (xlrec->flags & GIN_INSERT_ISLEAF) ? 'T' : 'F');
209 michael@paquier.xyz 133 [ # # ]:UNC 0 : if (xlrec->leftChildBlkno != InvalidBlockNumber)
134 : 0 : appendStringInfo(buf, " children: %u/%u",
135 : : xlrec->leftChildBlkno, xlrec->rightChildBlkno);
136 : : }
4906 alvherre@alvh.no-ip. 137 :UBC 0 : break;
138 : 0 : case XLOG_GIN_VACUUM_PAGE:
139 : : /* no further information */
140 : 0 : break;
4486 heikki.linnakangas@i 141 : 0 : case XLOG_GIN_VACUUM_DATA_LEAF_PAGE:
142 : : {
211 michael@paquier.xyz 143 [ # # ]:UNC 0 : if (!XLogRecHasBlockImage(record, 0))
144 : : {
145 : : ginxlogVacuumDataLeafPage *xlrec =
1082 tgl@sss.pgh.pa.us 146 :UBC 0 : (ginxlogVacuumDataLeafPage *) XLogRecGetBlockData(record, 0, NULL);
147 : :
4418 heikki.linnakangas@i 148 : 0 : desc_recompress_leaf(buf, &xlrec->data);
149 : : }
150 : : }
4486 151 : 0 : break;
4906 alvherre@alvh.no-ip. 152 : 0 : case XLOG_GIN_DELETE_PAGE:
153 : : /* no further information */
154 : 0 : break;
4906 alvherre@alvh.no-ip. 155 :CBC 7014 : case XLOG_GIN_UPDATE_META_PAGE:
156 : : {
209 michael@paquier.xyz 157 :GNC 7014 : ginxlogUpdateMeta *xlrec = (ginxlogUpdateMeta *) rec;
158 : :
159 : 7014 : appendStringInfo(buf, "ntuples: %d", xlrec->ntuples);
160 [ + + ]: 7014 : if (xlrec->prevTail != InvalidBlockNumber)
161 : 98 : appendStringInfo(buf, " prevTail: %u",
162 : : xlrec->prevTail);
163 [ + + ]: 7014 : if (xlrec->newRightlink != InvalidBlockNumber)
120 164 : 98 : appendStringInfo(buf, " newRightlink: %u",
165 : : xlrec->newRightlink);
166 : : }
4906 alvherre@alvh.no-ip. 167 :CBC 7014 : break;
168 : 112 : case XLOG_GIN_INSERT_LISTPAGE:
169 : : {
209 michael@paquier.xyz 170 :GNC 112 : ginxlogInsertListPage *xlrec = (ginxlogInsertListPage *) rec;
171 : :
172 : 112 : appendStringInfo(buf, "ntuples: %d", xlrec->ntuples);
173 [ - + ]: 112 : if (xlrec->rightlink != InvalidBlockNumber)
209 michael@paquier.xyz 174 :UNC 0 : appendStringInfo(buf, " rightlink: %u",
175 : : xlrec->rightlink);
176 : : }
4906 alvherre@alvh.no-ip. 177 :CBC 112 : break;
178 : 14 : case XLOG_GIN_DELETE_LISTPAGE:
4184 heikki.linnakangas@i 179 : 14 : appendStringInfo(buf, "ndeleted: %d",
180 : : ((ginxlogDeleteListPages *) rec)->ndeleted);
4906 alvherre@alvh.no-ip. 181 : 14 : break;
182 : : }
4246 andres@anarazel.de 183 : 7224 : }
184 : :
185 : : const char *
186 : 7236 : gin_identify(uint8 info)
187 : : {
188 : 7236 : const char *id = NULL;
189 : :
4243 190 [ - + - - : 7236 : switch (info & ~XLR_INFO_MASK)
- - + + +
- ]
191 : : {
4246 andres@anarazel.de 192 :UBC 0 : case XLOG_GIN_CREATE_PTREE:
193 : 0 : id = "CREATE_PTREE";
194 : 0 : break;
4246 andres@anarazel.de 195 :CBC 87 : case XLOG_GIN_INSERT:
196 : 87 : id = "INSERT";
197 : 87 : break;
4246 andres@anarazel.de 198 :UBC 0 : case XLOG_GIN_SPLIT:
199 : 0 : id = "SPLIT";
200 : 0 : break;
201 : 0 : case XLOG_GIN_VACUUM_PAGE:
202 : 0 : id = "VACUUM_PAGE";
203 : 0 : break;
204 : 0 : case XLOG_GIN_VACUUM_DATA_LEAF_PAGE:
205 : 0 : id = "VACUUM_DATA_LEAF_PAGE";
206 : 0 : break;
207 : 0 : case XLOG_GIN_DELETE_PAGE:
208 : 0 : id = "DELETE_PAGE";
209 : 0 : break;
4246 andres@anarazel.de 210 :CBC 7017 : case XLOG_GIN_UPDATE_META_PAGE:
211 : 7017 : id = "UPDATE_META_PAGE";
212 : 7017 : break;
213 : 115 : case XLOG_GIN_INSERT_LISTPAGE:
214 : 115 : id = "INSERT_LISTPAGE";
215 : 115 : break;
216 : 17 : case XLOG_GIN_DELETE_LISTPAGE:
217 : 17 : id = "DELETE_LISTPAGE";
4906 alvherre@alvh.no-ip. 218 : 17 : break;
219 : : }
220 : :
4246 andres@anarazel.de 221 : 7236 : return id;
222 : : }
|