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:1421
void ginGetStats(Relation index, GinStatsData *stats)
Definition ginutil.c:578
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:2111
PGDLLIMPORT int GinFuzzySearchLimit
Definition ginget.c:27
void ginUpdateStats(Relation index, const GinStatsData *stats, bool is_build)
Definition ginutil.c:605
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 2111 of file gininsert.c.

2112{
2113 char *sharedquery;
2114 GinBuildShared *ginshared;
2115 Sharedsort *sharedsort;
2117 Relation heapRel;
2118 Relation indexRel;
2121 WalUsage *walusage;
2122 BufferUsage *bufferusage;
2123 int sortmem;
2124
2125 /*
2126 * The only possible status flag that can be set to the parallel worker is
2127 * PROC_IN_SAFE_IC.
2128 */
2129 Assert((MyProc->statusFlags == 0) ||
2131
2132 /* Set debug_query_string for individual workers first */
2135
2136 /* Report the query string from leader */
2138
2139 /* Look up gin shared state */
2140 ginshared = shm_toc_lookup(toc, PARALLEL_KEY_GIN_SHARED, false);
2141
2142 /* Open relations using lock modes known to be obtained by index.c */
2143 if (!ginshared->isconcurrent)
2144 {
2147 }
2148 else
2149 {
2152 }
2153
2154 /* Open relations within worker */
2155 heapRel = table_open(ginshared->heaprelid, heapLockmode);
2156 indexRel = index_open(ginshared->indexrelid, indexLockmode);
2157
2158 /* initialize the GIN build state */
2159 initGinState(&buildstate.ginstate, indexRel);
2160 buildstate.indtuples = 0;
2161 memset(&buildstate.buildStats, 0, sizeof(GinStatsData));
2162 memset(&buildstate.tid, 0, sizeof(ItemPointerData));
2163
2164 /*
2165 * create a temporary memory context that is used to hold data not yet
2166 * dumped out to the index
2167 */
2169 "Gin build temporary context",
2171
2172 /*
2173 * create a temporary memory context that is used for calling
2174 * ginExtractEntries(), and can be reset after each tuple
2175 */
2177 "Gin build temporary context for user-defined function",
2179
2180 buildstate.accum.ginstate = &buildstate.ginstate;
2181 ginInitBA(&buildstate.accum);
2182
2183
2184 /* Look up shared state private to tuplesort.c */
2185 sharedsort = shm_toc_lookup(toc, PARALLEL_KEY_TUPLESORT, false);
2186 tuplesort_attach_shared(sharedsort, seg);
2187
2188 /* Prepare to track buffer usage during parallel execution */
2190
2191 /*
2192 * Might as well use reliable figure when doling out maintenance_work_mem
2193 * (when requested number of workers were not launched, this will be
2194 * somewhat higher than it is for other workers).
2195 */
2197
2198 _gin_parallel_scan_and_build(&buildstate, ginshared, sharedsort,
2199 heapRel, indexRel, sortmem, false);
2200
2201 /* Report WAL/buffer usage during parallel execution */
2202 bufferusage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
2203 walusage = shm_toc_lookup(toc, PARALLEL_KEY_WAL_USAGE, false);
2205 &walusage[ParallelWorkerNumber]);
2206
2207 index_close(indexRel, indexLockmode);
2208 table_close(heapRel, heapLockmode);
2209}
int ParallelWorkerNumber
Definition parallel.c:117
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
#define Assert(condition)
Definition c.h:943
void ginInitBA(BuildAccumulator *accum)
Definition ginbulk.c:109
#define PARALLEL_KEY_BUFFER_USAGE
Definition gininsert.c:49
#define PARALLEL_KEY_GIN_SHARED
Definition gininsert.c:45
static void _gin_parallel_scan_and_build(GinBuildState *state, GinBuildShared *ginshared, Sharedsort *sharedsort, Relation heap, Relation index, int sortmem, bool progress)
Definition gininsert.c:2032
#define PARALLEL_KEY_TUPLESORT
Definition gininsert.c:46
#define PARALLEL_KEY_QUERY_TEXT
Definition gininsert.c:47
#define PARALLEL_KEY_WAL_USAGE
Definition gininsert.c:48
void initGinState(GinState *state, Relation index)
Definition ginutil.c:104
int maintenance_work_mem
Definition globals.c:135
void index_close(Relation relation, LOCKMODE lockmode)
Definition indexam.c:178
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:134
void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition instrument.c:287
void InstrStartParallelQuery(void)
Definition instrument.c:279
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:94
#define PROC_IN_SAFE_IC
Definition proc.h:63
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition shm_toc.c:239
PGPROC * MyProc
Definition proc.c:71
int scantuplesortstates
Definition gininsert.c:65
bool isconcurrent
Definition gininsert.c:64
uint8 statusFlags
Definition proc.h:210
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:3269

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 578 of file ginutil.c.

