PostgreSQL Source Code  git master
gin.h File Reference
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
#include "storage/block.h"
#include "utils/relcache.h"
Include dependency graph for gin.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GinStatsData
 

Macros

#define GIN_COMPARE_PROC   1
 
#define GIN_EXTRACTVALUE_PROC   2
 
#define GIN_EXTRACTQUERY_PROC   3
 
#define GIN_CONSISTENT_PROC   4
 
#define GIN_COMPARE_PARTIAL_PROC   5
 
#define GIN_TRICONSISTENT_PROC   6
 
#define GIN_OPTIONS_PROC   7
 
#define GINNProcs   7
 
#define GIN_SEARCH_MODE_DEFAULT   0
 
#define GIN_SEARCH_MODE_INCLUDE_EMPTY   1
 
#define GIN_SEARCH_MODE_ALL   2
 
#define GIN_SEARCH_MODE_EVERYTHING   3 /* for internal use only */
 
#define GIN_FALSE   0 /* item is not present / does not match */
 
#define GIN_TRUE   1 /* item is present / matches */
 
#define GIN_MAYBE
 
#define DatumGetGinTernaryValue(X)   ((GinTernaryValue)(X))
 
#define GinTernaryValueGetDatum(X)   ((Datum)(X))
 
#define PG_RETURN_GIN_TERNARY_VALUE(x)   return GinTernaryValueGetDatum(x)
 

Typedefs

typedef struct GinStatsData GinStatsData
 
typedef char GinTernaryValue
 

Functions

void ginGetStats (Relation index, GinStatsData *stats)
 
void ginUpdateStats (Relation index, const GinStatsData *stats, bool is_build)
 

Variables

PGDLLIMPORT int GinFuzzySearchLimit
 
int gin_pending_list_limit
 

Macro Definition Documentation

◆ DatumGetGinTernaryValue

#define DatumGetGinTernaryValue (   X)    ((GinTernaryValue)(X))

Definition at line 65 of file gin.h.

Referenced by directTriConsistentFn(), and shimBoolConsistentFn().

◆ GIN_COMPARE_PARTIAL_PROC

#define GIN_COMPARE_PARTIAL_PROC   5

Definition at line 26 of file gin.h.

Referenced by ginvalidate(), and initGinState().

◆ GIN_COMPARE_PROC

#define GIN_COMPARE_PROC   1

Definition at line 22 of file gin.h.

Referenced by ginvalidate(), and initGinState().

◆ GIN_CONSISTENT_PROC

#define GIN_CONSISTENT_PROC   4

Definition at line 25 of file gin.h.

Referenced by ginvalidate(), and initGinState().

◆ GIN_EXTRACTQUERY_PROC

#define GIN_EXTRACTQUERY_PROC   3

Definition at line 24 of file gin.h.

Referenced by gincost_pattern(), ginvalidate(), and initGinState().

◆ GIN_EXTRACTVALUE_PROC

#define GIN_EXTRACTVALUE_PROC   2

Definition at line 23 of file gin.h.

Referenced by ginvalidate(), and initGinState().

◆ GIN_FALSE

◆ GIN_MAYBE

◆ GIN_OPTIONS_PROC

#define GIN_OPTIONS_PROC   7

Definition at line 28 of file gin.h.

Referenced by ginhandler(), and ginvalidate().

◆ GIN_SEARCH_MODE_ALL

◆ GIN_SEARCH_MODE_DEFAULT

#define GIN_SEARCH_MODE_DEFAULT   0

◆ GIN_SEARCH_MODE_EVERYTHING

#define GIN_SEARCH_MODE_EVERYTHING   3 /* for internal use only */

Definition at line 37 of file gin.h.

Referenced by ginFillScanKey(), and ginInitConsistentFunction().

◆ GIN_SEARCH_MODE_INCLUDE_EMPTY

#define GIN_SEARCH_MODE_INCLUDE_EMPTY   1

Definition at line 35 of file gin.h.

Referenced by gincost_pattern(), ginFillScanKey(), ginint4_queryextract(), and ginqueryarrayextract().

◆ GIN_TRICONSISTENT_PROC

#define GIN_TRICONSISTENT_PROC   6

