/* Options to forcefully change the state of a heap tuple. */ typedefenum HeapTupleForceOption
{
HEAP_FORCE_KILL,
HEAP_FORCE_FREEZE,
} HeapTupleForceOption;
if (RecoveryInProgress())
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("recovery is in progress"),
errhint("Heap surgery functions cannot be executed during recovery.")));
/* *Checktargetrelation.
*/ if (!RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot operate on relation \"%s\"",
RelationGetRelationName(rel)),
errdetail_relkind_not_supported(rel->rd_rel->relkind)));
if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("only heap AM is supported")));
/* Must be owner of the table or superuser. */ if (!object_ownercheck(RelationRelationId, RelationGetRelid(rel), GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER,
get_relkind_objtype(rel->rd_rel->relkind),
RelationGetRelationName(rel));
/* Check whether the block number is valid. */ if (blkno >= nblocks)
{ /* Update the current_start_ptr before moving to the next page. */
curr_start_ptr = next_start_ptr;
ereport(NOTICE,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("skipping block %u for relation \"%s\" because the block number is out of range",
blkno, RelationGetRelationName(rel)))); continue;
}
/* *FigureoutwhichTIDswearegoingtoprocessandwhichonesweare *goingtoskip.
*/
memset(include_this_tid, 0, sizeof(include_this_tid)); for (i = curr_start_ptr; i < next_start_ptr; i++)
{
OffsetNumber offno = ItemPointerGetOffsetNumberNoCheck(&tids[i]);
ItemId itemid;
/* Check whether the offset number is valid. */ if (offno == InvalidOffsetNumber || offno > maxoffset)
{
ereport(NOTICE,
errmsg("skipping tid (%u, %u) for relation \"%s\" because the item number is out of range",
blkno, offno, RelationGetRelationName(rel))); continue;
}
itemid = PageGetItemId(page, offno);
/* Only accept an item ID that is used. */ if (ItemIdIsRedirected(itemid))
{
ereport(NOTICE,
errmsg("skipping tid (%u, %u) for relation \"%s\" because it redirects to item %u",
blkno, offno, RelationGetRelationName(rel),
ItemIdGetRedirect(itemid))); continue;
} elseif (ItemIdIsDead(itemid))
{
ereport(NOTICE,
(errmsg("skipping tid (%u, %u) for relation \"%s\" because it is marked dead",
blkno, offno, RelationGetRelationName(rel)))); continue;
} elseif (!ItemIdIsUsed(itemid))
{
ereport(NOTICE,
(errmsg("skipping tid (%u, %u) for relation \"%s\" because it is marked unused",
blkno, offno, RelationGetRelationName(rel)))); continue;
}
/* Mark it for processing. */
Assert(offno < MaxHeapTuplesPerPage);
include_this_tid[offno] = true;
}
/* *Ifthepagewasmodified,onlythen,wemarkthebufferdirtyordo *theWALlogging.
*/ if (did_modify_page)
{ /* Mark buffer dirty before we write WAL. */
MarkBufferDirty(buf);
/* XLOG stuff */ if (RelationNeedsWAL(rel))
log_newpage_buffer(buf, true);
}
/* WAL log the VM page if it was modified. */ if (did_modify_vm && RelationNeedsWAL(rel))
log_newpage_buffer(vmbuf, false);
END_CRIT_SECTION();
UnlockReleaseBuffer(buf);
if (vmbuf != InvalidBuffer)
ReleaseBuffer(vmbuf);
/* Update the current_start_ptr before moving to the next page. */
curr_start_ptr = next_start_ptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.