19#include "catalog/pg_am_d.h"
46#define NUM_OUTPUT_COLUMNS 10
74 for (blkno = 0; blkno < nblocks; blkno++)
91 stat->tuple_len += BLCKSZ - freespace;
92 stat->free_space += freespace;
161 stat->dead_tuple_count++;
164 elog(
ERROR,
"unexpected HeapTupleSatisfiesVacuum result");
193 stat->scanned_percent = 100.0 * scanned / nblocks;
194 stat->tuple_percent = 100.0 *
stat->tuple_len /
stat->table_len;
195 stat->dead_tuple_percent = 100.0 *
stat->dead_tuple_len /
stat->table_len;
196 stat->free_percent = 100.0 *
stat->free_space /
stat->table_len;
220 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
221 errmsg(
"must be superuser to use pgstattuple functions")));
253 elog(
ERROR,
"return type must be a row type");
256 elog(
ERROR,
"incorrect number of output arguments");
267 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
268 errmsg(
"cannot access temporary tables of other sessions")));
274 if (!(rel->
rd_rel->relkind == RELKIND_RELATION ||
275 rel->
rd_rel->relkind == RELKIND_MATVIEW ||
276 rel->
rd_rel->relkind == RELKIND_TOASTVALUE))
278 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
279 errmsg(
"relation \"%s\" is of wrong relation kind",
283 if (rel->
rd_rel->relam != HEAP_TABLE_AM_OID)
285 errmsg(
"only heap AM is supported")));
291 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)