PostgreSQL Source Code git master
Loading...
Searching...
No Matches
gin.h File Reference
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
#include "storage/block.h"
#include "storage/dsm.h"
#include "storage/shm_toc.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 PROGRESS_GIN_PHASE_INDEXBUILD_TABLESCAN   2
 
#define PROGRESS_GIN_PHASE_PERFORMSORT_1   3
 
#define PROGRESS_GIN_PHASE_MERGE_1   4
 
#define PROGRESS_GIN_PHASE_PERFORMSORT_2   5
 
#define PROGRESS_GIN_PHASE_MERGE_2   6
 
#define GIN_FALSE   0 /* item is not present / does not match */
 
#define GIN_TRUE   1 /* item is present / matches */
 
#define GIN_MAYBE
 
#define PG_RETURN_GIN_TERNARY_VALUE(x)   return GinTernaryValueGetDatum(x)
 

Typedefs

typedef struct GinStatsData GinStatsData
 
typedef char GinTernaryValue
 

Functions

 StaticAssertDecl (sizeof(GinTernaryValue)==sizeof(bool), "sizes of GinTernaryValue and bool are not equal")
 
static GinTernaryValue DatumGetGinTernaryValue (Datum X)
 
static Datum GinTernaryValueGetDatum (GinTernaryValue X)
 
void ginGetStats (Relation index, GinStatsData *stats)
 
void ginUpdateStats (Relation index, const GinStatsData *stats, bool is_build)
 
void _gin_parallel_build_main (dsm_segment *seg, shm_toc *toc)
 

Variables

PGDLLIMPORT int GinFuzzySearchLimit
 
PGDLLIMPORT int gin_pending_list_limit
 

Macro Definition Documentation

◆ GIN_COMPARE_PARTIAL_PROC

#define GIN_COMPARE_PARTIAL_PROC   5

Definition at line 28 of file gin.h.

◆ GIN_COMPARE_PROC

#define GIN_COMPARE_PROC   1

Definition at line 24 of file gin.h.

◆ GIN_CONSISTENT_PROC

#define GIN_CONSISTENT_PROC   4

Definition at line 27 of file gin.h.

◆ GIN_EXTRACTQUERY_PROC

#define GIN_EXTRACTQUERY_PROC   3

Definition at line 26 of file gin.h.

◆ GIN_EXTRACTVALUE_PROC

#define GIN_EXTRACTVALUE_PROC   2

Definition at line 25 of file gin.h.

◆ GIN_FALSE

#define GIN_FALSE   0 /* item is not present / does not match */

Definition at line 76 of file gin.h.

◆ GIN_MAYBE

#define GIN_MAYBE
Value:
2 /* don't know if item is present / don't know
* if matches */

Definition at line 78 of file gin.h.

83{
84 return (GinTernaryValue) X;
85}
86
87static inline Datum
89{
90 return (Datum) X;
91}
92
93#define PG_RETURN_GIN_TERNARY_VALUE(x) return GinTernaryValueGetDatum(x)
94
95/* GUC parameters */
98
99/* ginutil.c */
100extern void ginGetStats(Relation index, GinStatsData *stats);
101extern void ginUpdateStats(Relation index, const GinStatsData *stats,
102 bool is_build);
103
104extern void _gin_parallel_build_main(dsm_segment *seg, shm_toc *toc);
105
106#endif /* GIN_H */
#define PGDLLIMPORT
Definition c.h:1334
void ginGetStats(Relation index, GinStatsData *stats)
Definition ginutil.c:591
static Datum GinTernaryValueGetDatum(GinTernaryValue X)
Definition gin.h:87
char GinTernaryValue
Definition gin.h:71
PGDLLIMPORT int gin_pending_list_limit
Definition ginfast.c:39
void _gin_parallel_build_main(dsm_segment *seg, shm_toc *toc)
Definition gininsert.c:2101
PGDLLIMPORT int GinFuzzySearchLimit
Definition ginget.c:27
void ginUpdateStats(Relation index, const GinStatsData *stats, bool is_build)
Definition ginutil.c:618
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
Definition type.h:96

◆ GIN_OPTIONS_PROC

#define GIN_OPTIONS_PROC   7

Definition at line 30 of file gin.h.

◆ GIN_SEARCH_MODE_ALL

#define GIN_SEARCH_MODE_ALL   2

Definition at line 38 of file gin.h.

◆ GIN_SEARCH_MODE_DEFAULT

#define GIN_SEARCH_MODE_DEFAULT   0

Definition at line 36 of file gin.h.

◆ GIN_SEARCH_MODE_EVERYTHING

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

Definition at line 39 of file gin.h.