Definition at line 27 of file gin.h.

Referenced by ginvalidate(), and initGinState().

◆ GIN_TRUE

◆ GINNProcs

#define GINNProcs   7

Definition at line 29 of file gin.h.

Referenced by ginhandler(), and ginvalidate().

◆ GinTernaryValueGetDatum

#define GinTernaryValueGetDatum (   X)    ((Datum)(X))

Definition at line 66 of file gin.h.

◆ PG_RETURN_GIN_TERNARY_VALUE

#define PG_RETURN_GIN_TERNARY_VALUE (   x)    return GinTernaryValueGetDatum(x)

Typedef Documentation

◆ GinStatsData

typedef struct GinStatsData GinStatsData

◆ GinTernaryValue

typedef char GinTernaryValue

Definition at line 58 of file gin.h.

Function Documentation

◆ ginGetStats()

void ginGetStats ( Relation  index,
GinStatsData stats 
)

Definition at line 629 of file ginutil.c.

References BufferGetPage, GIN_METAPAGE_BLKNO, GIN_SHARE, GinPageGetMeta, GinStatsData::ginVersion, GinMetaPageData::ginVersion, LockBuffer(), GinStatsData::nDataPages, GinMetaPageData::nDataPages, GinStatsData::nEntries, GinMetaPageData::nEntries, GinStatsData::nEntryPages, GinMetaPageData::nEntryPages, GinStatsData::nPendingPages, GinMetaPageData::nPendingPages, GinStatsData::nTotalPages, GinMetaPageData::nTotalPages, ReadBuffer(), and UnlockReleaseBuffer().

Referenced by gincostestimate().

630 {
631  Buffer metabuffer;
632  Page metapage;
633  GinMetaPageData *metadata;
634 
635  metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
636  LockBuffer(metabuffer, GIN_SHARE);
637  metapage = BufferGetPage(metabuffer);
638  metadata = GinPageGetMeta(metapage);
639 
640  stats->nPendingPages = metadata->nPendingPages;
641  stats->nTotalPages = metadata->nTotalPages;
642  stats->nEntryPages = metadata->nEntryPages;
643  stats->nDataPages = metadata->nDataPages;
644  stats->nEntries = metadata->nEntries;
645  stats->ginVersion = metadata->ginVersion;
646 
647  UnlockReleaseBuffer(metabuffer);
648 }
BlockNumber nEntryPages
Definition: ginblock.h:80
BlockNumber nEntryPages
Definition: gin.h:46
int64 nEntries
Definition: gin.h:48
BlockNumber nTotalPages
Definition: ginblock.h:79
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:51
int64 nEntries
Definition: ginblock.h:82
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3506
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define GIN_SHARE
Definition: gin_private.h:49
BlockNumber nPendingPages
Definition: gin.h:44
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3722
BlockNumber nDataPages
Definition: gin.h:47
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:606
BlockNumber nTotalPages
Definition: gin.h:45
int32 ginVersion
Definition: ginblock.h:99
int32 ginVersion
Definition: gin.h:49
BlockNumber nDataPages
Definition: ginblock.h:81
#define GinPageGetMeta(p)
Definition: ginblock.h:104
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78
BlockNumber nPendingPages
Definition: ginblock.h:73

◆ ginUpdateStats()

void ginUpdateStats ( Relation  index,
const GinStatsData stats,
bool  is_build 
)

Definition at line 656 of file ginutil.c.

References BufferGetPage, END_CRIT_SECTION, GIN_EXCLUSIVE, GIN_METAPAGE_BLKNO, GinPageGetMeta, InvalidBlockNumber, LockBuffer(), MarkBufferDirty(), ginxlogUpdateMeta::metadata, GinStatsData::nDataPages, GinMetaPageData::nDataPages, GinStatsData::nEntries, GinMetaPageData::nEntries, GinStatsData::nEntryPages, GinMetaPageData::nEntryPages, ginxlogUpdateMeta::newRightlink, ginxlogUpdateMeta::node, GinStatsData::nTotalPages, GinMetaPageData::nTotalPages, ginxlogUpdateMeta::ntuples, PageSetLSN, ginxlogUpdateMeta::prevTail, RelationData::rd_node, ReadBuffer(), REGBUF_STANDARD, REGBUF_WILL_INIT, RelationNeedsWAL, START_CRIT_SECTION, UnlockReleaseBuffer(), XLOG_GIN_UPDATE_META_PAGE, XLogBeginInsert(), XLogInsert(), XLogRegisterBuffer(), and XLogRegisterData().

