PostgreSQL Source Code: contrib/pgstattuple/pgstatapprox.c File Reference (original) (raw)
Go to the source code of this file.
Functions | |
---|---|
PG_FUNCTION_INFO_V1 (pgstattuple_approx) | |
PG_FUNCTION_INFO_V1 (pgstattuple_approx_v1_5) | |
Datum | pgstattuple_approx_internal (Oid relid, FunctionCallInfo fcinfo) |
static void | statapprox_heap (Relation rel, output_type *stat) |
Datum | pgstattuple_approx (PG_FUNCTION_ARGS) |
Datum | pgstattuple_approx_v1_5 (PG_FUNCTION_ARGS) |
◆ NUM_OUTPUT_COLUMNS
#define NUM_OUTPUT_COLUMNS 10
◆ output_type
◆ PG_FUNCTION_INFO_V1() [1/2]
◆ PG_FUNCTION_INFO_V1() [2/2]
◆ pgstattuple_approx()
Definition at line 214 of file pgstatapprox.c.
215{
217
220 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
221 errmsg("must be superuser to use pgstattuple functions")));
222
224}
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_RETURN_DATUM(x)
Datum pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_OID, PG_RETURN_DATUM, pgstattuple_approx_internal(), and superuser().
◆ pgstattuple_approx_internal()
Definition at line 242 of file pgstatapprox.c.
243{
250 int i = 0;
251
253 elog(ERROR, "return type must be a row type");
254
256 elog(ERROR, "incorrect number of output arguments");
257
259
260
261
262
263
264
267 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
268 errmsg("cannot access temporary tables of other sessions")));
269
270
271
272
273
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",
282
283 if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
285 errmsg("only heap AM is supported")));
286
288
290
291 memset(nulls, 0, sizeof(nulls));
292
303
306}
static Datum values[MAXATTR]
Datum Int64GetDatum(int64 X)
Datum Float8GetDatum(float8 X)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
int errdetail_relkind_not_supported(char relkind)
static void statapprox_heap(Relation rel, output_type *stat)
#define NUM_OUTPUT_COLUMNS
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
References AccessShareLock, elog, ereport, errcode(), errdetail_relkind_not_supported(), errmsg(), ERROR, Float8GetDatum(), get_call_result_type(), heap_form_tuple(), HeapTupleGetDatum(), i, Int64GetDatum(), TupleDescData::natts, NUM_OUTPUT_COLUMNS, RelationData::rd_rel, relation_close(), RELATION_IS_OTHER_TEMP, relation_open(), RelationGetRelationName, statapprox_heap(), TYPEFUNC_COMPOSITE, and values.
Referenced by pgstattuple_approx(), and pgstattuple_approx_v1_5().
◆ pgstattuple_approx_v1_5()
◆ statapprox_heap()
Definition at line 59 of file pgstatapprox.c.
60{
62 nblocks,
63 blkno;
67
70
72 scanned = 0;
73
74 for (blkno = 0; blkno < nblocks; blkno++)
75 {
79 maxoff;
80 Size freespace;
81
83
84
85
86
87
89 {
91 stat->tuple_len += BLCKSZ - freespace;
92 stat->free_space += freespace;
93 continue;
94 }
95
98
100
102
104
105
106 scanned++;
107
109 {
111 continue;
112 }
113
114
115
116
117
118
120
122 offnum <= maxoff;
124 {
127
129
132 {
133 continue;
134 }
135
137
139
143
144
145
146
147
148
149
151 {
155 stat->tuple_count++;
156 break;
160 stat->dead_tuple_len += tuple.t_len;
161 stat->dead_tuple_count++;
162 break;
163 default:
164 elog(ERROR, "unexpected HeapTupleSatisfiesVacuum result");
165 break;
166 }
167 }
168
170 }
171
172 stat->table_len = (uint64) nblocks * BLCKSZ;
173
174
175
176
177
178
179
180
181
183 stat->tuple_count);
184
185
186 stat->tuple_count = Max(stat->tuple_count, 0);
187
188
189
190
191 if (nblocks != 0)
192 {
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;
197 }
198
200 {
203 }
204}
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(const PageData *page)
static bool PageIsEmpty(const PageData *page)
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
static bool PageIsNew(const PageData *page)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
Assert(PointerIsAligned(start, uint64))
@ HEAPTUPLE_RECENTLY_DEAD
@ HEAPTUPLE_INSERT_IN_PROGRESS
@ HEAPTUPLE_DELETE_IN_PROGRESS
HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, Buffer buffer)
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
TransactionId GetOldestNonRemovableTransactionId(Relation rel)
#define RelationGetRelid(relation)
double vac_estimate_reltuples(Relation relation, BlockNumber total_pages, BlockNumber scanned_pages, double scanned_tuples)
#define VM_ALL_VISIBLE(r, b, v)
References Assert(), BAS_BULKREAD, buf, BUFFER_LOCK_SHARE, BufferGetPage(), BufferIsValid(), CHECK_FOR_INTERRUPTS, elog, ERROR, FirstOffsetNumber, GetAccessStrategy(), GetOldestNonRemovableTransactionId(), GetRecordedFreeSpace(), HEAPTUPLE_DEAD, HEAPTUPLE_DELETE_IN_PROGRESS, HEAPTUPLE_INSERT_IN_PROGRESS, HEAPTUPLE_LIVE, HEAPTUPLE_RECENTLY_DEAD, HeapTupleSatisfiesVacuum(), InvalidBuffer, ItemIdGetLength, ItemIdIsDead, ItemIdIsNormal, ItemIdIsRedirected, ItemIdIsUsed, ItemPointerSet(), LockBuffer(), MAIN_FORKNUM, Max, OffsetNumberNext, PageGetExactFreeSpace(), PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), PageIsEmpty(), PageIsNew(), RBM_NORMAL, ReadBufferExtended(), RelationGetNumberOfBlocks, RelationGetRelid, ReleaseBuffer(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, UnlockReleaseBuffer(), vac_estimate_reltuples(), and VM_ALL_VISIBLE.
Referenced by pgstattuple_approx_internal().