◆ GIN_SEARCH_MODE_INCLUDE_EMPTY

#define GIN_SEARCH_MODE_INCLUDE_EMPTY   1

Definition at line 37 of file gin.h.

◆ GIN_TRICONSISTENT_PROC

#define GIN_TRICONSISTENT_PROC   6

Definition at line 29 of file gin.h.

◆ GIN_TRUE

#define GIN_TRUE   1 /* item is present / matches */

Definition at line 77 of file gin.h.

◆ GINNProcs

#define GINNProcs   7

Definition at line 31 of file gin.h.

◆ PG_RETURN_GIN_TERNARY_VALUE

#define PG_RETURN_GIN_TERNARY_VALUE (   x)    return GinTernaryValueGetDatum(x)

Definition at line 92 of file gin.h.

◆ PROGRESS_GIN_PHASE_INDEXBUILD_TABLESCAN

#define PROGRESS_GIN_PHASE_INDEXBUILD_TABLESCAN   2

Definition at line 46 of file gin.h.

◆ PROGRESS_GIN_PHASE_MERGE_1

#define PROGRESS_GIN_PHASE_MERGE_1   4

Definition at line 48 of file gin.h.

◆ PROGRESS_GIN_PHASE_MERGE_2

#define PROGRESS_GIN_PHASE_MERGE_2   6

Definition at line 50 of file gin.h.

◆ PROGRESS_GIN_PHASE_PERFORMSORT_1

#define PROGRESS_GIN_PHASE_PERFORMSORT_1   3

Definition at line 47 of file gin.h.

◆ PROGRESS_GIN_PHASE_PERFORMSORT_2

#define PROGRESS_GIN_PHASE_PERFORMSORT_2   5

Definition at line 49 of file gin.h.

Typedef Documentation

◆ GinStatsData

◆ GinTernaryValue

Definition at line 71 of file gin.h.

Function Documentation

◆ _gin_parallel_build_main()

void _gin_parallel_build_main ( dsm_segment seg,
shm_toc toc 
)
extern

Definition at line 2101 of file gininsert.c.

2102{
2103 char *sharedquery;
2104 GinBuildShared *ginshared;
2105 Sharedsort *sharedsort;
2107 Relation heapRel;
2108 Relation indexRel;
2111 WalUsage *walusage;
2112 BufferUsage *bufferusage;
2113 int sortmem;
2114
2115 /*
2116 * The only possible status flag that can be set to the parallel worker is
2117 * PROC_IN_SAFE_IC.
2118 */
2119 Assert((MyProc->statusFlags == 0) ||
2121
2122 /* Set debug_query_string for individual workers first */
2125
2126 /* Report the query string from leader */
2128
2129 /* Look up gin shared state */
2130 ginshared = shm_toc_lookup(toc, PARALLEL_KEY_GIN_SHARED, false);
2131
2132 /* Open relations using lock modes known to be obtained by index.c */
2133 if (!ginshared->isconcurrent)
2134 {
2137 }
2138 else
2139 {
2142 }
2143
2144 /* Open relations within worker */
2145 heapRel = table_open(ginshared->heaprelid, heapLockmode);
2146 indexRel = index_open(ginshared->indexrelid, indexLockmode);
2147
2148 /* initialize the GIN build state */
2149 initGinState(&buildstate.ginstate, indexRel);
2150 buildstate.indtuples = 0;
2151 memset(&buildstate.buildStats, 0, sizeof(GinStatsData));
2152 memset(&buildstate.tid, 0, sizeof(ItemPointerData));
2153
2154 /*
2155 * create a temporary memory context that is used to hold data not yet
2156 * dumped out to the index
2157 */
2159 "Gin build temporary context",
2161
2162 /*
2163 * create a temporary memory context that is used for calling
2164 * ginExtractEntries(), and can be reset after each tuple
2165 */
2167 "Gin build temporary context for user-defined function",
2169
2170 buildstate.accum.ginstate = &buildstate.ginstate;
2171 ginInitBA(&buildstate.accum);
2172
2173
2174 /* Look up shared state private to tuplesort.c */
2175 sharedsort = shm_toc_lookup(toc, PARALLEL_KEY_TUPLESORT, false);
2176 tuplesort_attach_shared(sharedsort, seg);
2177
2178 /* Prepare to track buffer usage during parallel execution */
2180
2181 /*
2182 * Might as well use reliable figure when doling out maintenance_work_mem
2183 * (when requested number of workers were not launched, this will be
2184 * somewhat higher than it is for other workers).
2185 */
2187
2188 _gin_parallel_scan_and_build(&buildstate, ginshared, sharedsort,
2189 heapRel, indexRel, sortmem, false);
2190
2191 /* Report WAL/buffer usage during parallel execution */
2192 bufferusage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
2193 walusage = shm_toc_lookup(toc, PARALLEL_KEY_WAL_USAGE, false);
2195 &walusage[ParallelWorkerNumber]);
2196
2197 index_close(indexRel, indexLockmode);
2198 table_close(heapRel, heapLockmode);
2199}
int ParallelWorkerNumber
Definition parallel.c:115
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
#define Assert(condition)
Definition c.h:873
void ginInitBA(BuildAccumulator *accum)
Definition ginbulk.c:109
#define PARALLEL_KEY_BUFFER_USAGE
Definition gininsert.c:44
#define PARALLEL_KEY_GIN_SHARED
Definition gininsert.c:40
static void _gin_parallel_scan_and_build(GinBuildState *state, GinBuildShared *ginshared, Sharedsort *sharedsort, Relation heap, Relation index, int sortmem, bool progress)
Definition gininsert.c:2023
#define PARALLEL_KEY_TUPLESORT
Definition gininsert.c:41
#define PARALLEL_KEY_QUERY_TEXT
Definition gininsert.c:42
#define PARALLEL_KEY_WAL_USAGE
Definition gininsert.c:43
void initGinState(GinState *state, Relation index)
Definition ginutil.c:103
int maintenance_work_mem
Definition globals.c:133
void index_close(Relation relation, LOCKMODE lockmode)
Definition indexam.c:177
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:133
void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition instrument.c:205
void InstrStartParallelQuery(void)
Definition instrument.c:197
int LOCKMODE
Definition lockdefs.h:26
#define AccessExclusiveLock
Definition lockdefs.h:43
#define ShareUpdateExclusiveLock
Definition lockdefs.h:39
#define ShareLock
Definition lockdefs.h:40
#define RowExclusiveLock
Definition lockdefs.h:38
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
const char * debug_query_string
Definition postgres.c:89
#define PROC_IN_SAFE_IC
Definition proc.h:59
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition shm_toc.c:232
PGPROC * MyProc
Definition proc.c:67
int scantuplesortstates
Definition gininsert.c:60
bool isconcurrent
Definition gininsert.c:59
uint8 statusFlags
Definition proc.h:265
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40
void tuplesort_attach_shared(Sharedsort *shared, dsm_segment *seg)
Definition tuplesort.c:2944

