68 #define PARALLEL_KEY_BTREE_SHARED UINT64CONST(0xA000000000000001) 69 #define PARALLEL_KEY_TUPLESORT UINT64CONST(0xA000000000000002) 70 #define PARALLEL_KEY_TUPLESORT_SPOOL2 UINT64CONST(0xA000000000000003) 71 #define PARALLEL_KEY_QUERY_TEXT UINT64CONST(0xA000000000000004) 72 #define PARALLEL_KEY_WAL_USAGE UINT64CONST(0xA000000000000005) 73 #define PARALLEL_KEY_BUFFER_USAGE UINT64CONST(0xA000000000000006) 163 #define ParallelTableScanFromBTShared(shared) \ 164 (ParallelTableScanDesc) ((char *) (shared) + BUFFERALIGN(sizeof(BTShared))) 266 bool *isnull,
bool tupleIsAlive,
void *
state);
272 bool newfirstdataitem);
286 bool *brokenhotchain);
304 #ifdef BTREE_BUILD_STATS 312 buildstate.
spool = NULL;
322 elog(
ERROR,
"index \"%s\" already contains data",
344 #ifdef BTREE_BUILD_STATS 372 double reltuples = 0;
385 buildstate->
spool = btspool;
450 buildstate->
spool2 = btspool2;
489 const int index[] = {
494 const int64
val[] = {
495 buildstate->indtuples,
503 if (buildstate->spool2 && !buildstate->havedead)
507 buildstate->spool2 = NULL;
530 self, values, isnull);
542 #ifdef BTREE_BUILD_STATS 545 ShowUsage(
"BTREE BUILD (Spool) STATISTICS");
574 _bt_load(&wstate, btspool, btspool2);
594 if (tupleIsAlive || buildstate->
spool2 == NULL)
677 (
char *) page,
true);
684 (
char *) page,
true);
767 bool newfirstdataitem)
771 if (newfirstdataitem)
782 elog(
ERROR,
"failed to add item to the index page");
839 Size last_truncextra;
899 Assert(last_truncextra == 0 || isleaf);
901 (pgspc + last_truncextra < state->btps_full && last_off >
P_FIRSTKEY))
981 elog(
ERROR,
"failed to add high key to the index page");
1095 pfree(postingtuple);
1118 for (s = state; s != NULL; s = s->
btps_next)
1183 bool merge = (btspool2 != NULL);
1191 int64 tuples_done = 0;
1211 for (i = 0; i < keysz; i++)
1241 else if (itup != NULL)
1245 for (i = 1; i <= keysz; i++)
1253 entry = sortKeys + i - 1;
1258 attrDatum2, isNull2,
1265 else if (compare < 0)
1307 else if (deduplicate)
1317 dstate->
base = NULL;
1321 dstate->
htids = NULL;
1456 int scantuplesortstates;
1467 bool leaderparticipates =
true;
1470 #ifdef DISABLE_LEADER_PARTICIPATION 1471 leaderparticipates =
false;
1483 scantuplesortstates = leaderparticipates ? request + 1 : request;
1547 if (pcxt->
seg == NULL)
1627 btleader->
pcxt = pcxt;
1629 if (leaderparticipates)
1649 if (leaderparticipates)
1712 int nparticipanttuplesorts;
1758 leaderworker2 = NULL;
1765 leaderworker2->
heap = leaderworker->
heap;
1782 #ifdef BTREE_BUILD_STATS 1785 ShowUsage(
"BTREE BUILD (Leader Partial Spool) STATISTICS");
1811 #ifdef BTREE_BUILD_STATS 1844 btspool->
heap = heapRel;
1845 btspool->
index = indexRel;
1876 sharedsort2, sortmem,
false);
1882 &walusage[ParallelWorkerNumber]);
1884 #ifdef BTREE_BUILD_STATS 1887 ShowUsage(
"BTREE BUILD (Worker Partial Spool) STATISTICS");
1929 sortmem, coordinate,
1960 buildstate.
spool = btspool;
1961 buildstate.
spool2 = btspool2;
1972 (
void *) &buildstate, scan);
1992 if (buildstate.havedead)
1994 btshared->
indtuples += buildstate.indtuples;
struct SortSupportData * SortSupport
IndexTuple tuplesort_getindextuple(Tuplesortstate *state, bool forward)
static void _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
void tuplesort_performsort(Tuplesortstate *state)
#define PROGRESS_BTREE_PHASE_INDEXBUILD_TABLESCAN
void table_close(Relation relation, LOCKMODE lockmode)
#define BTGreaterStrategyNumber
struct BTWriteState BTWriteState
#define PARALLEL_KEY_TUPLESORT
#define AssertState(condition)
ParallelContext * CreateParallelContext(const char *library_name, const char *function_name, int nworkers)
static void _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
Snapshot RegisterSnapshot(Snapshot snapshot)
#define RelationGetDescr(relation)
BTScanInsert _bt_mkscankey(Relation rel, IndexTuple itup)
#define BTGetTargetPageFreeSpace(relation)
void pgstat_report_activity(BackendState state, const char *cmd_str)
#define BTGetDeduplicateItems(relation)
#define PROGRESS_BTREE_PHASE_PERFORMSORT_1
static void _bt_sort_dedup_finish_pending(BTWriteState *wstate, BTPageState *state, BTDedupState dstate)
void ShowUsage(const char *title)
BlockNumber btws_pages_alloced
struct SMgrRelationData * rd_smgr
void pgstat_progress_update_param(int index, int64 val)
shm_toc_estimator estimator
#define SpinLockInit(lock)
void _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
union BTPageOpaqueData::@46 btpo
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
static void _bt_slideleft(Page rightmostpage)
#define ParallelTableScanFromBTShared(shared)
void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level, bool allequalimage)
#define PROGRESS_CREATEIDX_TUPLES_TOTAL
void _bt_dedup_start_pending(BTDedupState state, IndexTuple base, OffsetNumber baseoff)
static void _bt_end_parallel(BTLeader *btleader)
Tuplesortstate * sortstate
IndexInfo * BuildIndexInfo(Relation index)
static void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
void tuplesort_initialize_shared(Sharedsort *shared, int nWorkers, dsm_segment *seg)
#define shm_toc_estimate_chunk(e, sz)
#define BTreeTupleGetNAtts(itup, rel)
void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
static void _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
static pairingheap_node * merge(pairingheap *heap, pairingheap_node *a, pairingheap_node *b)
Snapshot GetTransactionSnapshot(void)
#define PageGetMaxOffsetNumber(page)
BTPageOpaqueData * BTPageOpaque
Size PageGetFreeSpace(Page page)
struct BTBuildState BTBuildState
static void BTreeTupleSetNAtts(IndexTuple itup, uint16 nkeyatts, bool heaptid)
#define RelationOpenSmgr(relation)
IndexTuple _bt_truncate(Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
void WaitForParallelWorkersToFinish(ParallelContext *pcxt)
#define SpinLockAcquire(lock)
void ConditionVariableInit(ConditionVariable *cv)
void DestroyParallelContext(ParallelContext *pcxt)
#define ItemIdGetLength(itemId)
void pfree(void *pointer)
#define PARALLEL_KEY_BUFFER_USAGE
void ConditionVariableCancelSleep(void)
#define BTREE_NONLEAF_FILLFACTOR
static int compare(const void *arg1, const void *arg2)
static double _bt_parallel_heapscan(BTBuildState *buildstate, bool *brokenhotchain)
IndexBuildResult * btbuild(Relation heap, Relation index, IndexInfo *indexInfo)
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 ConditionVariableSignal(ConditionVariable *cv)
#define PROGRESS_BTREE_PHASE_PERFORMSORT_2
void ExitParallelMode(void)
BufferUsage * bufferusage
bool PageIndexTupleOverwrite(Page page, OffsetNumber offnum, Item newtup, Size newsize)
IndexTuple CopyIndexTuple(IndexTuple source)
OffsetNumber btps_lastoff
static void _bt_sortaddtup(Page page, Size itemsize, IndexTuple itup, OffsetNumber itup_off, bool newfirstdataitem)
bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
IndexTupleData * IndexTuple
#define PARALLEL_KEY_QUERY_TEXT
#define RelationGetRelationName(relation)
#define P_LEFTMOST(opaque)
#define PARALLEL_KEY_TUPLESORT_SPOOL2
struct ItemIdData ItemIdData
MemoryContext CurrentMemoryContext
static void BTreeTupleSetDownLink(IndexTuple pivot, BlockNumber blkno)
#define IndexRelationGetNumberOfKeyAttributes(relation)
void PrepareSortSupportFromIndexRel(Relation indexRel, int16 strategy, SortSupport ssup)
void LaunchParallelWorkers(ParallelContext *pcxt)
void InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
void UnregisterSnapshot(Snapshot snapshot)
TableScanDesc table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
const char * debug_query_string
void InitializeParallelDSM(ParallelContext *pcxt)
#define PageGetItemId(page, offsetNumber)
#define SK_BT_NULLS_FIRST
void InstrStartParallelQuery(void)
#define SpinLockRelease(lock)
Size mul_size(Size s1, Size s2)
BlockNumber btws_pages_written
void * palloc0(Size size)
struct SortCoordinateData * SortCoordinate
#define PROGRESS_SCAN_BLOCKS_DONE
struct IndexTupleData IndexTupleData
static BTPageState * _bt_pagestate(BTWriteState *wstate, uint32 level)
static void _bt_build_callback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
Size add_size(Size s1, Size s2)
static double _bt_spools_heapscan(Relation heap, Relation index, BTBuildState *buildstate, IndexInfo *indexInfo)
bool log_btree_build_stats
#define RelationGetNumberOfBlocks(reln)
static void _bt_parallel_scan_and_sort(BTSpool *btspool, BTSpool *btspool2, BTShared *btshared, Sharedsort *sharedsort, Sharedsort *sharedsort2, int sortmem, bool progress)
#define IsMVCCSnapshot(snapshot)
struct BTPageState * btps_next
#define InvalidOffsetNumber
void tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel, ItemPointer self, Datum *values, bool *isnull)
static void _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup, Size truncextra)
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot)
void tuplesort_attach_shared(Sharedsort *shared, dsm_segment *seg)
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
#define ShareUpdateExclusiveLock
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
PageHeaderData * PageHeader
#define Assert(condition)
int nparticipanttuplesorts
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
#define OffsetNumberNext(offsetNumber)
#define PageGetSpecialPointer(page)
static Size _bt_parallel_estimate_shared(Relation heap, Snapshot snapshot)
#define shm_toc_estimate_keys(e, cnt)
#define OffsetNumberPrev(offsetNumber)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
#define index_getattr(tup, attnum, tupleDesc, isnull)
void EnterParallelMode(void)
#define PROGRESS_SCAN_BLOCKS_TOTAL
ScanKeyData scankeys[INDEX_MAX_KEYS]
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
static void _bt_leader_participate_as_worker(BTBuildState *buildstate)
Size tuplesort_estimate_shared(int nWorkers)
#define RelationNeedsWAL(relation)
void _bt_check_third_page(Relation rel, Relation heap, bool needheaptidspace, Page page, IndexTuple newtup)
#define PROGRESS_BTREE_PHASE_LEAF_LOAD
static void _bt_spooldestroy(BTSpool *btspool)
void index_close(Relation relation, LOCKMODE lockmode)
void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
#define BTMaxItemSize(page)
static Datum values[MAXATTR]
struct BTPageState BTPageState
#define AccessExclusiveLock
#define PARALLEL_KEY_WAL_USAGE
int _bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
#define PROGRESS_CREATEIDX_TUPLES_DONE
static Page _bt_blnewpage(uint32 level)
XLogRecPtr log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno, Page page, bool page_std)
static void _bt_spool(BTSpool *btspool, ItemPointer self, Datum *values, bool *isnull)
void _bt_pageinit(Page page, Size size)
#define CHECK_FOR_INTERRUPTS()
#define PROGRESS_CREATEIDX_SUBPHASE
Tuplesortstate * tuplesort_begin_index_btree(Relation heapRel, Relation indexRel, bool enforceUnique, int workMem, SortCoordinate coordinate, bool randomAccess)
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state)
ConditionVariable workersdonecv
BTDedupStateData * BTDedupState
#define ItemIdSetUnused(itemId)
#define PARALLEL_KEY_BTREE_SHARED
void table_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan, Snapshot snapshot)
void tuplesort_end(Tuplesortstate *state)
#define BTLessStrategyNumber
Relation table_open(Oid relationId, LOCKMODE lockmode)
bool _bt_allequalimage(Relation rel, bool debugmessage)
static int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
void WaitForParallelWorkersToAttach(ParallelContext *pcxt)
void smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
#define RelationGetRelid(relation)
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Relation index_open(Oid relationId, LOCKMODE lockmode)
#define PageGetItem(page, itemId)
#define IndexTupleSize(itup)
#define MAXALIGN_DOWN(LEN)