79 bool *continuescan,
int *
ikey);
82 ScanDirection dir,
bool forcenonrequired,
bool *continuescan);
108#ifdef USE_ASSERT_CHECKING
156 pstate.
dir =
so->currPos.dir = dir;
157 so->currPos.nextTupleOffset = 0;
161 so->currPos.moreLeft);
168 arrayKeys =
so->numArrayKeys != 0;
192 so->currPos.currPage);
195 so->currPos.currPage);
215 so->currPos.moreRight =
false;
216 so->needPrimScan =
true;
219 so->currPos.currPage);
224 so->scanBehind =
so->oppositeDirCheck =
false;
231 if (!pstate.
firstpage && minoff < maxoff)
237 offnum =
Max(offnum, minoff);
239 while (offnum <= maxoff)
272 offnum = pstate.
skip;
342 so->currPos.moreRight =
false;
345 so->currPos.firstItem = 0;
346 so->currPos.lastItem = itemIndex - 1;
347 so->currPos.itemIndex = 0;
364 so->currPos.moreLeft =
false;
365 so->needPrimScan =
true;
368 so->currPos.currPage);
373 so->scanBehind =
so->oppositeDirCheck =
false;
380 if (!pstate.
firstpage && minoff < maxoff)
386 offnum =
Min(offnum, maxoff);
388 while (offnum >= minoff)
432 if (arrayKeys &&
so->scanBehind)
457 offnum = pstate.
skip;
505 so->currPos.moreLeft =
false;
508 so->currPos.firstItem = itemIndex;
527 return (
so->currPos.firstItem <=
so->currPos.lastItem);
545 for (
int i = 0;
i <
so->numArrayKeys;
i++)
555 so->scanBehind =
so->oppositeDirCheck =
false;
614 if (
so->numberOfKeys == 0)
628 for (; startikey <
so->numberOfKeys; startikey++)
784 key->sk_collation, lastdatum,
832 array = &
so->arrayKeys[arrayidx++];
982 if (!
so->oppositeDirCheck)
1021 false, &continuescan,
1045 currItem->tupleOffset =
so->currPos.nextTupleOffset;
1078 currItem->tupleOffset =
so->currPos.nextTupleOffset;
1079 base = (
IndexTuple) (
so->currTuples +
so->currPos.nextTupleOffset);
1084 so->currPos.nextTupleOffset +=
itupsz;
1113 currItem->tupleOffset = tupleOffset;
1116#define LOOK_AHEAD_REQUIRED_RECHECKS 3
1117#define LOOK_AHEAD_DEFAULT_DISTANCE 5
1118#define NSKIPADVANCES_THRESHOLD 3
1159 Assert(!
so->needPrimScan && !
so->scanBehind && !
so->oppositeDirCheck);
1160 Assert(arrayKeys ||
so->numArrayKeys == 0);
1174#ifdef USE_ASSERT_CHECKING
1315 bool *continuescan,
int *
ikey)
1319 *continuescan =
true;
1321 for (; *
ikey <
so->numberOfKeys; (*ikey)++)
1334 if (forcenonrequired)
1373 if (forcenonrequired)
1375 tupdesc, *
ikey,
false);
1377 *continuescan =
false;
1385 forcenonrequired, continuescan))
1417 *continuescan =
false;
1447 tupdesc, *
ikey,
false);
1465 *continuescan =
false;
1483 *continuescan =
false;
1493 datum, key->sk_argument)))
1501 *continuescan =
false;
1513 tupdesc, *
ikey,
false);
1581 bool forcenonrequired,
bool *continuescan)
1612 if (forcenonrequired)
1618 *continuescan =
false;
1621 *continuescan =
false;
1646 if (forcenonrequired)
1686 *continuescan =
false;
1724 *continuescan =
false;
1754 if (!result && !forcenonrequired)
1764 *continuescan =
false;
1767 *continuescan =
false;
1787 switch (
subkey->sk_strategy)
1866 *scanBehind =
false;
1977 for (
int arrayidx = 0; arrayidx <
so->numArrayKeys; arrayidx++)
1979 array = &
so->arrayKeys[arrayidx];
1985 array,
cur, &result);
2196 Assert(!
so->needPrimScan && !
so->scanBehind && !
so->oppositeDirCheck);
2230 false, &continuescan,
2240 bool required =
false,
2250 array = &
so->arrayKeys[arrayidx++];
2279 so->scanBehind =
true;
2331 else if (!required && !array)
2659 false, 0, &
so->scanBehind))
2750 so->needPrimScan =
false;
2813 so->scanBehind =
true;
2828 so->needPrimScan =
true;
2849 so->needPrimScan =
false;
2879 for (
int i =
so->numArrayKeys - 1;
i >= 0;
i--)
3461 if (high_elem >= low_elem)
3477 if (high_elem < low_elem)
3489 if (high_elem >= low_elem)
3505 if (high_elem < low_elem)
3514 while (high_elem > low_elem)
3516 mid_elem = low_elem + ((high_elem - low_elem) / 2);
3647#ifdef USE_ASSERT_CHECKING
3665#ifdef USE_ASSERT_CHECKING
3690 array = &
so->arrayKeys[arrayidx++];
3713 if (arrayidx !=
so->numArrayKeys)
#define InvalidAttrNumber
BlockNumber BufferGetBlockNumber(Buffer buffer)
static Page BufferGetPage(Buffer buffer)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static void * PageGetItem(PageData *page, const ItemIdData *itemId)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
#define INVERT_COMPARE_RESULT(var)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
Datum datumCopy(Datum value, bool typByVal, int typLen)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
#define ItemIdIsDead(itemId)
IndexTupleData * IndexTuple
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static Size IndexTupleSize(const IndexTupleData *itup)
#define MaxIndexTuplesPerPage
void pfree(void *pointer)
static void _bt_binsrch_skiparray_skey(bool cur_elem_trig, ScanDirection dir, Datum tupdatum, bool tupnull, BTArrayKeyInfo *array, ScanKey cur, int32 *set_elem_result)
static void _bt_array_set_low_or_high(Relation rel, ScanKey skey, BTArrayKeyInfo *array, bool low_not_high)
static void _bt_saveitem(BTScanOpaque so, int itemIndex, OffsetNumber offnum, IndexTuple itup)
static void _bt_skiparray_set_element(Relation rel, ScanKey skey, BTArrayKeyInfo *array, int32 set_elem_result, Datum tupdatum, bool tupnull)
#define NSKIPADVANCES_THRESHOLD
int _bt_binsrch_array_skey(FmgrInfo *orderproc, bool cur_elem_trig, ScanDirection dir, Datum tupdatum, bool tupnull, BTArrayKeyInfo *array, ScanKey cur, int32 *set_elem_result)
static int _bt_setuppostingitems(BTScanOpaque so, int itemIndex, OffsetNumber offnum, const ItemPointerData *heapTid, IndexTuple itup)
static bool _bt_advance_array_keys(IndexScanDesc scan, BTReadPageState *pstate, IndexTuple tuple, int tupnatts, TupleDesc tupdesc, int sktrig, bool sktrig_required)
#define LOOK_AHEAD_REQUIRED_RECHECKS
static bool _bt_rowcompare_cmpresult(ScanKey subkey, int cmpresult)
static bool _bt_oppodir_checkkeys(IndexScanDesc scan, ScanDirection dir, IndexTuple finaltup)
static bool _bt_scanbehind_checkkeys(IndexScanDesc scan, ScanDirection dir, IndexTuple finaltup)
#define LOOK_AHEAD_DEFAULT_DISTANCE
static bool _bt_check_rowcompare(ScanKey header, IndexTuple tuple, int tupnatts, TupleDesc tupdesc, ScanDirection dir, bool forcenonrequired, bool *continuescan)
static void _bt_savepostingitem(BTScanOpaque so, int itemIndex, OffsetNumber offnum, ItemPointer heapTid, int tupleOffset)
static bool _bt_check_compare(IndexScanDesc scan, ScanDirection dir, IndexTuple tuple, int tupnatts, TupleDesc tupdesc, bool advancenonrequired, bool forcenonrequired, bool *continuescan, int *ikey)
bool _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum, bool firstpage)
static bool _bt_array_decrement(Relation rel, ScanKey skey, BTArrayKeyInfo *array)
static bool _bt_tuple_before_array_skeys(IndexScanDesc scan, ScanDirection dir, IndexTuple tuple, TupleDesc tupdesc, int tupnatts, bool readpagetup, int sktrig, bool *scanBehind)
static void _bt_set_startikey(IndexScanDesc scan, BTReadPageState *pstate)
static void _bt_skiparray_set_isnull(Relation rel, ScanKey skey, BTArrayKeyInfo *array)
static bool _bt_advance_array_keys_increment(IndexScanDesc scan, ScanDirection dir, bool *skip_array_set)
static void _bt_checkkeys_look_ahead(IndexScanDesc scan, BTReadPageState *pstate, int tupnatts, TupleDesc tupdesc)
static int32 _bt_compare_array_skey(FmgrInfo *orderproc, Datum tupdatum, bool tupnull, Datum arrdatum, ScanKey cur)
void _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir)
static bool _bt_checkkeys(IndexScanDesc scan, BTReadPageState *pstate, bool arrayKeys, IndexTuple tuple, int tupnatts)
static bool _bt_array_increment(Relation rel, ScanKey skey, BTArrayKeyInfo *array)
void _bt_parallel_primscan_schedule(IndexScanDesc scan, BlockNumber curr_page)
void _bt_parallel_release(IndexScanDesc scan, BlockNumber next_scan_page, BlockNumber curr_page)
#define BTScanPosIsPinned(scanpos)
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
static bool BTreeTupleIsPivot(IndexTuple itup)
#define P_LEFTMOST(opaque)
#define BTPageGetOpaque(page)
#define MaxTIDsPerBTreePage
#define P_FIRSTDATAKEY(opaque)
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
#define P_RIGHTMOST(opaque)
#define SK_BT_NULLS_FIRST
static ItemPointer BTreeTupleGetPostingN(IndexTuple posting, int n)
static bool BTreeTupleIsPosting(IndexTuple itup)
#define BTreeTupleGetNAtts(itup, rel)
BTScanOpaqueData * BTScanOpaque
int _bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
#define InvalidOffsetNumber
#define OffsetNumberIsValid(offsetNumber)
#define OffsetNumberNext(offsetNumber)
#define OffsetNumberPrev(offsetNumber)
static bool DatumGetBool(Datum X)
static Pointer DatumGetPointer(Datum X)
static int32 DatumGetInt32(Datum X)
void PredicateLockPage(Relation relation, BlockNumber blkno, Snapshot snapshot)
#define RelationGetDescr(relation)
#define IndexRelationGetNumberOfAttributes(relation)
#define ScanDirectionIsForward(direction)
#define ScanDirectionIsBackward(direction)
#define ScanDirectionIsNoMovement(direction)
@ NoMovementScanDirection
#define BTGreaterStrategyNumber
#define BTLessStrategyNumber
#define BTEqualStrategyNumber
#define BTLessEqualStrategyNumber
#define BTGreaterEqualStrategyNumber
struct ParallelIndexScanDescData * parallel_scan
bool ignore_killed_tuples
struct SnapshotData * xs_snapshot
StrategyNumber sk_strategy
SkipSupportIncDec decrement
SkipSupportIncDec increment