18 #include "catalog/pg_am_d.h"
19 #include "catalog/pg_proc_d.h"
96 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
97 errmsg(
"recovery is in progress"),
98 errhint(
"Heap surgery functions cannot be executed during recovery.")));
108 if (!RELKIND_HAS_TABLE_AM(rel->
rd_rel->relkind))
110 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
111 errmsg(
"cannot operate on relation \"%s\"",
115 if (rel->
rd_rel->relam != HEAP_TABLE_AM_OID)
117 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
118 errmsg(
"only heap AM is supported")));
136 curr_start_ptr = next_start_ptr = 0;
142 while (next_start_ptr != ntids)
151 bool did_modify_page =
false;
152 bool did_modify_vm =
false;
163 if (blkno >= nblocks)
166 curr_start_ptr = next_start_ptr;
169 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
170 errmsg(
"skipping block %u for relation \"%s\" because the block number is out of range",
186 memset(include_this_tid, 0,
sizeof(include_this_tid));
187 for (
i = curr_start_ptr;
i < next_start_ptr;
i++)
196 errmsg(
"skipping tid (%u, %u) for relation \"%s\" because the item number is out of range",
207 errmsg(
"skipping tid (%u, %u) for relation \"%s\" because it redirects to item %u",
215 (
errmsg(
"skipping tid (%u, %u) for relation \"%s\" because it is marked dead",
222 (
errmsg(
"skipping tid (%u, %u) for relation \"%s\" because it is marked unused",
229 include_this_tid[offno] =
true;
247 if (!include_this_tid[curoff])
253 did_modify_page =
true;
269 did_modify_vm =
true;
335 curr_start_ptr = next_start_ptr;
374 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
375 errmsg(
"array must not contain nulls")));
379 (
errcode(ERRCODE_DATA_EXCEPTION),
380 errmsg(
"argument must be empty or one-dimensional array")));
403 for (
i = *next_start_ptr;
i < ntids;
i++)
409 if (
i == *next_start_ptr)
412 if (prev_blkno != blkno)
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)
bool array_contains_nulls(ArrayType *array)
int ArrayGetNItems(int ndim, const int *dims)
#define InvalidBlockNumber
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,...)
#define PG_RETURN_DATUM(x)
Datum heap_force_freeze(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(heap_force_kill)
Datum heap_force_kill(PG_FUNCTION_ARGS)
static int32 tidcmp(const void *a, const void *b)
static BlockNumber find_tids_one_page(ItemPointer tids, int ntids, OffsetNumber *next_start_ptr)
static Datum heap_force_common(FunctionCallInfo fcinfo, HeapTupleForceOption heap_force_opt)
static void sanity_check_tid_array(ArrayType *ta, int *ntids)
HeapTupleHeaderData * HeapTupleHeader
#define HEAP_KEYS_UPDATED
#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)
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
static OffsetNumber ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumberNoCheck(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)