579{
582 GinMetaPageData *metadata;
583
587 metadata = GinPageGetMeta(metapage);
588
589 stats->nPendingPages = metadata->nPendingPages;
590 stats->nTotalPages = metadata->nTotalPages;
591 stats->nEntryPages = metadata->nEntryPages;
592 stats->nDataPages = metadata->nDataPages;
593 stats->nEntries = metadata->nEntries;
594 stats->ginVersion = metadata->ginVersion;
595
597}
int Buffer
Definition buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5603
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition bufmgr.c:879
static Page BufferGetPage(Buffer buffer)
Definition bufmgr.h:468
static void LockBuffer(Buffer buffer, BufferLockMode mode)
Definition bufmgr.h:334
PageData * Page
Definition bufpage.h:81
#define GIN_SHARE
Definition gin_private.h:52
#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 605 of file ginutil.c.

606{
609 GinMetaPageData *metadata;
610
614 metadata = GinPageGetMeta(metapage);
615
617
618 metadata->nTotalPages = stats->nTotalPages;
619 metadata->nEntryPages = stats->nEntryPages;
620 metadata->nDataPages = stats->nDataPages;
621 metadata->nEntries = stats->nEntries;
622
623 /*
624 * Set pd_lower just past the end of the metadata. This is essential,
625 * because without doing so, metadata will be lost if xlog.c compresses
626 * the page. (We must do this here because pre-v11 versions of PG did not
627 * set the metapage's pd_lower correctly, so a pg_upgraded index might
628 * contain the wrong value.)
629 */
630 ((PageHeader) metapage)->pd_lower =
631 ((char *) metadata + sizeof(GinMetaPageData)) - (char *) metapage;
632
634
635 if (RelationNeedsWAL(index) && !is_build)
636 {
639
640 data.locator = index->rd_locator;
641 data.ntuples = 0;
642 data.newRightlink = data.prevTail = InvalidBlockNumber;
643 memcpy(&data.metadata, metadata, sizeof(GinMetaPageData));
644
648
651 }
652
654
656}
#define InvalidBlockNumber
Definition block.h:33
void MarkBufferDirty(Buffer buffer)
Definition bufmgr.c:3147
PageHeaderData * PageHeader
Definition bufpage.h:199
static void PageSetLSN(Page page, XLogRecPtr lsn)
Definition bufpage.h:416
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define GIN_EXCLUSIVE
Definition gin_private.h:53
#define XLOG_GIN_UPDATE_META_PAGE
Definition ginxlog.h:162
#define START_CRIT_SECTION()
Definition miscadmin.h:152
#define END_CRIT_SECTION()
Definition miscadmin.h:154
const void * data
#define RelationNeedsWAL(relation)
Definition rel.h:639
RelFileLocator locator
Definition ginxlog.h:170
uint64 XLogRecPtr
Definition xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition xloginsert.c:482
void XLogRegisterData(const void *data, uint32 len)
Definition xloginsert.c:372
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition xloginsert.c:246
void XLogBeginInsert(void)
Definition xloginsert.c:153
#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(), memcpy(), 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().