Referenced by ginbuild(), and ginvacuumcleanup().

657 {
658  Buffer metabuffer;
659  Page metapage;
660  GinMetaPageData *metadata;
661 
662  metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
663  LockBuffer(metabuffer, GIN_EXCLUSIVE);
664  metapage = BufferGetPage(metabuffer);
665  metadata = GinPageGetMeta(metapage);
666 
668 
669  metadata->nTotalPages = stats->nTotalPages;
670  metadata->nEntryPages = stats->nEntryPages;
671  metadata->nDataPages = stats->nDataPages;
672  metadata->nEntries = stats->nEntries;
673 
674  /*
675  * Set pd_lower just past the end of the metadata. This is essential,
676  * because without doing so, metadata will be lost if xlog.c compresses
677  * the page. (We must do this here because pre-v11 versions of PG did not
678  * set the metapage's pd_lower correctly, so a pg_upgraded index might
679  * contain the wrong value.)
680  */
681  ((PageHeader) metapage)->pd_lower =
682  ((char *) metadata + sizeof(GinMetaPageData)) - (char *) metapage;
683 
684  MarkBufferDirty(metabuffer);
685 
686  if (RelationNeedsWAL(index) && !is_build)
687  {
688  XLogRecPtr recptr;
689  ginxlogUpdateMeta data;
690 
691  data.node = index->rd_node;
692  data.ntuples = 0;
694  memcpy(&data.metadata, metadata, sizeof(GinMetaPageData));
695 
696  XLogBeginInsert();
697  XLogRegisterData((char *) &data, sizeof(ginxlogUpdateMeta));
699 
700  recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_UPDATE_META_PAGE);
701  PageSetLSN(metapage, recptr);
702  }
703 
704  UnlockReleaseBuffer(metabuffer);
705 
707 }
BlockNumber nEntryPages
Definition: ginblock.h:80
BlockNumber prevTail
Definition: ginxlog.h:172
BlockNumber nEntryPages
Definition: gin.h:46
RelFileNode node
Definition: ginxlog.h:170
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1468
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:214
#define END_CRIT_SECTION()
Definition: miscadmin.h:134
#define REGBUF_WILL_INIT
Definition: xloginsert.h:33
#define START_CRIT_SECTION()
Definition: miscadmin.h:132
int64 nEntries
Definition: gin.h:48
BlockNumber nTotalPages
Definition: ginblock.h:79
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:51
int64 nEntries
Definition: ginblock.h:82
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3506
#define XLOG_GIN_UPDATE_META_PAGE
Definition: ginxlog.h:162
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
BlockNumber newRightlink
Definition: ginxlog.h:173
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:324
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:416
#define GIN_EXCLUSIVE
Definition: gin_private.h:50
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3722
BlockNumber nDataPages
Definition: gin.h:47
GinMetaPageData metadata
Definition: ginxlog.h:171
RelFileNode rd_node
Definition: rel.h:55
PageHeaderData * PageHeader
Definition: bufpage.h:166
uint64 XLogRecPtr
Definition: xlogdefs.h:21
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:606
#define InvalidBlockNumber
Definition: block.h:33
BlockNumber nTotalPages
Definition: gin.h:45
#define RelationNeedsWAL(relation)
Definition: rel.h:562
BlockNumber nDataPages
Definition: ginblock.h:81
#define GinPageGetMeta(p)
Definition: ginblock.h:104
void XLogBeginInsert(void)
Definition: xloginsert.c:121
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78

Variable Documentation

◆ gin_pending_list_limit

int gin_pending_list_limit

Definition at line 39 of file ginfast.c.

◆ GinFuzzySearchLimit

PGDLLIMPORT int GinFuzzySearchLimit

Definition at line 26 of file ginget.c.

Referenced by startScan().