1 /*-------------------------------------------------------------------------
2 *
3 * heapdesc.c
4 * rmgr descriptor routines for access/heap/heapam.c
5 *
6 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/access/rmgrdesc/heapdesc.c
12 *
13 *-------------------------------------------------------------------------
14 */
15 #include "postgres.h"
16
17 #include "access/heapam_xlog.h"
18
19 static void
out_infobits(StringInfo buf,uint8 infobits)20 out_infobits(StringInfo buf, uint8 infobits)
21 {
22 if (infobits & XLHL_XMAX_IS_MULTI)
23 appendStringInfoString(buf, "IS_MULTI ");
24 if (infobits & XLHL_XMAX_LOCK_ONLY)
25 appendStringInfoString(buf, "LOCK_ONLY ");
26 if (infobits & XLHL_XMAX_EXCL_LOCK)
27 appendStringInfoString(buf, "EXCL_LOCK ");
28 if (infobits & XLHL_XMAX_KEYSHR_LOCK)
29 appendStringInfoString(buf, "KEYSHR_LOCK ");
30 if (infobits & XLHL_KEYS_UPDATED)
31 appendStringInfoString(buf, "KEYS_UPDATED ");
32 }
33
34 void
heap_desc(StringInfo buf,XLogReaderState * record)35 heap_desc(StringInfo buf, XLogReaderState *record)
36 {
37 char *rec = XLogRecGetData(record);
38 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
39
40 info &= XLOG_HEAP_OPMASK;
41 if (info == XLOG_HEAP_INSERT)
42 {
43 xl_heap_insert *xlrec = (xl_heap_insert *) rec;
44
45 appendStringInfo(buf, "off %u", xlrec->offnum);
46 }
47 else if (info == XLOG_HEAP_DELETE)
48 {
49 xl_heap_delete *xlrec = (xl_heap_delete *) rec;
50
51 appendStringInfo(buf, "off %u ", xlrec->offnum);
52 out_infobits(buf, xlrec->infobits_set);
53 }
54 else if (info == XLOG_HEAP_UPDATE)
55 {
56 xl_heap_update *xlrec = (xl_heap_update *) rec;
57
58 appendStringInfo(buf, "off %u xmax %u ",
59 xlrec->old_offnum,
60 xlrec->old_xmax);
61 out_infobits(buf, xlrec->old_infobits_set);
62 appendStringInfo(buf, "; new off %u xmax %u",
63 xlrec->new_offnum,
64 xlrec->new_xmax);
65 }
66 else if (info == XLOG_HEAP_HOT_UPDATE)
67 {
68 xl_heap_update *xlrec = (xl_heap_update *) rec;
69
70 appendStringInfo(buf, "off %u xmax %u ",
71 xlrec->old_offnum,
72 xlrec->old_xmax);
73 out_infobits(buf, xlrec->old_infobits_set);
74 appendStringInfo(buf, "; new off %u xmax %u",
75 xlrec->new_offnum,
76 xlrec->new_xmax);
77 }
78 else if (info == XLOG_HEAP_CONFIRM)
79 {
80 xl_heap_confirm *xlrec = (xl_heap_confirm *) rec;
81
82 appendStringInfo(buf, "off %u", xlrec->offnum);
83 }
84 else if (info == XLOG_HEAP_LOCK)
85 {
86 xl_heap_lock *xlrec = (xl_heap_lock *) rec;
87
88 appendStringInfo(buf, "off %u: xid %u: flags %u ",
89 xlrec->offnum, xlrec->locking_xid, xlrec->flags);
90 out_infobits(buf, xlrec->infobits_set);
91 }
92 else if (info == XLOG_HEAP_INPLACE)
93 {
94 xl_heap_inplace *xlrec = (xl_heap_inplace *) rec;
95
96 appendStringInfo(buf, "off %u", xlrec->offnum);
97 }
98 }
99 void
heap2_desc(StringInfo buf,XLogReaderState * record)100 heap2_desc(StringInfo buf, XLogReaderState *record)
101 {
102 char *rec = XLogRecGetData(record);
103 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
104
105 info &= XLOG_HEAP_OPMASK;
106 if (info == XLOG_HEAP2_CLEAN)
107 {
108 xl_heap_clean *xlrec = (xl_heap_clean *) rec;
109
110 appendStringInfo(buf, "remxid %u", xlrec->latestRemovedXid);
111 }
112 else if (info == XLOG_HEAP2_FREEZE_PAGE)
113 {
114 xl_heap_freeze_page *xlrec = (xl_heap_freeze_page *) rec;
115
116 appendStringInfo(buf, "cutoff xid %u ntuples %u",
117 xlrec->cutoff_xid, xlrec->ntuples);
118 }
119 else if (info == XLOG_HEAP2_CLEANUP_INFO)
120 {
121 xl_heap_cleanup_info *xlrec = (xl_heap_cleanup_info *) rec;
122
123 appendStringInfo(buf, "remxid %u", xlrec->latestRemovedXid);
124 }
125 else if (info == XLOG_HEAP2_VISIBLE)
126 {
127 xl_heap_visible *xlrec = (xl_heap_visible *) rec;
128
129 appendStringInfo(buf, "cutoff xid %u flags %d",
130 xlrec->cutoff_xid, xlrec->flags);
131 }
132 else if (info == XLOG_HEAP2_MULTI_INSERT)
133 {
134 xl_heap_multi_insert *xlrec = (xl_heap_multi_insert *) rec;
135
136 appendStringInfo(buf, "%d tuples", xlrec->ntuples);
137 }
138 else if (info == XLOG_HEAP2_LOCK_UPDATED)
139 {
140 xl_heap_lock_updated *xlrec = (xl_heap_lock_updated *) rec;
141
142 appendStringInfo(buf, "off %u: xmax %u: flags %u ",
143 xlrec->offnum, xlrec->xmax, xlrec->flags);
144 out_infobits(buf, xlrec->infobits_set);
145 }
146 else if (info == XLOG_HEAP2_NEW_CID)
147 {
148 xl_heap_new_cid *xlrec = (xl_heap_new_cid *) rec;
149
150 appendStringInfo(buf, "rel %u/%u/%u; tid %u/%u",
151 xlrec->target_node.spcNode,
152 xlrec->target_node.dbNode,
153 xlrec->target_node.relNode,
154 ItemPointerGetBlockNumber(&(xlrec->target_tid)),
155 ItemPointerGetOffsetNumber(&(xlrec->target_tid)));
156 appendStringInfo(buf, "; cmin: %u, cmax: %u, combo: %u",
157 xlrec->cmin, xlrec->cmax, xlrec->combocid);
158 }
159 }
160
161 const char *
heap_identify(uint8 info)162 heap_identify(uint8 info)
163 {
164 const char *id = NULL;
165
166 switch (info & ~XLR_INFO_MASK)
167 {
168 case XLOG_HEAP_INSERT:
169 id = "INSERT";
170 break;
171 case XLOG_HEAP_INSERT | XLOG_HEAP_INIT_PAGE:
172 id = "INSERT+INIT";
173 break;
174 case XLOG_HEAP_DELETE:
175 id = "DELETE";
176 break;
177 case XLOG_HEAP_UPDATE:
178 id = "UPDATE";
179 break;
180 case XLOG_HEAP_UPDATE | XLOG_HEAP_INIT_PAGE:
181 id = "UPDATE+INIT";
182 break;
183 case XLOG_HEAP_HOT_UPDATE:
184 id = "HOT_UPDATE";
185 break;
186 case XLOG_HEAP_HOT_UPDATE | XLOG_HEAP_INIT_PAGE:
187 id = "HOT_UPDATE+INIT";
188 break;
189 case XLOG_HEAP_CONFIRM:
190 id = "HEAP_CONFIRM";
191 break;
192 case XLOG_HEAP_LOCK:
193 id = "LOCK";
194 break;
195 case XLOG_HEAP_INPLACE:
196 id = "INPLACE";
197 break;
198 }
199
200 return id;
201 }
202
203 const char *
heap2_identify(uint8 info)204 heap2_identify(uint8 info)
205 {
206 const char *id = NULL;
207
208 switch (info & ~XLR_INFO_MASK)
209 {
210 case XLOG_HEAP2_CLEAN:
211 id = "CLEAN";
212 break;
213 case XLOG_HEAP2_FREEZE_PAGE:
214 id = "FREEZE_PAGE";
215 break;
216 case XLOG_HEAP2_CLEANUP_INFO:
217 id = "CLEANUP_INFO";
218 break;
219 case XLOG_HEAP2_VISIBLE:
220 id = "VISIBLE";
221 break;
222 case XLOG_HEAP2_MULTI_INSERT:
223 id = "MULTI_INSERT";
224 break;
225 case XLOG_HEAP2_MULTI_INSERT | XLOG_HEAP_INIT_PAGE:
226 id = "MULTI_INSERT+INIT";
227 break;
228 case XLOG_HEAP2_LOCK_UPDATED:
229 id = "LOCK_UPDATED";
230 break;
231 case XLOG_HEAP2_NEW_CID:
232 id = "NEW_CID";
233 break;
234 case XLOG_HEAP2_REWRITE:
235 id = "REWRITE";
236 break;
237 }
238
239 return id;
240 }
241