PostgreSQL Source Code: contrib/pgstattuple/pgstatapprox.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
14
19#include "catalog/pg_am_d.h"
26
29
31
33{
45
46#define NUM_OUTPUT_COLUMNS 10
47
48
49
50
51
52
53
54
55
56
57
58static void
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}
205
206
207
208
209
210
211
212
215{
217
220 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
221 errmsg("must be superuser to use pgstattuple functions")));
222
224}
225
226
227
228
229
230
231
232
235{
237
239}
240
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]
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)
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)
Assert(PointerIsAligned(start, uint64))
@ 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)