PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gin.h File Reference
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
#include "nodes/execnodes.h"
#include "storage/shm_toc.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 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.

◆ 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

typedef struct GinStatsData GinStatsData

◆ GinTernaryValue

typedef char 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 
)

Definition at line 2060 of file gininsert.c.

2061{
2062 char *sharedquery;
2063 GinBuildShared *ginshared;
2064 Sharedsort *sharedsort;
2065 GinBuildState buildstate;
2066 Relation heapRel;
2067 Relation indexRel;
2068 LOCKMODE heapLockmode;
2069 LOCKMODE indexLockmode;
2070 WalUsage *walusage;
2071 BufferUsage *bufferusage;
2072 int sortmem;
2073
2074 /*
2075 * The only possible status flag that can be set to the parallel worker is
2076 * PROC_IN_SAFE_IC.
2077 */
2078 Assert((MyProc->statusFlags == 0) ||
2080
2081 /* Set debug_query_string for individual workers first */
2082 sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, true);
2083 debug_query_string = sharedquery;
2084
2085 /* Report the query string from leader */
2087
2088 /* Look up gin shared state */
2089 ginshared = shm_toc_lookup(toc, PARALLEL_KEY_GIN_SHARED, false);
2090
2091 /* Open relations using lock modes known to be obtained by index.c */
2092 if (!ginshared->isconcurrent)
2093 {
2094 heapLockmode = ShareLock;
2095 indexLockmode = AccessExclusiveLock;
2096 }
2097 else
2098 {
2099 heapLockmode = ShareUpdateExclusiveLock;
2100 indexLockmode = RowExclusiveLock;
2101 }
2102
2103 /* Open relations within worker */
2104 heapRel = table_open(ginshared->heaprelid, heapLockmode);
2105 indexRel = index_open(ginshared->indexrelid, indexLockmode);
2106
2107 /* initialize the GIN build state */
2108 initGinState(&buildstate.ginstate, indexRel);
2109 buildstate.indtuples = 0;
2110 memset(&buildstate.buildStats, 0, sizeof(GinStatsData));
2111 memset(&buildstate.tid, 0, sizeof(ItemPointerData));
2112
2113 /*
2114 * create a temporary memory context that is used to hold data not yet
2115 * dumped out to the index
2116 */
2118 "Gin build temporary context",
2120
2121 /*
2122 * create a temporary memory context that is used for calling
2123 * ginExtractEntries(), and can be reset after each tuple
2124 */
2126 "Gin build temporary context for user-defined function",
2128
2129 buildstate.accum.ginstate = &buildstate.ginstate;
2130 ginInitBA(&buildstate.accum);
2131
2132
2133 /* Look up shared state private to tuplesort.c */
2134 sharedsort = shm_toc_lookup(toc, PARALLEL_KEY_TUPLESORT, false);
2135 tuplesort_attach_shared(sharedsort, seg);
2136
2137 /* Prepare to track buffer usage during parallel execution */
2139
2140 /*
2141 * Might as well use reliable figure when doling out maintenance_work_mem
2142 * (when requested number of workers were not launched, this will be
2143 * somewhat higher than it is for other workers).
2144 */
2145 sortmem = maintenance_work_mem / ginshared->scantuplesortstates;
2146
2147 _gin_parallel_scan_and_build(&buildstate, ginshared, sharedsort,
2148 heapRel, indexRel, sortmem, false);
2149
2150 /* Report WAL/buffer usage during parallel execution */
2151 bufferusage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
2152 walusage = shm_toc_lookup(toc, PARALLEL_KEY_WAL_USAGE, false);
2154 &walusage[ParallelWorkerNumber]);
2155
2156 index_close(indexRel, indexLockmode);
2157 table_close(heapRel, heapLockmode);
2158}
int ParallelWorkerNumber
Definition: parallel.c:115
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
void ginInitBA(BuildAccumulator *accum)
Definition: ginbulk.c:109
#define PARALLEL_KEY_BUFFER_USAGE
Definition: gininsert.c:43
#define PARALLEL_KEY_GIN_SHARED
Definition: gininsert.c:39
static void _gin_parallel_scan_and_build(GinBuildState *state, GinBuildShared *ginshared, Sharedsort *sharedsort, Relation heap, Relation index, int sortmem, bool progress)
Definition: gininsert.c:1985
#define PARALLEL_KEY_TUPLESORT
Definition: gininsert.c:40
#define PARALLEL_KEY_QUERY_TEXT
Definition: gininsert.c:41
#define PARALLEL_KEY_WAL_USAGE
Definition: gininsert.c:42
void initGinState(GinState *state, Relation index)
Definition: ginutil.c:102
int maintenance_work_mem
Definition: globals.c:134
Assert(PointerIsAligned(start, uint64))
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:208
void InstrStartParallelQuery(void)
Definition: instrument.c:200
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:159
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
const char * debug_query_string
Definition: postgres.c:88
#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
GinState * ginstate
Definition: gin_private.h:441
int scantuplesortstates
Definition: gininsert.c:59
bool isconcurrent
Definition: gininsert.c:58
double indtuples
Definition: gininsert.c:142
GinState ginstate
Definition: gininsert.c:141
MemoryContext tmpCtx
Definition: gininsert.c:144
GinStatsData buildStats
Definition: gininsert.c:143
ItemPointerData tid
Definition: gininsert.c:147
MemoryContext funcCtx
Definition: gininsert.c:145
BuildAccumulator accum
Definition: gininsert.c:146
uint8 statusFlags
Definition: proc.h:243
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:2961

