83{
87 int ntids,
88 nblocks;
91 next_start_ptr;
93
96 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
97 errmsg(
"recovery is in progress"),
98 errhint(
"Heap surgery functions cannot be executed during recovery.")));
99
100
102
104
105
106
107
108 if (!RELKIND_HAS_TABLE_AM(rel->
rd_rel->relkind))
110 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
111 errmsg(
"cannot operate on relation \"%s\"",
114
115 if (rel->
rd_rel->relam != HEAP_TABLE_AM_OID)
117 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
118 errmsg(
"only heap AM is supported")));
119
120
125
127
128
129
130
131
132
133 if (ntids > 1)
135
136 curr_start_ptr = next_start_ptr = 0;
138
139
140
141
142 while (next_start_ptr != ntids)
143 {
151 bool did_modify_page = false;
152 bool did_modify_vm = false;
153
155
156
157
158
159
161
162
163 if (blkno >= nblocks)
164 {
165
166 curr_start_ptr = next_start_ptr;
167
169 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
170 errmsg(
"skipping block %u for relation \"%s\" because the block number is out of range",
172 continue;
173 }
174
177
179
181
182
183
184
185
186 memset(include_this_tid, 0, sizeof(include_this_tid));
187 for (
i = curr_start_ptr;
i < next_start_ptr;
i++)
188 {
191
192
194 {
196 errmsg(
"skipping tid (%u, %u) for relation \"%s\" because the item number is out of range",
198 continue;
199 }
200
202
203
205 {
207 errmsg(
"skipping tid (%u, %u) for relation \"%s\" because it redirects to item %u",
210 continue;
211 }
213 {
215 (
errmsg(
"skipping tid (%u, %u) for relation \"%s\" because it is marked dead",
217 continue;
218 }
220 {
222 (
errmsg(
"skipping tid (%u, %u) for relation \"%s\" because it is marked unused",
224 continue;
225 }
226
227
229 include_this_tid[offno] = true;
230 }
231
232
233
234
235
238
239
241
244 {
246
247 if (!include_this_tid[curoff])
248 continue;
249
252
253 did_modify_page = true;
254
256 {
258
259
260
261
262
263
265 {
269 did_modify_vm = true;
270 }
271 }
272 else
273 {
275
277
279
280
281
282
283
284
285
290 {
293 else
295 }
296
297
298
299
300
301
306 }
307 }
308
309
310
311
312
313 if (did_modify_page)
314 {
315
317
318
321 }
322
323
326
328
330
333
334
335 curr_start_ptr = next_start_ptr;
336 }
337
339
341
343}
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
void ReleaseBuffer(Buffer buffer)
void UnlockReleaseBuffer(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBufferForCleanup(Buffer buffer)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
static Item PageGetItem(Page page, ItemId itemId)
static void PageClearAllVisible(Page page)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static bool PageIsAllVisible(Page page)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
#define Assert(condition)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
static int32 tidcmp(const void *a, const void *b)
static BlockNumber find_tids_one_page(ItemPointer tids, int ntids, OffsetNumber *next_start_ptr)
static void sanity_check_tid_array(ArrayType *ta, int *ntids)
HeapTupleHeaderData * HeapTupleHeader
#define HeapTupleHeaderSetXmin(tup, xid)
#define HeapTupleHeaderSetXmax(tup, xid)
#define HeapTupleHeaderSetXvac(tup, xid)
#define HEAP_XMAX_INVALID
#define MaxHeapTuplesPerPage
#define ItemIdIsNormal(itemId)
#define ItemIdGetRedirect(itemId)
#define ItemIdIsDead(itemId)
#define ItemIdSetDead(itemId)
#define ItemIdIsUsed(itemId)
#define ItemIdIsRedirected(itemId)
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
static OffsetNumber ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
ItemPointerData * ItemPointer
void pfree(void *pointer)
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define END_CRIT_SECTION()
ObjectType get_relkind_objtype(char relkind)
#define InvalidOffsetNumber
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
int errdetail_relkind_not_supported(char relkind)
#define qsort(a, b, c, d)
#define RelationGetRelid(relation)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(relation)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
#define FrozenTransactionId
#define InvalidTransactionId
bool visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf, uint8 flags)
void visibilitymap_pin(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
#define VISIBILITYMAP_VALID_BITS
bool RecoveryInProgress(void)
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)