61#define PARALLEL_KEY_BTREE_SHARED UINT64CONST(0xA000000000000001)
62#define PARALLEL_KEY_TUPLESORT UINT64CONST(0xA000000000000002)
63#define PARALLEL_KEY_TUPLESORT_SPOOL2 UINT64CONST(0xA000000000000003)
64#define PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xA000000000000004)
65#define PARALLEL_KEY_WAL_USAGE UINT64CONST(0xA000000000000005)
66#define PARALLEL_KEY_BUFFER_USAGE UINT64CONST(0xA000000000000006)
161#define ParallelTableScanFromBTShared(shared) \
162 (ParallelTableScanDesc) ((char *) (shared) + BUFFERALIGN(sizeof(BTShared)))
263 bool *isnull,
bool tupleIsAlive,
void *
state);
269 bool newfirstdataitem);
283 bool *brokenhotchain);
301#ifdef BTREE_BUILD_STATS
309 buildstate.
heap = heap;
310 buildstate.
spool = NULL;
320 elog(
ERROR,
"index \"%s\" already contains data",
342#ifdef BTREE_BUILD_STATS
370 double reltuples = 0;
378 btspool->
heap = heap;
384 buildstate->
spool = btspool;
446 btspool2->
heap = heap;
450 buildstate->
spool2 = btspool2;
489 const int progress_index[] = {
494 const int64 progress_vals[] = {
507 buildstate->
spool2 = NULL;
542#ifdef BTREE_BUILD_STATS
545 ShowUsage(
"BTREE BUILD (Spool) STATISTICS");
572 _bt_load(&wstate, btspool, btspool2);
592 if (tupleIsAlive || buildstate->
spool2 == NULL)
658 state->btps_lowkey = NULL;
661 state->btps_lastextra = 0;
662 state->btps_level = level;
670 state->btps_next = NULL;
720 bool newfirstdataitem)
724 if (newfirstdataitem)
735 elog(
ERROR,
"failed to add item to the index page");
793 Size last_truncextra;
804 nbuf =
state->btps_buf;
806 nblkno =
state->btps_blkno;
807 last_off =
state->btps_lastoff;
808 last_truncextra =
state->btps_lastextra;
809 state->btps_lastextra = truncextra;
815 isleaf = (
state->btps_level == 0);
854 Assert(last_truncextra == 0 || isleaf);
856 (pgspc + last_truncextra < state->btps_full && last_off >
P_FIRSTKEY))
938 elog(
ERROR,
"failed to add high key to the index page");
950 if (
state->btps_next == NULL)
1018 state->btps_buf = nbuf;
1019 state->btps_blkno = nblkno;
1020 state->btps_lastoff = last_off;
1052 pfree(postingtuple);
1140 bool merge = (btspool2 != NULL);
1148 int64 tuples_done = 0;
1170 for (
i = 0;
i < keysz;
i++)
1200 else if (itup != NULL)
1204 for (
i = 1;
i <= keysz;
i++)
1212 entry = sortKeys +
i - 1;
1217 attrDatum2, isNull2,
1266 else if (deduplicate)
1276 dstate->
base = NULL;
1280 dstate->
htids = NULL;
1401 int scantuplesortstates;
1412 bool leaderparticipates =
true;
1415#ifdef DISABLE_LEADER_PARTICIPATION
1416 leaderparticipates =
false;
1428 scantuplesortstates = leaderparticipates ? request + 1 : request;
1492 if (pcxt->
seg == NULL)
1574 btleader->
pcxt = pcxt;
1576 if (leaderparticipates)
1596 if (leaderparticipates)
1659 int nparticipanttuplesorts;
1678 WAIT_EVENT_PARALLEL_CREATE_INDEX_SCAN);
1706 leaderworker2 = NULL;
1713 leaderworker2->
heap = leaderworker->
heap;
1730#ifdef BTREE_BUILD_STATS
1733 ShowUsage(
"BTREE BUILD (Leader Partial Spool) STATISTICS");
1759#ifdef BTREE_BUILD_STATS
1802 btspool->
heap = heapRel;
1803 btspool->
index = indexRel;
1835 sharedsort2, sortmem,
false);
1843#ifdef BTREE_BUILD_STATS
1846 ShowUsage(
"BTREE BUILD (Worker Partial Spool) STATISTICS");
1889 sortmem, coordinate,
1921 buildstate.
spool = btspool;
1922 buildstate.
spool2 = btspool2;
void InitializeParallelDSM(ParallelContext *pcxt)
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
void LaunchParallelWorkers(ParallelContext *pcxt)
void DestroyParallelContext(ParallelContext *pcxt)
ParallelContext * CreateParallelContext(const char *library_name, const char *function_name, int nworkers)
void WaitForParallelWorkersToAttach(ParallelContext *pcxt)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
uint64 pgstat_get_my_query_id(void)
void pgstat_report_query_id(uint64 query_id, bool force)
void pgstat_report_activity(BackendState state, const char *cmd_str)
static Datum values[MAXATTR]
#define RelationGetNumberOfBlocks(reln)
Size PageGetFreeSpace(const PageData *page)
bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum, Item newtup, Size newsize)
PageHeaderData * PageHeader
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
BulkWriteState * smgr_bulk_start_rel(Relation rel, ForkNumber forknum)
void smgr_bulk_write(BulkWriteState *bulkstate, BlockNumber blocknum, BulkWriteBuffer buf, bool page_std)
BulkWriteBuffer smgr_bulk_get_buf(BulkWriteState *bulkstate)
void smgr_bulk_finish(BulkWriteState *bulkstate)
#define MAXALIGN_DOWN(LEN)
#define Assert(condition)
bool ConditionVariableCancelSleep(void)
void ConditionVariableInit(ConditionVariable *cv)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
void ConditionVariableSignal(ConditionVariable *cv)
static int compare(const void *arg1, const void *arg2)
bool log_btree_build_stats
IndexInfo * BuildIndexInfo(Relation index)
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
IndexTuple CopyIndexTuple(IndexTuple source)
void InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
void InstrStartParallelQuery(void)
#define ItemIdGetLength(itemId)
struct ItemIdData ItemIdData
#define ItemIdSetUnused(itemId)
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
IndexTupleData * IndexTuple
#define IndexTupleSize(itup)
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
struct IndexTupleData IndexTupleData
#define AccessExclusiveLock
#define ShareUpdateExclusiveLock
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
void _bt_dedup_start_pending(BTDedupState state, IndexTuple base, OffsetNumber baseoff)
IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
void _bt_pageinit(Page page, Size size)
void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level, bool allequalimage)
#define BTGetDeduplicateItems(relation)
#define BTGetTargetPageFreeSpace(relation)
#define PROGRESS_BTREE_PHASE_PERFORMSORT_2
#define PROGRESS_BTREE_PHASE_LEAF_LOAD
#define P_LEFTMOST(opaque)
#define BTPageGetOpaque(page)
static void BTreeTupleSetDownLink(IndexTuple pivot, BlockNumber blkno)
#define PROGRESS_BTREE_PHASE_INDEXBUILD_TABLESCAN
#define PROGRESS_BTREE_PHASE_PERFORMSORT_1
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
#define BTMaxItemSize(page)
#define SK_BT_NULLS_FIRST
BTDedupStateData * BTDedupState
static void BTreeTupleSetNAtts(IndexTuple itup, uint16 nkeyatts, bool heaptid)
#define BTreeTupleGetNAtts(itup, rel)
#define BTREE_NONLEAF_FILLFACTOR
#define PARALLEL_KEY_BUFFER_USAGE
#define ParallelTableScanFromBTShared(shared)
static void _bt_blwritepage(BTWriteState *wstate, BulkWriteBuffer buf, BlockNumber blkno)
static void _bt_sortaddtup(Page page, Size itemsize, IndexTuple itup, OffsetNumber itup_off, bool newfirstdataitem)
static void _bt_slideleft(Page rightmostpage)
static BTPageState * _bt_pagestate(BTWriteState *wstate, uint32 level)
static void _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
static void _bt_end_parallel(BTLeader *btleader)
#define PARALLEL_KEY_TUPLESORT_SPOOL2
static void _bt_parallel_scan_and_sort(BTSpool *btspool, BTSpool *btspool2, BTShared *btshared, Sharedsort *sharedsort, Sharedsort *sharedsort2, int sortmem, bool progress)
static Size _bt_parallel_estimate_shared(Relation heap, Snapshot snapshot)
struct BTPageState BTPageState
static void _bt_sort_dedup_finish_pending(BTWriteState *wstate, BTPageState *state, BTDedupState dstate)
static double _bt_parallel_heapscan(BTBuildState *buildstate, bool *brokenhotchain)
static void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
#define PARALLEL_KEY_BTREE_SHARED
IndexBuildResult * btbuild(Relation heap, Relation index, IndexInfo *indexInfo)
static void _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
static void _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup, Size truncextra)
struct BTBuildState BTBuildState
void _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
static void _bt_build_callback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
static double _bt_spools_heapscan(Relation heap, Relation index, BTBuildState *buildstate, IndexInfo *indexInfo)
static void _bt_spooldestroy(BTSpool *btspool)
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state)
#define PARALLEL_KEY_TUPLESORT
#define PARALLEL_KEY_QUERY_TEXT
#define PARALLEL_KEY_WAL_USAGE
static BulkWriteBuffer _bt_blnewpage(BTWriteState *wstate, uint32 level)
static void _bt_leader_participate_as_worker(BTBuildState *buildstate)
struct BTWriteState BTWriteState
static void _bt_spool(BTSpool *btspool, ItemPointer self, Datum *values, bool *isnull)
void _bt_check_third_page(Relation rel, Relation heap, bool needheaptidspace, Page page, IndexTuple newtup)
BTScanInsert _bt_mkscankey(Relation rel, IndexTuple itup)
IndexTuple _bt_truncate(Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
int _bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
bool _bt_allequalimage(Relation rel, bool debugmessage)
#define InvalidOffsetNumber
#define OffsetNumberNext(offsetNumber)
#define OffsetNumberPrev(offsetNumber)
static pairingheap_node * merge(pairingheap *heap, pairingheap_node *a, pairingheap_node *b)
const char * debug_query_string
void ShowUsage(const char *title)
#define PROGRESS_CREATEIDX_TUPLES_TOTAL
#define PROGRESS_SCAN_BLOCKS_DONE
#define PROGRESS_CREATEIDX_TUPLES_DONE
#define PROGRESS_CREATEIDX_SUBPHASE
#define PROGRESS_SCAN_BLOCKS_TOTAL
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
#define shm_toc_estimate_chunk(e, sz)
#define shm_toc_estimate_keys(e, cnt)
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
Snapshot GetTransactionSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
Snapshot RegisterSnapshot(Snapshot snapshot)
#define IsMVCCSnapshot(snapshot)
void PrepareSortSupportFromIndexRel(Relation indexRel, int16 strategy, SortSupport ssup)
struct SortSupportData * SortSupport
static int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
#define BTGreaterStrategyNumber
#define BTLessStrategyNumber
int nparticipanttuplesorts
BufferUsage * bufferusage
OffsetNumber btps_lastoff
struct BTPageState * btps_next
ScanKeyData scankeys[INDEX_MAX_KEYS]
ConditionVariable workersdonecv
Tuplesortstate * sortstate
BulkWriteState * bulkstate
BlockNumber btws_pages_alloced
shm_toc_estimator estimator
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc pscan)
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
static double table_index_build_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, bool allow_sync, bool progress, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
void tuplesort_performsort(Tuplesortstate *state)
void tuplesort_initialize_shared(Sharedsort *shared, int nWorkers, dsm_segment *seg)
Size tuplesort_estimate_shared(int nWorkers)
void tuplesort_end(Tuplesortstate *state)
void tuplesort_attach_shared(Sharedsort *shared, dsm_segment *seg)
struct SortCoordinateData * SortCoordinate
IndexTuple tuplesort_getindextuple(Tuplesortstate *state, bool forward)
void tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel, ItemPointer self, const Datum *values, const bool *isnull)
Tuplesortstate * tuplesort_begin_index_btree(Relation heapRel, Relation indexRel, bool enforceUnique, bool uniqueNullsNotDistinct, int workMem, SortCoordinate coordinate, int sortopt)
void ExitParallelMode(void)
void EnterParallelMode(void)