References _gin_parallel_scan_and_build(), AccessExclusiveLock, GinBuildState::accum, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), GinBuildState::buildStats, CurrentMemoryContext, debug_query_string, GinBuildState::funcCtx, ginInitBA(), GinBuildState::ginstate, BuildAccumulator::ginstate, GinBuildShared::heaprelid, index_close(), index_open(), GinBuildShared::indexrelid, GinBuildState::indtuples, 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(), GinBuildState::tid, GinBuildState::tmpCtx, and tuplesort_attach_shared().

◆ DatumGetGinTernaryValue()

static GinTernaryValue DatumGetGinTernaryValue ( Datum  X)
inlinestatic

Definition at line 81 of file gin.h.

83{
84 return (GinTernaryValue) X;
char GinTernaryValue
Definition: gin.h:71

Referenced by directTriConsistentFn(), and shimBoolConsistentFn().

◆ ginGetStats()

void ginGetStats ( Relation  index,
GinStatsData stats 
)

Definition at line 628 of file ginutil.c.

629{
630 Buffer metabuffer;
631 Page metapage;
632 GinMetaPageData *metadata;
633
634 metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
635 LockBuffer(metabuffer, GIN_SHARE);
636 metapage = BufferGetPage(metabuffer);
637 metadata = GinPageGetMeta(metapage);
638
639 stats->nPendingPages = metadata->nPendingPages;
640 stats->nTotalPages = metadata->nTotalPages;
641 stats->nEntryPages = metadata->nEntryPages;
642 stats->nDataPages = metadata->nDataPages;
643 stats->nEntries = metadata->nEntries;
644 stats->ginVersion = metadata->ginVersion;
645
646 UnlockReleaseBuffer(metabuffer);
647}
int Buffer
Definition: buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:5320
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:5537
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:751
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:414
PageData * Page
Definition: bufpage.h:82
#define GIN_SHARE
Definition: gin_private.h:50
#define GIN_METAPAGE_BLKNO
Definition: ginblock.h:51
#define GinPageGetMeta(p)
Definition: ginblock.h:104
int64 nEntries
Definition: ginblock.h:82
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
Definition: type.h:96

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().

◆ GinTernaryValueGetDatum()

static Datum GinTernaryValueGetDatum ( GinTernaryValue  X)
inlinestatic

Definition at line 87 of file gin.h.

89{
90 return (Datum) X;
uintptr_t Datum
Definition: postgres.h:69

◆ ginUpdateStats()

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

Definition at line 655 of file ginutil.c.

656{
657 Buffer metabuffer;
658 Page metapage;
659 GinMetaPageData *metadata;
660
661 metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
662 LockBuffer(metabuffer, GIN_EXCLUSIVE);
663 metapage = BufferGetPage(metabuffer);
664 metadata = GinPageGetMeta(metapage);
665
667
668 metadata->nTotalPages = stats->nTotalPages;
669 metadata->nEntryPages = stats->nEntryPages;
670 metadata->nDataPages = stats->nDataPages;
671 metadata->nEntries = stats->nEntries;
672
673 /*
674 * Set pd_lower just past the end of the metadata. This is essential,
675 * because without doing so, metadata will be lost if xlog.c compresses
676 * the page. (We must do this here because pre-v11 versions of PG did not
677 * set the metapage's pd_lower correctly, so a pg_upgraded index might
678 * contain the wrong value.)
679 */
680 ((PageHeader) metapage)->pd_lower =
681 ((char *) metadata + sizeof(GinMetaPageData)) - (char *) metapage;
682
683 MarkBufferDirty(metabuffer);
684
685 if (RelationNeedsWAL(index) && !is_build)
686 {
687 XLogRecPtr recptr;
689
690 data.locator = index->rd_locator;
691 data.ntuples = 0;
692 data.newRightlink = data.prevTail = InvalidBlockNumber;
693 memcpy(&data.metadata, metadata, sizeof(GinMetaPageData));
694
698
699 recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_UPDATE_META_PAGE);
700 PageSetLSN(metapage, recptr);
701 }
702
703 UnlockReleaseBuffer(metabuffer);
704
706}
#define InvalidBlockNumber
Definition: block.h:33
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:2945
PageHeaderData * PageHeader
Definition: bufpage.h:174
static void PageSetLSN(Page page, XLogRecPtr lsn)
Definition: bufpage.h:391
#define GIN_EXCLUSIVE
Definition: gin_private.h:51
#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:639
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogRegisterData(const void *data, uint32 len)
Definition: xloginsert.c:364
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:242
void XLogBeginInsert(void)
Definition: xloginsert.c:149
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define REGBUF_WILL_INIT
Definition: xloginsert.h:34

References BufferGetPage(), data, END_CRIT_SECTION, GIN_EXCLUSIVE, GIN_METAPAGE_BLKNO, GinPageGetMeta, InvalidBlockNumber, 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().