PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pgstatindex.c
Go to the documentation of this file.
1/*
2 * contrib/pgstattuple/pgstatindex.c
3 *
4 *
5 * pgstatindex
6 *
7 * Copyright (c) 2006 Satoshi Nagayasu <nagayasus@nttdata.co.jp>
8 *
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose, without fee, and without a
11 * written agreement is hereby granted, provided that the above
12 * copyright notice and this paragraph and the following two
13 * paragraphs appear in all copies.
14 *
15 * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
16 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
17 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
18 * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
19 * OF THE POSSIBILITY OF SUCH DAMAGE.
20 *
21 * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
24 * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
25 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
26 */
27
28#include "postgres.h"
29
30#include "access/gin_private.h"
31#include "access/hash.h"
32#include "access/htup_details.h"
33#include "access/nbtree.h"
34#include "access/relation.h"
35#include "catalog/namespace.h"
36#include "catalog/pg_am.h"
37#include "funcapi.h"
38#include "miscadmin.h"
39#include "storage/bufmgr.h"
40#include "utils/rel.h"
41#include "utils/varlena.h"
42
43
44/*
45 * Because of backward-compatibility issue, we have decided to have
46 * two types of interfaces, with regclass-type input arg and text-type
47 * input arg, for each function.
48 *
49 * Those functions which have text-type input arg will be deprecated
50 * in the future release.
51 */
58
64
66
67#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
68#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
69#define IS_GIN(r) ((r)->rd_rel->relam == GIN_AM_OID)
70#define IS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID)
71
72/* ------------------------------------------------
73 * A structure for a whole btree index statistics
74 * used by pgstatindex().
75 * ------------------------------------------------
76 */
77typedef struct BTIndexStat
78{
82
87
90
93
94/* ------------------------------------------------
95 * A structure for a whole GIN index statistics
96 * used by pgstatginindex().
97 * ------------------------------------------------
98 */
99typedef struct GinIndexStat
100{
102
106
107/* ------------------------------------------------
108 * A structure for a whole HASH index statistics
109 * used by pgstathashindex().
110 * ------------------------------------------------
111 */
112typedef struct HashIndexStat
113{
116
121
126
129static void GetHashPageStats(Page page, HashIndexStat *stats);
130
131/* ------------------------------------------------------
132 * pgstatindex()
133 *
134 * Usage: SELECT * FROM pgstatindex('t1_pkey');
135 *
136 * The superuser() check here must be kept as the library might be upgraded
137 * without the extension being upgraded, meaning that in pre-1.5 installations
138 * these functions could be called by any user.
139 * ------------------------------------------------------
140 */
141Datum
143{
145 Relation rel;
146 RangeVar *relrv;
147
148 if (!superuser())
150 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
151 errmsg("must be superuser to use pgstattuple functions")));
152
154 rel = relation_openrv(relrv, AccessShareLock);
155
156 PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
157}
158
159/*
160 * As of pgstattuple version 1.5, we no longer need to check if the user
161 * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
162 * Users can then grant access to it based on their policies.
163 *
164 * Otherwise identical to pgstatindex (above).
165 */
166Datum
168{
170 Relation rel;
171 RangeVar *relrv;
172
174 rel = relation_openrv(relrv, AccessShareLock);
175
176 PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
177}
178
179/*
180 * The superuser() check here must be kept as the library might be upgraded
181 * without the extension being upgraded, meaning that in pre-1.5 installations
182 * these functions could be called by any user.
183 */
184Datum
186{
187 Oid relid = PG_GETARG_OID(0);
188 Relation rel;
189
190 if (!superuser())
192 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
193 errmsg("must be superuser to use pgstattuple functions")));
194
195 rel = relation_open(relid, AccessShareLock);
196
197 PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
198}
199
200/* No need for superuser checks in v1.5, see above */
201Datum
203{
204 Oid relid = PG_GETARG_OID(0);
205 Relation rel;
206
207 rel = relation_open(relid, AccessShareLock);
208
209 PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
210}
211
212static Datum
214{
215 Datum result;
216 BlockNumber nblocks;
217 BlockNumber blkno;
218 BTIndexStat indexStat;
220
221 if (!IS_INDEX(rel) || !IS_BTREE(rel))
223 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
224 errmsg("relation \"%s\" is not a btree index",
226
227 /*
228 * Reject attempts to read non-local temporary relations; we would be
229 * likely to get wrong data since we have no visibility into the owning
230 * session's local buffers.
231 */
232 if (RELATION_IS_OTHER_TEMP(rel))
234 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
235 errmsg("cannot access temporary tables of other sessions")));
236
237 /*
238 * A !indisready index could lead to ERRCODE_DATA_CORRUPTED later, so exit
239 * early. We're capable of assessing an indisready&&!indisvalid index,
240 * but the results could be confusing. For example, the index's size
241 * could be too low for a valid index of the table.
242 */
243 if (!rel->rd_index->indisvalid)
245 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
246 errmsg("index \"%s\" is not valid",
248
249 /*
250 * Read metapage
251 */
252 {
253 Buffer buffer = ReadBufferExtended(rel, MAIN_FORKNUM, 0, RBM_NORMAL, bstrategy);
254 Page page = BufferGetPage(buffer);
255 BTMetaPageData *metad = BTPageGetMeta(page);
256
257 indexStat.version = metad->btm_version;
258 indexStat.level = metad->btm_level;
259 indexStat.root_blkno = metad->btm_root;
260
261 ReleaseBuffer(buffer);
262 }
263
264 /* -- init counters -- */
265 indexStat.internal_pages = 0;
266 indexStat.leaf_pages = 0;
267 indexStat.empty_pages = 0;
268 indexStat.deleted_pages = 0;
269
270 indexStat.max_avail = 0;
271 indexStat.free_space = 0;
272
273 indexStat.fragments = 0;
274
275 /*
276 * Scan all blocks except the metapage
277 */
278 nblocks = RelationGetNumberOfBlocks(rel);
279
280 for (blkno = 1; blkno < nblocks; blkno++)
281 {
282 Buffer buffer;
283 Page page;
284 BTPageOpaque opaque;
285
287
288 /* Read and lock buffer */
289 buffer = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
291
292 page = BufferGetPage(buffer);
293 opaque = BTPageGetOpaque(page);
294
295 /*
296 * Determine page type, and update totals.
297 *
298 * Note that we arbitrarily bucket deleted pages together without
299 * considering if they're leaf pages or internal pages.
300 */
301 if (P_ISDELETED(opaque))
302 indexStat.deleted_pages++;
303 else if (P_IGNORE(opaque))
304 indexStat.empty_pages++; /* this is the "half dead" state */
305 else if (P_ISLEAF(opaque))
306 {
307 int max_avail;
308
309 max_avail = BLCKSZ - (BLCKSZ - ((PageHeader) page)->pd_special + SizeOfPageHeaderData);
310 indexStat.max_avail += max_avail;
311 indexStat.free_space += PageGetExactFreeSpace(page);
312
313 indexStat.leaf_pages++;
314
315 /*
316 * If the next leaf is on an earlier block, it means a
317 * fragmentation.
318 */
319 if (opaque->btpo_next != P_NONE && opaque->btpo_next < blkno)
320 indexStat.fragments++;
321 }
322 else
323 indexStat.internal_pages++;
324
325 /* Unlock and release buffer */
327 ReleaseBuffer(buffer);
328 }
329
331
332 /*----------------------------
333 * Build a result tuple
334 *----------------------------
335 */
336 {
337 TupleDesc tupleDesc;
338 int j;
339 char *values[10];
340 HeapTuple tuple;
341
342 /* Build a tuple descriptor for our result type */
343 if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
344 elog(ERROR, "return type must be a row type");
345
346 j = 0;
347 values[j++] = psprintf("%d", indexStat.version);
348 values[j++] = psprintf("%d", indexStat.level);
350 (1 + /* include the metapage in index_size */
351 indexStat.leaf_pages +
352 indexStat.internal_pages +
353 indexStat.deleted_pages +
354 indexStat.empty_pages) * BLCKSZ);
355 values[j++] = psprintf("%u", indexStat.root_blkno);
357 values[j++] = psprintf(INT64_FORMAT, indexStat.leaf_pages);
358 values[j++] = psprintf(INT64_FORMAT, indexStat.empty_pages);
359 values[j++] = psprintf(INT64_FORMAT, indexStat.deleted_pages);
360 if (indexStat.max_avail > 0)
361 values[j++] = psprintf("%.2f",
362 100.0 - (double) indexStat.free_space / (double) indexStat.max_avail * 100.0);
363 else
364 values[j++] = pstrdup("NaN");
365 if (indexStat.leaf_pages > 0)
366 values[j++] = psprintf("%.2f",
367 (double) indexStat.fragments / (double) indexStat.leaf_pages * 100.0);
368 else
369 values[j++] = pstrdup("NaN");
370
372 values);
373
374 result = HeapTupleGetDatum(tuple);
375 }
376
377 return result;
378}
379
380/* --------------------------------------------------------
381 * pg_relpages()
382 *
383 * Get the number of pages of the table/index.
384 *
385 * Usage: SELECT pg_relpages('t1');
386 * SELECT pg_relpages('t1_pkey');
387 *
388 * Must keep superuser() check, see above.
389 * --------------------------------------------------------
390 */
391Datum
393{
395 Relation rel;
396 RangeVar *relrv;
397
398 if (!superuser())
400 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
401 errmsg("must be superuser to use pgstattuple functions")));
402
404 rel = relation_openrv(relrv, AccessShareLock);
405
407}
408
409/* No need for superuser checks in v1.5, see above */
410Datum
412{
414 Relation rel;
415 RangeVar *relrv;
416
418 rel = relation_openrv(relrv, AccessShareLock);
419
421}
422
423/* Must keep superuser() check, see above. */
424Datum
426{
427 Oid relid = PG_GETARG_OID(0);
428 Relation rel;
429
430 if (!superuser())
432 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
433 errmsg("must be superuser to use pgstattuple functions")));
434
435 rel = relation_open(relid, AccessShareLock);
436
438}
439
440/* No need for superuser checks in v1.5, see above */
441Datum
443{
444 Oid relid = PG_GETARG_OID(0);
445 Relation rel;
446
447 rel = relation_open(relid, AccessShareLock);
448
450}
451
452static int64
454{
455 int64 relpages;
456
457 if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
459 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
460 errmsg("cannot get page count of relation \"%s\"",
463
464 /* note: this will work OK on non-local temp tables */
465
466 relpages = RelationGetNumberOfBlocks(rel);
467
469
470 return relpages;
471}
472
473/* ------------------------------------------------------
474 * pgstatginindex()
475 *
476 * Usage: SELECT * FROM pgstatginindex('ginindex');
477 *
478 * Must keep superuser() check, see above.
479 * ------------------------------------------------------
480 */
481Datum
483{
484 Oid relid = PG_GETARG_OID(0);
485
486 if (!superuser())
488 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
489 errmsg("must be superuser to use pgstattuple functions")));
490
492}
493
494/* No need for superuser checks in v1.5, see above */
495Datum
497{
498 Oid relid = PG_GETARG_OID(0);
499
501}
502
503Datum
505{
506 Relation rel;
507 Buffer buffer;
508 Page page;
509 GinMetaPageData *metadata;
510 GinIndexStat stats;
511 HeapTuple tuple;
512 TupleDesc tupleDesc;
513 Datum values[3];
514 bool nulls[3] = {false, false, false};
515 Datum result;
516
517 rel = relation_open(relid, AccessShareLock);
518
519 if (!IS_INDEX(rel) || !IS_GIN(rel))
521 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
522 errmsg("relation \"%s\" is not a GIN index",
524
525 /*
526 * Reject attempts to read non-local temporary relations; we would be
527 * likely to get wrong data since we have no visibility into the owning
528 * session's local buffers.
529 */
530 if (RELATION_IS_OTHER_TEMP(rel))
532 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
533 errmsg("cannot access temporary indexes of other sessions")));
534
535 /* see pgstatindex_impl */
536 if (!rel->rd_index->indisvalid)
538 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
539 errmsg("index \"%s\" is not valid",
541
542 /*
543 * Read metapage
544 */
545 buffer = ReadBuffer(rel, GIN_METAPAGE_BLKNO);
546 LockBuffer(buffer, GIN_SHARE);
547 page = BufferGetPage(buffer);
548 metadata = GinPageGetMeta(page);
549
550 stats.version = metadata->ginVersion;
551 stats.pending_pages = metadata->nPendingPages;
552 stats.pending_tuples = metadata->nPendingHeapTuples;
553
554 UnlockReleaseBuffer(buffer);
556
557 /*
558 * Build a tuple descriptor for our result type
559 */
560 if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
561 elog(ERROR, "return type must be a row type");
562
563 values[0] = Int32GetDatum(stats.version);
566
567 /*
568 * Build and return the tuple
569 */
570 tuple = heap_form_tuple(tupleDesc, values, nulls);
571 result = HeapTupleGetDatum(tuple);
572
573 return result;
574}
575
576/* ------------------------------------------------------
577 * pgstathashindex()
578 *
579 * Usage: SELECT * FROM pgstathashindex('hashindex');
580 * ------------------------------------------------------
581 */
582Datum
584{
585 Oid relid = PG_GETARG_OID(0);
586 BlockNumber nblocks;
587 BlockNumber blkno;
588 Relation rel;
589 HashIndexStat stats;
590 BufferAccessStrategy bstrategy;
591 HeapTuple tuple;
592 TupleDesc tupleDesc;
593 Datum values[8];
594 bool nulls[8] = {0};
595 Buffer metabuf;
596 HashMetaPage metap;
597 float8 free_percent;
598 uint64 total_space;
599
600 rel = relation_open(relid, AccessShareLock);
601
602 if (!IS_INDEX(rel) || !IS_HASH(rel))
604 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
605 errmsg("relation \"%s\" is not a hash index",
607
608 /*
609 * Reject attempts to read non-local temporary relations; we would be
610 * likely to get wrong data since we have no visibility into the owning
611 * session's local buffers.
612 */
613 if (RELATION_IS_OTHER_TEMP(rel))
615 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
616 errmsg("cannot access temporary indexes of other sessions")));
617
618 /* see pgstatindex_impl */
619 if (!rel->rd_index->indisvalid)
621 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
622 errmsg("index \"%s\" is not valid",
624
625 /* Get the information we need from the metapage. */
626 memset(&stats, 0, sizeof(stats));
628 metap = HashPageGetMeta(BufferGetPage(metabuf));
629 stats.version = metap->hashm_version;
630 stats.space_per_page = metap->hashm_bsize;
631 _hash_relbuf(rel, metabuf);
632
633 /* Get the current relation length */
634 nblocks = RelationGetNumberOfBlocks(rel);
635
636 /* prepare access strategy for this index */
637 bstrategy = GetAccessStrategy(BAS_BULKREAD);
638
639 /* Start from blkno 1 as 0th block is metapage */
640 for (blkno = 1; blkno < nblocks; blkno++)
641 {
642 Buffer buf;
643 Page page;
644
646
648 bstrategy);
650 page = (Page) BufferGetPage(buf);
651
652 if (PageIsNew(page))
653 stats.unused_pages++;
654 else if (PageGetSpecialSize(page) !=
657 (errcode(ERRCODE_INDEX_CORRUPTED),
658 errmsg("index \"%s\" contains corrupted page at block %u",
661 else
662 {
663 HashPageOpaque opaque;
664 int pagetype;
665
666 opaque = HashPageGetOpaque(page);
667 pagetype = opaque->hasho_flag & LH_PAGE_TYPE;
668
669 if (pagetype == LH_BUCKET_PAGE)
670 {
671 stats.bucket_pages++;
672 GetHashPageStats(page, &stats);
673 }
674 else if (pagetype == LH_OVERFLOW_PAGE)
675 {
676 stats.overflow_pages++;
677 GetHashPageStats(page, &stats);
678 }
679 else if (pagetype == LH_BITMAP_PAGE)
680 stats.bitmap_pages++;
681 else if (pagetype == LH_UNUSED_PAGE)
682 stats.unused_pages++;
683 else
685 (errcode(ERRCODE_INDEX_CORRUPTED),
686 errmsg("unexpected page type 0x%04X in HASH index \"%s\" block %u",
689 }
691 }
692
693 /* Done accessing the index */
695
696 /* Count unused pages as free space. */
697 stats.free_space += (uint64) stats.unused_pages * stats.space_per_page;
698
699 /*
700 * Total space available for tuples excludes the metapage and the bitmap
701 * pages.
702 */
703 total_space = (uint64) (nblocks - (stats.bitmap_pages + 1)) *
704 stats.space_per_page;
705
706 if (total_space == 0)
707 free_percent = 0.0;
708 else
709 free_percent = 100.0 * stats.free_space / total_space;
710
711 /*
712 * Build a tuple descriptor for our result type
713 */
714 if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
715 elog(ERROR, "return type must be a row type");
716
717 tupleDesc = BlessTupleDesc(tupleDesc);
718
719 /*
720 * Build and return the tuple
721 */
722 values[0] = Int32GetDatum(stats.version);
727 values[5] = Int64GetDatum(stats.live_items);
728 values[6] = Int64GetDatum(stats.dead_items);
729 values[7] = Float8GetDatum(free_percent);
730 tuple = heap_form_tuple(tupleDesc, values, nulls);
731
733}
734
735/* -------------------------------------------------
736 * GetHashPageStats()
737 *
738 * Collect statistics of single hash page
739 * -------------------------------------------------
740 */
741static void
743{
745 int off;
746
747 /* count live and dead tuples, and free space */
748 for (off = FirstOffsetNumber; off <= maxoff; off++)
749 {
750 ItemId id = PageGetItemId(page, off);
751
752 if (!ItemIdIsDead(id))
753 stats->live_items++;
754 else
755 stats->dead_items++;
756 }
757 stats->free_space += PageGetExactFreeSpace(page);
758}
uint32 BlockNumber
Definition: block.h:31
static Datum values[MAXATTR]
Definition: bootstrap.c:151
int Buffer
Definition: buf.h:23
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:3724
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4924
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4941
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:5158
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:793
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:746
@ BAS_BULKREAD
Definition: bufmgr.h:36
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:189
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:190
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:273
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:400
@ RBM_NORMAL
Definition: bufmgr.h:45
Size PageGetExactFreeSpace(Page page)
Definition: bufpage.c:947
PageHeaderData * PageHeader
Definition: bufpage.h:173
Pointer Page
Definition: bufpage.h:81
#define SizeOfPageHeaderData
Definition: bufpage.h:216
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:243
static bool PageIsNew(Page page)
Definition: bufpage.h:233
static OffsetNumber PageGetMaxOffsetNumber(Page page)
Definition: bufpage.h:372
static uint16 PageGetSpecialSize(Page page)
Definition: bufpage.h:316
#define MAXALIGN(LEN)
Definition: c.h:765
#define INT64_FORMAT
Definition: c.h:503
int64_t int64
Definition: c.h:482
double float8
Definition: c.h:584
int32_t int32
Definition: c.h:481
uint64_t uint64
Definition: c.h:486
uint32_t uint32
Definition: c.h:485
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2258
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2322
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2273
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1816
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:541
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
#define GIN_SHARE
Definition: gin_private.h:50
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:51
#define GinPageGetMeta(p)
Definition: ginblock.h:104
#define HashPageGetOpaque(page)
Definition: hash.h:88
#define LH_BUCKET_PAGE
Definition: hash.h:55
#define LH_UNUSED_PAGE
Definition: hash.h:53
#define LH_META_PAGE
Definition: hash.h:57
#define HashPageGetMeta(page)
Definition: hash.h:323
#define HASH_READ
Definition: hash.h:339
#define HASH_METAPAGE
Definition: hash.h:198
#define LH_PAGE_TYPE
Definition: hash.h:63
#define LH_BITMAP_PAGE
Definition: hash.h:56
#define LH_OVERFLOW_PAGE
Definition: hash.h:54
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:266
Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
Definition: hashpage.c:70
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
int j
Definition: isn.c:73
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define AccessShareLock
Definition: lockdefs.h:36
char * pstrdup(const char *in)
Definition: mcxt.c:1696
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3554
#define BTPageGetMeta(p)
Definition: nbtree.h:121
#define P_ISLEAF(opaque)
Definition: nbtree.h:220
#define BTPageGetOpaque(page)
Definition: nbtree.h:73
#define P_ISDELETED(opaque)
Definition: nbtree.h:222
#define P_NONE
Definition: nbtree.h:212
#define P_IGNORE(opaque)
Definition: nbtree.h:225
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
NameData relname
Definition: pg_class.h:38
static char * buf
Definition: pg_test_fsync.c:72
Datum pgstatindexbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:185
Datum pgstatindexbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:202
Datum pgstatindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:167
#define IS_BTREE(r)
Definition: pgstatindex.c:68
#define IS_HASH(r)
Definition: pgstatindex.c:70
static void GetHashPageStats(Page page, HashIndexStat *stats)
Definition: pgstatindex.c:742
static int64 pg_relpages_impl(Relation rel)
Definition: pgstatindex.c:453
Datum pgstatginindex_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:496
Datum pg_relpagesbyid(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:425
Datum pg_relpages(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:392
Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:504
Datum pg_relpages_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:411
struct HashIndexStat HashIndexStat
#define IS_INDEX(r)
Definition: pgstatindex.c:67
static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstatindex.c:213
Datum pg_relpagesbyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:442
PG_FUNCTION_INFO_V1(pgstatindex)
Datum pgstatginindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:482
#define IS_GIN(r)
Definition: pgstatindex.c:69
struct GinIndexStat GinIndexStat
Datum pgstathashindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:583
struct BTIndexStat BTIndexStat
Datum pgstatindex(PG_FUNCTION_ARGS)
Definition: pgstatindex.c:142
uintptr_t Datum
Definition: postgres.h:64
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:232
unsigned int Oid
Definition: postgres_ext.h:31
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
#define RelationGetRelationName(relation)
Definition: rel.h:539
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:658
@ MAIN_FORKNUM
Definition: relpath.h:58
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:137
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
uint64 max_avail
Definition: pgstatindex.c:88
uint32 level
Definition: pgstatindex.c:80
uint64 empty_pages
Definition: pgstatindex.c:85
uint64 deleted_pages
Definition: pgstatindex.c:86
uint64 internal_pages
Definition: pgstatindex.c:83
uint64 leaf_pages
Definition: pgstatindex.c:84
uint32 version
Definition: pgstatindex.c:79
uint64 fragments
Definition: pgstatindex.c:91
BlockNumber root_blkno
Definition: pgstatindex.c:81
uint64 free_space
Definition: pgstatindex.c:89
uint32 btm_level
Definition: nbtree.h:108
uint32 btm_version
Definition: nbtree.h:106
BlockNumber btm_root
Definition: nbtree.h:107
BlockNumber btpo_next
Definition: nbtree.h:65
BlockNumber pending_pages
Definition: pgstatindex.c:103
int64 pending_tuples
Definition: pgstatindex.c:104
int32 ginVersion
Definition: ginblock.h:99
BlockNumber nPendingPages
Definition: ginblock.h:73
int64 nPendingHeapTuples
Definition: ginblock.h:74
BlockNumber bitmap_pages
Definition: pgstatindex.c:119
BlockNumber overflow_pages
Definition: pgstatindex.c:118
BlockNumber bucket_pages
Definition: pgstatindex.c:117
BlockNumber unused_pages
Definition: pgstatindex.c:120
uint64 free_space
Definition: pgstatindex.c:124
int64 dead_items
Definition: pgstatindex.c:123
int32 space_per_page
Definition: pgstatindex.c:115
int64 live_items
Definition: pgstatindex.c:122
uint32 hashm_version
Definition: hash.h:247
uint16 hashm_bsize
Definition: hash.h:250
uint16 hasho_flag
Definition: hash.h:82
Form_pg_index rd_index
Definition: rel.h:192
Form_pg_class rd_rel
Definition: rel.h:111
Definition: c.h:641
bool superuser(void)
Definition: superuser.c:46
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3374