23 #include "catalog/pg_am_d.h"
52 #define NUM_OUTPUT_COLUMNS 10
80 for (blkno = 0; blkno < nblocks; blkno++)
97 stat->tuple_len += BLCKSZ - freespace;
98 stat->free_space += freespace;
167 stat->dead_tuple_count++;
170 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
178 stat->table_len = (uint64) nblocks * BLCKSZ;
199 stat->scanned_percent = 100.0 * scanned / nblocks;
200 stat->tuple_percent = 100.0 *
stat->tuple_len /
stat->table_len;
201 stat->dead_tuple_percent = 100.0 *
stat->dead_tuple_len /
stat->table_len;
202 stat->free_percent = 100.0 *
stat->free_space /
stat->table_len;
226 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
227 errmsg(
"must be superuser to use pgstattuple functions")));
259 elog(
ERROR,
"return type must be a row type");
262 elog(
ERROR,
"incorrect number of output arguments");
273 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
274 errmsg(
"cannot access temporary tables of other sessions")));
280 if (!(rel->
rd_rel->relkind == RELKIND_RELATION ||
281 rel->
rd_rel->relkind == RELKIND_MATVIEW ||
282 rel->
rd_rel->relkind == RELKIND_TOASTVALUE))
284 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
285 errmsg(
"relation \"%s\" is of wrong relation kind",
289 if (rel->
rd_rel->relam != HEAP_TABLE_AM_OID)
291 errmsg(
"only heap AM is supported")));
297 memset(nulls, 0,
sizeof(nulls));
static Datum values[MAXATTR]
void ReleaseBuffer(Buffer buffer)
void UnlockReleaseBuffer(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
#define BUFFER_LOCK_SHARE
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
static bool BufferIsValid(Buffer bufnum)
Size PageGetExactFreeSpace(Page page)
static bool PageIsEmpty(Page page)
static Item PageGetItem(Page page, ItemId itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static bool PageIsNew(Page page)
static OffsetNumber PageGetMaxOffsetNumber(Page page)
#define Assert(condition)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum Int64GetDatum(int64 X)
Datum Float8GetDatum(float8 X)
#define PG_RETURN_DATUM(x)
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
@ HEAPTUPLE_RECENTLY_DEAD
@ HEAPTUPLE_INSERT_IN_PROGRESS
@ HEAPTUPLE_DELETE_IN_PROGRESS
HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, Buffer buffer)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
HeapTupleHeaderData * HeapTupleHeader
#define ItemIdGetLength(itemId)
#define ItemIdIsNormal(itemId)
#define ItemIdIsDead(itemId)
#define ItemIdIsUsed(itemId)
#define ItemIdIsRedirected(itemId)
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
#define CHECK_FOR_INTERRUPTS()
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
int errdetail_relkind_not_supported(char relkind)
static void statapprox_heap(Relation rel, output_type *stat)
Datum pgstattuple_approx(PG_FUNCTION_ARGS)
#define NUM_OUTPUT_COLUMNS
struct output_type output_type
Datum pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
PG_FUNCTION_INFO_V1(pgstattuple_approx)
Datum pgstattuple_approx_v1_5(PG_FUNCTION_ARGS)
TransactionId GetOldestNonRemovableTransactionId(Relation rel)
#define RelationGetRelid(relation)
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
double dead_tuple_percent
double vac_estimate_reltuples(Relation relation, BlockNumber total_pages, BlockNumber scanned_pages, double scanned_tuples)
#define VM_ALL_VISIBLE(r, b, v)