35#include "utils/fmgrprotos.h"
124 .amcanorderbyop =
false,
126 .amconsistentequality =
true,
127 .amconsistentordering =
true,
128 .amcanbackward =
true,
130 .amcanmulticol =
true,
131 .amoptionalkey =
true,
132 .amsearcharray =
true,
133 .amsearchnulls =
true,
135 .amclusterable =
true,
137 .amcanparallel =
true,
138 .amcanbuildparallel =
true,
139 .amcaninclude =
true,
140 .amusemaintenanceworkmem =
false,
141 .amsummarizing =
false,
142 .amparallelvacuumoptions =
149 .aminsertcleanup =
NULL,
264 if (
so->killedItems ==
NULL)
267 so->killedItems[
so->numKilled++] =
so->currPos.itemIndex;
314 if (++
so->currPos.itemIndex >
so->currPos.lastItem)
322 heapTid = &
so->currPos.items[
so->currPos.itemIndex].heapTid;
357 so->skipScan =
false;
358 so->needPrimScan =
false;
359 so->scanBehind =
false;
360 so->oppositeDirCheck =
false;
373 so->currTuples =
so->markTuples =
NULL;
387 ScanKey orderbys,
int norderbys)
395 if (
so->numKilled > 0)
429 so->markItemIndex = -1;
430 so->needPrimScan =
false;
431 so->scanBehind =
false;
432 so->oppositeDirCheck =
false;
453 so->numberOfKeys = 0;
454 so->numArrayKeys = 0;
469 if (
so->numKilled > 0)
474 so->markItemIndex = -1;
483 if (
so->arrayContext !=
NULL)
485 if (
so->killedItems !=
NULL)
487 if (
so->currTuples !=
NULL)
511 so->markItemIndex =
so->currPos.itemIndex;
515 so->markItemIndex = -1;
527 if (
so->markItemIndex >= 0)
536 so->currPos.itemIndex =
so->markItemIndex;
549 if (
so->numKilled > 0)
564 so->markPos.nextTupleOffset);
566 if (
so->numArrayKeys)
569 so->needPrimScan =
false;
665 so->scanBehind =
so->oppositeDirCheck =
false;
701 if (
so->needPrimScan)
730 for (
int i = 0;
i <
so->numArrayKeys;
i++)
773 for (
int i = 0;
i <
so->numArrayKeys;
i++)
897 so->currPos.moreLeft =
so->currPos.moreRight =
true;
905 so->needPrimScan =
false;
906 so->scanBehind =
false;
907 so->oppositeDirCheck =
false;
915 if (
so->needPrimScan)
965 so->needPrimScan =
true;
966 so->scanBehind =
false;
967 so->oppositeDirCheck =
false;
1051 if (parallel_scan ==
NULL)
1058 if (
so->needPrimScan)
1278 vstate.callback_state = callback_state;
1279 vstate.cycleid = cycleid;
1290 vstate.npendingpages = 0;
1423 void *callback_state =
vstate->callback_state;
1472 errmsg_internal(
"right sibling %u of scanblkno %u unexpectedly in an inconsistent state in index \"%s\"",
1553 if (
vstate->cycleid != 0 &&
1569 for (offnum = minoff;
1668 if (
vstate->cycleid != 0 &&
1691 if (minoff > maxoff)
1764 for (
int i = 0;
i < nitem;
i++)
void pgstat_progress_update_param(int index, int64 val)
#define InvalidBlockNumber
static bool BlockNumberIsValid(BlockNumber blockNumber)
static Datum values[MAXATTR]
void IncrBufferRefCount(Buffer buffer)
BlockNumber BufferGetBlockNumber(Buffer buffer)
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
#define RelationGetNumberOfBlocks(reln)
static Page BufferGetPage(Buffer buffer)
static bool BufferIsValid(Buffer bufnum)
static bool PageIsNew(const PageData *page)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static void * PageGetItem(PageData *page, const ItemIdData *itemId)
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 OffsetToPointer(base, offset)
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
bool ConditionVariableCancelSleep(void)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariableInit(ConditionVariable *cv)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
void ConditionVariableSignal(ConditionVariable *cv)
Datum datumRestore(char **start_address, bool *isnull)
void datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, char **start_address)
Size datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)
int errmsg_internal(const char *fmt,...)
int errcode(int sqlerrcode)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_object(type)
#define PG_RETURN_POINTER(x)
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
void IndexFreeSpaceMapVacuum(Relation rel)
void RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
#define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
IndexTupleData * IndexTuple
#define MaxIndexTuplesPerPage
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void LWLockInitialize(LWLock *lock, int tranche_id)
void MemoryContextReset(MemoryContext context)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
bool _bt_doinsert(Relation rel, IndexTuple itup, IndexUniqueCheck checkUnique, bool indexUnchanged, Relation heapRel)
void _bt_relbuf(Relation rel, Buffer buf)
int _bt_getrootheight(Relation rel)
void _bt_pagedel(Relation rel, Buffer leafbuf, BTVacState *vstate)
void _bt_delitems_vacuum(Relation rel, Buffer buf, OffsetNumber *deletable, int ndeletable, BTVacuumPosting *updatable, int nupdatable)
void _bt_checkpage(Relation rel, Buffer buf)
void _bt_set_cleanup_info(Relation rel, BlockNumber num_delpages)
void _bt_upgradelockbufcleanup(Relation rel, Buffer buf)
void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level, bool allequalimage)
bool _bt_vacuum_needs_cleanup(Relation rel)
void _bt_pendingfsm_finalize(Relation rel, BTVacState *vstate)
void _bt_lockbuf(Relation rel, Buffer buf, int access)
void _bt_pendingfsm_init(Relation rel, BTVacState *vstate, bool cleanuponly)
void _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir)
void _bt_parallel_primscan_schedule(IndexScanDesc scan, BlockNumber curr_page)
bool btcanreturn(Relation index, int attno)
@ BTPARALLEL_NEED_PRIMSCAN
@ BTPARALLEL_NOT_INITIALIZED
bool _bt_parallel_seize(IndexScanDesc scan, BlockNumber *next_scan_page, BlockNumber *last_curr_page, bool first)
StrategyNumber bttranslatecmptype(CompareType cmptype, Oid opfamily)
IndexScanDesc btbeginscan(Relation rel, int nkeys, int norderbys)
static bool _bt_start_prim_scan(IndexScanDesc scan)
static BlockNumber btvacuumpage(BTVacState *vstate, Buffer buf)
Size btestimateparallelscan(Relation rel, int nkeys, int norderbys)
void _bt_parallel_done(IndexScanDesc scan)
IndexBulkDeleteResult * btvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
static BTVacuumPosting btreevacuumposting(BTVacState *vstate, IndexTuple posting, OffsetNumber updatedoffset, int *nremaining)
CompareType bttranslatestrategy(StrategyNumber strategy, Oid opfamily)
bool btgettuple(IndexScanDesc scan, ScanDirection dir)
void btparallelrescan(IndexScanDesc scan)
bool btinsert(Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
void btbuildempty(Relation index)
int btgettreeheight(Relation rel)
void btinitparallelscan(void *target)
IndexBulkDeleteResult * btbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
static void btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state, BTCycleId cycleid)
static void _bt_parallel_serialize_arrays(Relation rel, BTParallelScanDesc btscan, BTScanOpaque so)
int64 btgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
void btmarkpos(IndexScanDesc scan)
void btendscan(IndexScanDesc scan)
void btrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
struct BTParallelScanDescData * BTParallelScanDesc
void _bt_parallel_release(IndexScanDesc scan, BlockNumber next_scan_page, BlockNumber curr_page)
Datum bthandler(PG_FUNCTION_ARGS)
void btrestrpos(IndexScanDesc scan)
static void _bt_parallel_restore_arrays(Relation rel, BTParallelScanDesc btscan, BTScanOpaque so)
#define P_ISHALFDEAD(opaque)
#define BTScanPosIsPinned(scanpos)
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
static bool BTreeTupleIsPivot(IndexTuple itup)
#define BTPageGetOpaque(page)
#define P_ISDELETED(opaque)
static ItemPointer BTreeTupleGetPosting(IndexTuple posting)
#define MaxTIDsPerBTreePage
#define BTScanPosIsValid(scanpos)
#define P_FIRSTDATAKEY(opaque)
#define P_RIGHTMOST(opaque)
static bool BTPageIsRecyclable(Page page, Relation heaprel)
static bool BTreeTupleIsPosting(IndexTuple itup)
#define BTScanPosInvalidate(scanpos)
#define BTScanPosUnpinIfPinned(scanpos)
BTScanOpaqueData * BTScanOpaque
bool _bt_first(IndexScanDesc scan, ScanDirection dir)
bool _bt_next(IndexScanDesc scan, ScanDirection dir)
IndexBuildResult * btbuild(Relation heap, Relation index, IndexInfo *indexInfo)
void _bt_end_vacuum(Relation rel)
void _bt_end_vacuum_callback(int code, Datum arg)
void _bt_killitems(IndexScanDesc scan)
char * btbuildphasename(int64 phasenum)
bytea * btoptions(Datum reloptions, bool validate)
bool btproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
bool _bt_allequalimage(Relation rel, bool debugmessage)
BTCycleId _bt_start_vacuum(Relation rel)
bool btvalidate(Oid opclassoid)
void btadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)
#define OffsetNumberNext(offsetNumber)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static char buf[DEFAULT_XLOG_SEG_SIZE]
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
#define PROGRESS_SCAN_BLOCKS_DONE
#define PROGRESS_SCAN_BLOCKS_TOTAL
void read_stream_reset(ReadStream *stream)
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
void read_stream_end(ReadStream *stream)
BlockNumber block_range_read_stream_cb(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
#define READ_STREAM_MAINTENANCE
#define READ_STREAM_USE_BATCHING
#define RELATION_IS_LOCAL(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
void btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Size add_size(Size s1, Size s2)
#define IsMVCCSnapshot(snapshot)
#define BTGreaterStrategyNumber
#define BTMaxStrategyNumber
#define BTLessStrategyNumber
#define BTEqualStrategyNumber
#define BTLessEqualStrategyNumber
#define BTGreaterEqualStrategyNumber
BTPS_State btps_pageStatus
BlockNumber btps_lastCurrPage
ConditionVariable btps_cv
BlockNumber btps_nextScanPage
int btps_arrElems[FLEXIBLE_ARRAY_MEMBER]
BlockNumber last_exclusive
BlockNumber current_blocknum
BlockNumber pages_deleted
struct ScanKeyData * keyData
struct ParallelIndexScanDescData * parallel_scan
struct TupleDescData * xs_itupdesc
ItemPointerData xs_heaptid
struct SnapshotData * xs_snapshot
BufferAccessStrategy strategy
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
void tbm_add_tuples(TIDBitmap *tbm, const ItemPointerData *tids, int ntids, bool recheck)
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
void vacuum_delay_point(bool is_analyze)
#define VACUUM_OPTION_PARALLEL_BULKDEL
#define VACUUM_OPTION_PARALLEL_COND_CLEANUP