PostgreSQL Source Code git master
|
#include "postgres.h"
#include "access/gin_private.h"
#include "access/gin_tuple.h"
#include "access/parallel.h"
#include "access/table.h"
#include "access/tableam.h"
#include "access/xloginsert.h"
#include "catalog/index.h"
#include "catalog/pg_collation.h"
#include "commands/progress.h"
#include "miscadmin.h"
#include "nodes/execnodes.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/predicate.h"
#include "tcop/tcopprot.h"
#include "utils/datum.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/builtins.h"
Go to the source code of this file.
Data Structures | |
struct | GinBuildShared |
struct | GinLeader |
struct | GinBuildState |
struct | GinBuffer |
struct | GinSegmentInfo |
Macros | |
#define | PARALLEL_KEY_GIN_SHARED UINT64CONST(0xB000000000000001) |
#define | PARALLEL_KEY_TUPLESORT UINT64CONST(0xB000000000000002) |
#define | PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xB000000000000003) |
#define | PARALLEL_KEY_WAL_USAGE UINT64CONST(0xB000000000000004) |
#define | PARALLEL_KEY_BUFFER_USAGE UINT64CONST(0xB000000000000005) |
#define | ParallelTableScanFromGinBuildShared(shared) (ParallelTableScanDesc) ((char *) (shared) + BUFFERALIGN(sizeof(GinBuildShared))) |
Typedefs | |
typedef struct GinBuildShared | GinBuildShared |
typedef struct GinLeader | GinLeader |
typedef struct GinBuffer | GinBuffer |
#define PARALLEL_KEY_BUFFER_USAGE UINT64CONST(0xB000000000000005) |
Definition at line 43 of file gininsert.c.
#define PARALLEL_KEY_GIN_SHARED UINT64CONST(0xB000000000000001) |
Definition at line 39 of file gininsert.c.
#define PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xB000000000000003) |
Definition at line 41 of file gininsert.c.
#define PARALLEL_KEY_TUPLESORT UINT64CONST(0xB000000000000002) |
Definition at line 40 of file gininsert.c.
#define PARALLEL_KEY_WAL_USAGE UINT64CONST(0xB000000000000004) |
Definition at line 42 of file gininsert.c.
#define ParallelTableScanFromGinBuildShared | ( | shared | ) | (ParallelTableScanDesc) ((char *) (shared) + BUFFERALIGN(sizeof(GinBuildShared))) |
Definition at line 104 of file gininsert.c.
typedef struct GinBuildShared GinBuildShared |
|
static |
Definition at line 896 of file gininsert.c.
References _gin_end_parallel(), _gin_leader_participate_as_worker(), _gin_parallel_estimate_shared(), Assert(), GinBuildState::bs_leader, GinLeader::bufferusage, ConditionVariableInit(), CreateParallelContext(), debug_query_string, DestroyParallelContext(), EnterParallelMode(), ParallelContext::estimator, ExitParallelMode(), GetTransactionSnapshot(), GinLeader::ginshared, GinBuildShared::heaprelid, GinBuildShared::indexrelid, GinBuildShared::indtuples, InitializeParallelDSM(), GinBuildShared::isconcurrent, IsMVCCSnapshot, LaunchParallelWorkers(), mul_size(), GinBuildShared::mutex, GinBuildShared::nparticipantsdone, GinLeader::nparticipanttuplesorts, ParallelContext::nworkers, ParallelContext::nworkers_launched, palloc0(), PARALLEL_KEY_BUFFER_USAGE, PARALLEL_KEY_GIN_SHARED, PARALLEL_KEY_QUERY_TEXT, PARALLEL_KEY_TUPLESORT, PARALLEL_KEY_WAL_USAGE, ParallelTableScanFromGinBuildShared, GinLeader::pcxt, RegisterSnapshot(), RelationGetRelid, GinBuildShared::reltuples, GinBuildShared::scantuplesortstates, ParallelContext::seg, GinLeader::sharedsort, shm_toc_allocate(), shm_toc_estimate_chunk, shm_toc_estimate_keys, shm_toc_insert(), GinLeader::snapshot, SnapshotAny, SpinLockInit, table_parallelscan_initialize(), ParallelContext::toc, tuplesort_estimate_shared(), tuplesort_initialize_shared(), UnregisterSnapshot(), WaitForParallelWorkersToAttach(), GinLeader::walusage, and GinBuildShared::workersdonecv.
Referenced by ginbuild().
|
static |
Definition at line 2188 of file gininsert.c.
References GinTuple::attrnum, GinTuple::category, dlist_mutable_iter::cur, GinTuple::data, data, DatumGetPointer(), dlist_container, dlist_delete(), dlist_foreach_modify, dlist_init(), dlist_push_tail(), elog, ERROR, GIN_CAT_NORM_KEY, ginCompressPostingList(), items, sort-test::key, GinTuple::keylen, len, GinTuple::nitems, nitems, GinSegmentInfo::node, palloc(), palloc0(), pfree(), GinSegmentInfo::seg, SHORTALIGN, SizeOfGinPostingList, GinTuple::tuplen, GinTuple::typbyval, GinTuple::typlen, and VARSIZE_ANY.
Referenced by _gin_process_worker_data(), and ginFlushBuildState().
int _gin_compare_tuples | ( | GinTuple * | a, |
GinTuple * | b, | ||
SortSupport | ssup | ||
) |
Definition at line 2390 of file gininsert.c.
References _gin_parse_tuple_key(), a, ApplySortComparator(), b, GIN_CAT_NORM_KEY, GinTupleGetFirst(), and ItemPointerCompare().
Referenced by comparetup_index_gin().
|
static |
Definition at line 1075 of file gininsert.c.
References GinLeader::bufferusage, DestroyParallelContext(), ExitParallelMode(), i, InstrAccumParallelQuery(), IsMVCCSnapshot, ParallelContext::nworkers_launched, GinLeader::pcxt, GinLeader::snapshot, UnregisterSnapshot(), WaitForParallelWorkersToFinish(), and GinLeader::walusage.
Referenced by _gin_begin_parallel(), and ginbuild().
|
static |
Definition at line 1774 of file gininsert.c.
References _gin_parallel_scan_and_build(), GinBuildState::bs_leader, GinLeader::ginshared, maintenance_work_mem, GinLeader::nparticipanttuplesorts, and GinLeader::sharedsort.
Referenced by _gin_begin_parallel().
void _gin_parallel_build_main | ( | dsm_segment * | seg, |
shm_toc * | toc | ||
) |
Definition at line 2060 of file gininsert.c.
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().
Definition at line 1763 of file gininsert.c.
References add_size(), BUFFERALIGN, and table_parallelscan_estimate().
Referenced by _gin_begin_parallel().
|
static |
Definition at line 1106 of file gininsert.c.
References ConditionVariableCancelSleep(), ConditionVariableSleep(), GinBuildShared::indtuples, GinBuildShared::mutex, GinBuildShared::nparticipantsdone, GinBuildShared::reltuples, SpinLockAcquire, SpinLockRelease, and GinBuildShared::workersdonecv.
Referenced by _gin_parallel_merge().
|
static |
Definition at line 1613 of file gininsert.c.
References _gin_parallel_heapscan(), Assert(), AssertCheckItemPointers(), GinBuffer::attnum, GinBuffer::category, CHECK_FOR_INTERRUPTS, GinBufferCanAddKey(), GinBufferFree(), GinBufferInit(), GinBufferIsEmpty(), GinBufferReset(), GinBufferShouldTrim(), GinBufferStoreTuple(), GinBufferTrim(), ginEntryInsert(), GinBuffer::items, GinBuffer::key, GinBuffer::nfrozen, GinBuffer::nitems, pgstat_progress_update_multi_param(), pgstat_progress_update_param(), PROGRESS_CREATEIDX_SUBPHASE, PROGRESS_CREATEIDX_TUPLES_DONE, PROGRESS_CREATEIDX_TUPLES_TOTAL, PROGRESS_GIN_PHASE_MERGE_2, PROGRESS_GIN_PHASE_PERFORMSORT_2, PROGRESS_SCAN_BLOCKS_DONE, PROGRESS_SCAN_BLOCKS_TOTAL, tuplesort_end(), tuplesort_getgintuple(), and tuplesort_performsort().
Referenced by ginbuild().
|
static |
Definition at line 1985 of file gininsert.c.
References _gin_process_worker_data(), BuildIndexInfo(), ConditionVariableSignal(), ginBuildCallbackParallel(), ginFlushBuildState(), IndexInfo::ii_Concurrent, GinBuildShared::indtuples, GinBuildShared::isconcurrent, SortCoordinateData::isWorker, GinBuildShared::mutex, SortCoordinateData::nParticipants, GinBuildShared::nparticipantsdone, palloc0(), ParallelTableScanFromGinBuildShared, progress, GinBuildShared::reltuples, SortCoordinateData::sharedsort, SpinLockAcquire, SpinLockRelease, table_beginscan_parallel(), table_index_build_scan(), tuplesort_begin_index_gin(), tuplesort_end(), TUPLESORT_NONE, tuplesort_performsort(), and GinBuildShared::workersdonecv.
Referenced by _gin_leader_participate_as_worker(), and _gin_parallel_build_main().
|
static |
Definition at line 2358 of file gininsert.c.
References a, Assert(), data, ginPostingListDecodeAllSegments(), items, len, and SHORTALIGN.
Referenced by GinBufferStoreTuple().
Definition at line 2337 of file gininsert.c.
References a, GIN_CAT_NORM_KEY, sort-test::key, and PointerGetDatum().
Referenced by _gin_compare_tuples(), and GinBufferStoreTuple().
|
static |
Definition at line 1807 of file gininsert.c.
References _gin_build_tuple(), Assert(), AssertCheckItemPointers(), GinBuffer::attnum, GinBuffer::category, CHECK_FOR_INTERRUPTS, GinBufferCanAddKey(), GinBufferFree(), GinBufferInit(), GinBufferIsEmpty(), GinBufferReset(), GinBufferShouldTrim(), GinBufferStoreTuple(), GinBufferTrim(), GinBuffer::items, GinBuffer::key, GinBuffer::nfrozen, GinBuffer::nitems, pfree(), pgstat_progress_update_param(), progress, PROGRESS_CREATEIDX_SUBPHASE, PROGRESS_GIN_PHASE_MERGE_1, PROGRESS_GIN_PHASE_PERFORMSORT_1, tuplesort_end(), tuplesort_getgintuple(), tuplesort_performsort(), tuplesort_putgintuple(), GinBuffer::typbyval, and GinBuffer::typlen.
Referenced by _gin_parallel_scan_and_build().
|
static |
Definition at line 209 of file gininsert.c.
References Assert(), attnum, createPostingTree(), ginCompressPostingList(), GinFormTuple(), ginInsertItemPointers(), GinIsPostingTree, GinMaxItemSize, ginMergeItemPointers(), ginReadTuple(), GinSetPostingTree, gintuple_get_attrnum(), gintuple_get_key(), GinState::index, items, sort-test::key, pfree(), and SizeOfGinPostingList.
Referenced by ginEntryInsert().
|
static |
Definition at line 1200 of file gininsert.c.
References Assert(), AssertCheckItemPointers(), GinBuffer::items, and GinBuffer::nitems.
Referenced by GinBufferKeyEquals(), and GinBufferStoreTuple().
|
static |
Definition at line 1173 of file gininsert.c.
References Assert(), i, ItemPointerCompare(), ItemPointerIsValid(), GinBuffer::items, and GinBuffer::nitems.
Referenced by _gin_parallel_merge(), _gin_process_worker_data(), AssertCheckGinBuffer(), and GinBufferStoreTuple().
|
static |
Definition at line 289 of file gininsert.c.
References attnum, createPostingTree(), ginCompressPostingList(), GinFormTuple(), GinMaxItemSize, GinSetPostingTree, GinState::index, items, sort-test::key, pfree(), and SizeOfGinPostingList.
Referenced by ginEntryInsert().
Definition at line 1591 of file gininsert.c.
References GinBufferIsEmpty(), and GinBufferKeyEquals().
Referenced by _gin_parallel_merge(), and _gin_process_worker_data().
|
static |
Definition at line 1571 of file gininsert.c.
References GinBuffer::category, DatumGetPointer(), GIN_CAT_NORM_KEY, GinBufferIsEmpty(), GinBuffer::items, GinBuffer::key, pfree(), and GinBuffer::typbyval.
Referenced by _gin_parallel_merge(), and _gin_process_worker_data().
Definition at line 1229 of file gininsert.c.
References SortSupportData::abbreviate, Assert(), TypeCacheEntry::cmp_proc_finfo, CurrentMemoryContext, ereport, errcode(), errmsg(), ERROR, FmgrInfo::fn_oid, format_type_be(), GIN_COMPARE_PROC, i, index_getprocid(), IndexRelationGetNumberOfKeyAttributes, InvalidOid, lookup_type_cache(), GinBuffer::maxitems, OidIsValid, palloc0(), PrepareSortSupportComparisonShim(), RelationGetDescr, GinBuffer::ssup, SortSupportData::ssup_attno, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, TupleDescAttr(), and TYPECACHE_CMP_PROC_FINFO.
Referenced by _gin_parallel_merge(), and _gin_process_worker_data().
|
static |
Definition at line 1297 of file gininsert.c.
References GinBuffer::nitems.
Referenced by _gin_parallel_merge(), _gin_process_worker_data(), GinBufferCanAddKey(), GinBufferFree(), GinBufferReset(), and GinBufferStoreTuple().
Definition at line 1313 of file gininsert.c.
References ApplySortComparator(), Assert(), AssertCheckGinBuffer(), GinBuffer::attnum, GinTuple::attrnum, GinBuffer::category, GinTuple::category, GinTuple::data, GIN_CAT_NORM_KEY, GinBuffer::key, PointerGetDatum(), GinBuffer::ssup, GinBuffer::typbyval, GinTuple::typbyval, GinBuffer::typlen, and GinTuple::typlen.
Referenced by GinBufferCanAddKey().
|
static |
Definition at line 1525 of file gininsert.c.
References Assert(), GinBuffer::attnum, GinBuffer::category, DatumGetPointer(), GIN_CAT_NORM_KEY, GinBufferIsEmpty(), GinBuffer::key, GinBuffer::keylen, GinBuffer::nfrozen, GinBuffer::nitems, pfree(), GinBuffer::typbyval, and GinBuffer::typlen.
Referenced by _gin_parallel_merge(), and _gin_process_worker_data().
Definition at line 1375 of file gininsert.c.
References GinBuffer::maxitems, GinBuffer::nfrozen, GinBuffer::nitems, and GinTuple::nitems.
Referenced by _gin_parallel_merge(), and _gin_process_worker_data().
Definition at line 1416 of file gininsert.c.
References _gin_parse_tuple_items(), _gin_parse_tuple_key(), Assert(), AssertCheckGinBuffer(), AssertCheckItemPointers(), GinBuffer::attnum, GinTuple::attrnum, GinBuffer::category, GinTuple::category, datumCopy(), GIN_CAT_NORM_KEY, GinBufferIsEmpty(), ginMergeItemPointers(), GinTupleGetFirst(), i, ItemPointerCompare(), GinBuffer::items, items, GinBuffer::key, sort-test::key, GinBuffer::keylen, GinTuple::keylen, GinBuffer::nfrozen, GinBuffer::nitems, GinTuple::nitems, nitems, palloc(), pfree(), repalloc(), GinBuffer::typbyval, GinTuple::typbyval, GinBuffer::typlen, and GinTuple::typlen.
Referenced by _gin_parallel_merge(), and _gin_process_worker_data().
|
static |
Definition at line 1555 of file gininsert.c.
References Assert(), GinBuffer::items, GinBuffer::nfrozen, and GinBuffer::nitems.
Referenced by _gin_parallel_merge(), and _gin_process_worker_data().
IndexBuildResult * ginbuild | ( | Relation | heap, |
Relation | index, | ||
IndexInfo * | indexInfo | ||
) |
Definition at line 581 of file gininsert.c.
References _gin_begin_parallel(), _gin_end_parallel(), _gin_parallel_merge(), GinBuildState::accum, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, attnum, GinBuildState::bs_leader, GinBuildState::bs_numtuples, GinBuildState::bs_reltuples, GinBuildState::buildStats, CHECK_FOR_INTERRUPTS, CurrentMemoryContext, elog, END_CRIT_SECTION, ERROR, GinBuildState::funcCtx, GIN_LEAF, ginBeginBAScan(), ginBuildCallback(), ginEntryInsert(), ginGetBAEntry(), ginInitBA(), GinInitBuffer(), GinInitMetabuffer(), GinNewBuffer(), GinBuildState::ginstate, BuildAccumulator::ginstate, ginUpdateStats(), IndexBuildResult::heap_tuples, IndexInfo::ii_Concurrent, IndexInfo::ii_ParallelWorkers, IndexBuildResult::index_tuples, GinBuildState::indtuples, initGinState(), SortCoordinateData::isWorker, sort-test::key, sort-test::list, log_newpage_range(), MAIN_FORKNUM, maintenance_work_mem, MarkBufferDirty(), MemoryContextDelete(), MemoryContextSwitchTo(), GinStatsData::nEntryPages, SortCoordinateData::nParticipants, GinStatsData::nTotalPages, palloc(), palloc0(), pgstat_progress_update_param(), PROGRESS_CREATEIDX_SUBPHASE, PROGRESS_GIN_PHASE_INDEXBUILD_TABLESCAN, RelationGetNumberOfBlocks, RelationGetRelationName, RelationNeedsWAL, SortCoordinateData::sharedsort, START_CRIT_SECTION, table_index_build_scan(), GinBuildState::tid, GinBuildState::tmpCtx, tuplesort_begin_index_gin(), TUPLESORT_NONE, and UnlockReleaseBuffer().
Referenced by ginhandler().
|
static |
Definition at line 440 of file gininsert.c.
References GinBuildState::accum, BuildAccumulator::allocatedMemory, attnum, GinBuildState::buildStats, CHECK_FOR_INTERRUPTS, ginBeginBAScan(), ginEntryInsert(), ginGetBAEntry(), ginHeapTupleBulkInsert(), ginInitBA(), GinBuildState::ginstate, i, sort-test::key, sort-test::list, maintenance_work_mem, MemoryContextReset(), MemoryContextSwitchTo(), TupleDescData::natts, GinState::origTupdesc, GinBuildState::tmpCtx, and values.
Referenced by ginbuild().
|
static |
Definition at line 533 of file gininsert.c.
References GinBuildState::accum, BuildAccumulator::allocatedMemory, ginFlushBuildState(), ginHeapTupleBulkInsert(), GinBuildState::ginstate, i, ItemPointerCompare(), MemoryContextSwitchTo(), TupleDescData::natts, GinState::origTupdesc, GinBuildState::tid, GinBuildState::tmpCtx, values, and GinBuildState::work_mem.
Referenced by _gin_parallel_scan_and_build().
void ginbuildempty | ( | Relation | index | ) |
Definition at line 775 of file gininsert.c.
References BMR_REL, EB_LOCK_FIRST, EB_SKIP_EXTENSION_LOCK, END_CRIT_SECTION, ExtendBufferedRel(), GIN_LEAF, GinInitBuffer(), GinInitMetabuffer(), INIT_FORKNUM, log_newpage_buffer(), MarkBufferDirty(), START_CRIT_SECTION, and UnlockReleaseBuffer().
Referenced by ginhandler().
void ginEntryInsert | ( | GinState * | ginstate, |
OffsetNumber | attnum, | ||
Datum | key, | ||
GinNullCategory | category, | ||
ItemPointerData * | items, | ||
uint32 | nitem, | ||
GinStatsData * | buildStats | ||
) |
Definition at line 339 of file gininsert.c.
References addItemPointersToLeafTuple(), attnum, GinBtreeStack::buffer, BufferGetBlockNumber(), BufferGetPage(), buildFreshLeafTuple(), CheckForSerializableConflictIn(), GinBtreeEntryInsertData::entry, GinBtreeData::findItem, freeGinBtreeStack(), GIN_UNLOCK, ginFindLeafPage(), GinGetPostingTree, ginInsertItemPointers(), ginInsertValue(), GinIsPostingTree, ginPrepareEntryScan(), GinState::index, GinBtreeData::isBuild, GinBtreeEntryInsertData::isDelete, items, sort-test::key, LockBuffer(), GinStatsData::nEntries, GinBtreeStack::off, PageGetItem(), PageGetItemId(), and pfree().
Referenced by _gin_parallel_merge(), ginbuild(), ginBuildCallback(), ginHeapTupleInsert(), and ginInsertCleanup().
|
static |
Definition at line 484 of file gininsert.c.
References _gin_build_tuple(), GinBuildState::accum, attnum, GinBuildState::bs_worker_sort, CHECK_FOR_INTERRUPTS, ginBeginBAScan(), ginGetBAEntry(), ginInitBA(), sort-test::key, sort-test::list, MemoryContextReset(), pfree(), RelationGetDescr, GinBuildState::tmpCtx, TupleDescAttr(), and tuplesort_putgintuple().
Referenced by _gin_parallel_scan_and_build(), and ginBuildCallbackParallel().
|
static |
Definition at line 416 of file gininsert.c.
References GinBuildState::accum, attnum, GinBuildState::funcCtx, ginExtractEntries(), ginInsertBAEntries(), BuildAccumulator::ginstate, GinBuildState::indtuples, MemoryContextReset(), MemoryContextSwitchTo(), and value.
Referenced by ginBuildCallback(), and ginBuildCallbackParallel().
|
static |
Definition at line 806 of file gininsert.c.
References attnum, ginEntryInsert(), ginExtractEntries(), i, and value.
Referenced by gininsert().
bool gininsert | ( | Relation | index, |
Datum * | values, | ||
bool * | isnull, | ||
ItemPointer | ht_ctid, | ||
Relation | heapRel, | ||
IndexUniqueCheck | checkUnique, | ||
bool | indexUnchanged, | ||
IndexInfo * | indexInfo | ||
) |
Definition at line 824 of file gininsert.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CurrentMemoryContext, GinGetUseFastUpdate, ginHeapTupleFastCollect(), ginHeapTupleFastInsert(), ginHeapTupleInsert(), i, if(), IndexInfo::ii_AmCache, IndexInfo::ii_Context, initGinState(), MemoryContextDelete(), MemoryContextSwitchTo(), TupleDescData::natts, GinState::origTupdesc, palloc(), and values.
Referenced by ginhandler().