References _gin_parallel_scan_and_build(), AccessExclusiveLock, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, CurrentMemoryContext, debug_query_string, fb(), ginInitBA(), GinBuildShared::heaprelid, index_close(), index_open(), GinBuildShared::indexrelid, initGinState(), InstrEndParallelQuery(), InstrStartParallelQuery(), GinBuildShared::isconcurrent, maintenance_work_mem, MyProc, PARALLEL_KEY_BUFFER_USAGE, PARALLEL_KEY_GIN_SHARED, PARALLEL_KEY_QUERY_TEXT, PARALLEL_KEY_TUPLESORT, PARALLEL_KEY_WAL_USAGE, ParallelWorkerNumber, pgstat_report_activity(), PROC_IN_SAFE_IC, RowExclusiveLock, GinBuildShared::scantuplesortstates, ShareLock, ShareUpdateExclusiveLock, shm_toc_lookup(), STATE_RUNNING, PGPROC::statusFlags, table_close(), table_open(), and tuplesort_attach_shared().

◆ DatumGetGinTernaryValue()

static GinTernaryValue DatumGetGinTernaryValue ( Datum  X)
inlinestatic

Definition at line 81 of file gin.h.

83{
84 return (GinTernaryValue) X;

References fb().

Referenced by directTriConsistentFn(), and shimBoolConsistentFn().

◆ ginGetStats()

void ginGetStats ( Relation  index,
GinStatsData stats 
)
extern

Definition at line 591 of file ginutil.c.

592{
595 GinMetaPageData *metadata;
596
600 metadata = GinPageGetMeta(metapage);
601
602 stats->nPendingPages = metadata->nPendingPages;
603 stats->nTotalPages = metadata->nTotalPages;
604 stats->nEntryPages = metadata->nEntryPages;
605 stats->nDataPages = metadata->nDataPages;
606 stats->nEntries = metadata->nEntries;
607 stats->ginVersion = metadata->ginVersion;
608
610}
int Buffer
Definition buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5518
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition bufmgr.c:864
static Page BufferGetPage(Buffer buffer)
Definition bufmgr.h:466
static void LockBuffer(Buffer buffer, BufferLockMode mode)
Definition bufmgr.h:328
PageData * Page
Definition bufpage.h:81
#define GIN_SHARE
Definition gin_private.h:51
#define GIN_METAPAGE_BLKNO
Definition ginblock.h:51
#define GinPageGetMeta(p)
Definition ginblock.h:104
int32 ginVersion
Definition ginblock.h:99
BlockNumber nEntryPages
Definition ginblock.h:80
BlockNumber nPendingPages
Definition ginblock.h:73
BlockNumber nTotalPages
Definition ginblock.h:79
BlockNumber nDataPages
Definition ginblock.h:81
BlockNumber nDataPages
Definition gin.h:60
BlockNumber nPendingPages
Definition gin.h:57
BlockNumber nEntryPages
Definition gin.h:59
int64 nEntries
Definition gin.h:61
BlockNumber nTotalPages
Definition gin.h:58
int32 ginVersion
Definition gin.h:62

References BufferGetPage(), fb(), 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(), and ginNewScanKey().

◆ GinTernaryValueGetDatum()

static Datum GinTernaryValueGetDatum ( GinTernaryValue  X)
inlinestatic

Definition at line 87 of file gin.h.

89{
90 return (Datum) X;

References fb().

◆ ginUpdateStats()

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

Definition at line 618 of file ginutil.c.

619{
622 GinMetaPageData *metadata;
623
627 metadata = GinPageGetMeta(metapage);
628
630
631 metadata->nTotalPages = stats->nTotalPages;
632 metadata->nEntryPages = stats->nEntryPages;
633 metadata->nDataPages = stats->nDataPages;
634 metadata->nEntries = stats->nEntries;
635
636 /*
637 * Set pd_lower just past the end of the metadata. This is essential,
638 * because without doing so, metadata will be lost if xlog.c compresses
639 * the page. (We must do this here because pre-v11 versions of PG did not
640 * set the metapage's pd_lower correctly, so a pg_upgraded index might
641 * contain the wrong value.)
642 */
643 ((PageHeader) metapage)->pd_lower =
644 ((char *) metadata + sizeof(GinMetaPageData)) - (char *) metapage;
645
647
648 if (RelationNeedsWAL(index) && !is_build)
649 {
652
653 data.locator = index->rd_locator;
654 data.ntuples = 0;
655 data.newRightlink = data.prevTail = InvalidBlockNumber;
656 memcpy(&data.metadata, metadata, sizeof(GinMetaPageData));
657
661
664 }
665
667
669}
#define InvalidBlockNumber
Definition block.h:33
void MarkBufferDirty(Buffer buffer)
Definition bufmgr.c:3056
PageHeaderData * PageHeader
Definition bufpage.h:173
static void PageSetLSN(Page page, XLogRecPtr lsn)
Definition bufpage.h:390
#define GIN_EXCLUSIVE
Definition gin_private.h:52
#define XLOG_GIN_UPDATE_META_PAGE
Definition ginxlog.h:162
#define START_CRIT_SECTION()
Definition miscadmin.h:150
#define END_CRIT_SECTION()
Definition miscadmin.h:152
const void * data
#define RelationNeedsWAL(relation)
Definition rel.h:637
RelFileLocator locator
Definition ginxlog.h:170
uint64 XLogRecPtr
Definition xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition xloginsert.c:478
void XLogRegisterData(const void *data, uint32 len)
Definition xloginsert.c:368
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition xloginsert.c:245
void XLogBeginInsert(void)
Definition xloginsert.c:152
#define REGBUF_STANDARD
Definition xloginsert.h:35
#define REGBUF_WILL_INIT
Definition xloginsert.h:34

References BufferGetPage(), data, END_CRIT_SECTION, fb(), GIN_EXCLUSIVE, GIN_METAPAGE_BLKNO, GinPageGetMeta, InvalidBlockNumber, ginxlogUpdateMeta::locator, LockBuffer(), MarkBufferDirty(), GinStatsData::nDataPages, GinMetaPageData::nDataPages, GinStatsData::nEntries, GinMetaPageData::nEntries, GinStatsData::nEntryPages, GinMetaPageData::nEntryPages, GinStatsData::nTotalPages, GinMetaPageData::nTotalPages, PageSetLSN(), 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().

◆ StaticAssertDecl()

StaticAssertDecl ( sizeof(GinTernaryValue = =sizeof(bool),
"sizes of GinTernaryValue and bool are not equal"   
)

Variable Documentation

◆ gin_pending_list_limit

PGDLLIMPORT int gin_pending_list_limit
extern

Definition at line 39 of file ginfast.c.

◆ GinFuzzySearchLimit

PGDLLIMPORT int GinFuzzySearchLimit
extern

Definition at line 27 of file ginget.c.

Referenced by startScan().