59 const Datum *bdist,
const bool *bnulls,
64 Datum *orderbyvals,
bool *orderbynulls);
160 Datum *lastfetched_vals;
161 bool *lastfetched_nulls;
248 goto next_indextuple;
273 elog(
ERROR,
"index returned tuples in wrong order");
374 const Datum *bdist,
const bool *bnulls,
389 if (anulls[i] && !bnulls[i])
391 else if (!anulls[i] && bnulls[i])
393 else if (anulls[i] && bnulls[i])
396 result = ssup->
comparator(adist[i], bdist[i], ssup);
426 Datum *orderbyvals,
bool *orderbynulls)
442 if (!orderbynulls[i])
467 result = topmost->
htup;
567 for (j = 0; j < numRuntimeKeys; j++)
602 if (runtimeKeys[j].key_toastable)
631 for (j = 0; j < numArrayKeys; j++)
661 &elmlen, &elmbyval, &elmalign);
664 elmlen, elmbyval, elmalign,
665 &elem_values, &elem_nulls, &num_elems);
712 for (j = numArrayKeys - 1; j >= 0; j--)
720 if (next_elem >= num_elems)
728 if (elem_nulls[next_elem])
779 if (indexRelationDesc)
961 palloc(numOrderByKeys *
sizeof(
bool));
983 palloc(numOrderByKeys *
sizeof(
bool));
1095 List *quals,
bool isorderby,
1096 ScanKey *scanKeys,
int *numScanKeys,
1106 int max_runtime_keys;
1121 runtime_keys = *runtimeKeys;
1122 n_runtime_keys = max_runtime_keys = *numRuntimeKeys;
1134 foreach(qual_cell, quals)
1137 ScanKey this_scan_key = &scan_keys[j++];
1154 opno = ((
OpExpr *) clause)->opno;
1155 opfuncid = ((
OpExpr *) clause)->opfuncid;
1167 if (!(
IsA(leftop,
Var) &&
1169 elog(
ERROR,
"indexqual doesn't have key on left side");
1171 varattno = ((
Var *) leftop)->varattno;
1172 if (varattno < 1 || varattno > index->
rd_index->indnatts)
1173 elog(
ERROR,
"bogus index qualification");
1202 scanvalue = ((
Const *) rightop)->constvalue;
1203 if (((
Const *) rightop)->constisnull)
1209 if (n_runtime_keys >= max_runtime_keys)
1211 if (max_runtime_keys == 0)
1213 max_runtime_keys = 8;
1219 max_runtime_keys *= 2;
1224 runtime_keys[n_runtime_keys].
scan_key = this_scan_key;
1225 runtime_keys[n_runtime_keys].
key_expr =
1230 scanvalue = (
Datum) 0;
1241 ((
OpExpr *) clause)->inputcollid,
1263 while (opnos_cell !=
NULL)
1265 ScanKey this_sub_key = &first_sub_key[n_sub_key];
1274 largs_cell =
lnext(largs_cell);
1281 if (!(
IsA(leftop,
Var) &&
1283 elog(
ERROR,
"indexqual doesn't have key on left side");
1285 varattno = ((
Var *) leftop)->varattno;
1292 opnos_cell =
lnext(opnos_cell);
1295 varattno < 1 || varattno > index->
rd_index->indnatts)
1296 elog(
ERROR,
"bogus RowCompare index qualification");
1304 if (op_strategy != rc->
rctype)
1305 elog(
ERROR,
"RowCompare index qualification contains wrong operator");
1313 collids_cell =
lnext(collids_cell);
1319 rargs_cell =
lnext(rargs_cell);
1329 scanvalue = ((
Const *) rightop)->constvalue;
1330 if (((
Const *) rightop)->constisnull)
1336 if (n_runtime_keys >= max_runtime_keys)
1338 if (max_runtime_keys == 0)
1340 max_runtime_keys = 8;
1346 max_runtime_keys *= 2;
1351 runtime_keys[n_runtime_keys].
scan_key = this_sub_key;
1352 runtime_keys[n_runtime_keys].
key_expr =
1357 scanvalue = (
Datum) 0;
1411 if (!(
IsA(leftop,
Var) &&
1413 elog(
ERROR,
"indexqual doesn't have key on left side");
1415 varattno = ((
Var *) leftop)->varattno;
1416 if (varattno < 1 || varattno > index->
rd_index->indnatts)
1417 elog(
ERROR,
"bogus index qualification");
1447 scanvalue = ((
Const *) rightop)->constvalue;
1448 if (((
Const *) rightop)->constisnull)
1454 if (n_runtime_keys >= max_runtime_keys)
1456 if (max_runtime_keys == 0)
1458 max_runtime_keys = 8;
1464 max_runtime_keys *= 2;
1469 runtime_keys[n_runtime_keys].
scan_key = this_scan_key;
1470 runtime_keys[n_runtime_keys].
key_expr =
1481 scanvalue = (
Datum) 0;
1487 array_keys[n_array_keys].
scan_key = this_scan_key;
1492 scanvalue = (
Datum) 0;
1518 leftop = ntest->
arg;
1525 if (!(
IsA(leftop,
Var) &&
1527 elog(
ERROR,
"NullTest indexqual has wrong key");
1529 varattno = ((
Var *) leftop)->varattno;
1543 elog(
ERROR,
"unrecognized nulltesttype: %d",
1559 elog(
ERROR,
"unsupported indexqual type: %d",
1563 Assert(n_runtime_keys <= max_runtime_keys);
1566 if (n_array_keys == 0)
1575 *scanKeys = scan_keys;
1576 *numScanKeys = n_scan_keys;
1577 *runtimeKeys = runtime_keys;
1578 *numRuntimeKeys = n_runtime_keys;
1581 *arrayKeys = array_keys;
1582 *numArrayKeys = n_array_keys;
1584 else if (n_array_keys != 0)
1585 elog(
ERROR,
"ScalarArrayOpExpr index qual found where not allowed");
int(* comparator)(Datum x, Datum y, SortSupport ssup)
HeapTuple heap_copytuple(HeapTuple tuple)
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
pairingheap_node * pairingheap_first(pairingheap *heap)
#define IsA(nodeptr, _type_)
#define forboth(cell1, list1, cell2, list2)
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
void ExecEndIndexScan(IndexScanState *node)
static int cmp_orderbyvals(const Datum *adist, const bool *anulls, const Datum *bdist, const bool *bnulls, IndexScanState *node)
#define ScanDirectionIsForward(direction)
static bool IndexRecheck(IndexScanState *node, TupleTableSlot *slot)
#define RelationGetDescr(relation)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
IndexRuntimeKeyInfo * iss_RuntimeKeys
#define PointerGetDatum(X)
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
void index_markpos(IndexScanDesc scan)
int16 * iss_OrderByTypLens
ExprContext * ps_ExprContext
bool ExecIndexAdvanceArrayKeys(IndexArrayKeyInfo *arrayKeys, int numArrayKeys)
SortSupport iss_SortSupport
MemoryContext ecxt_per_tuple_memory
void ExecReScan(PlanState *node)
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
static void reorderqueue_push(IndexScanState *node, HeapTuple tuple, Datum *orderbyvals, bool *orderbynulls)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define pairingheap_is_empty(h)
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
#define MemSet(start, val, len)
pairingheap * pairingheap_allocate(pairingheap_comparator compare, void *arg)
TupleTableSlot * ss_ScanTupleSlot
Relation ss_currentRelation
struct ScanKeyData ScanKeyData
struct IndexAmRoutine * rd_amroutine
void ExecFreeExprContext(PlanState *planstate)
ScanDirection es_direction
void ExecAssignResultTypeFromTL(PlanState *planstate)
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
bool ExecIndexEvalArrayKeys(ExprContext *econtext, IndexArrayKeyInfo *arrayKeys, int numArrayKeys)
void index_restrpos(IndexScanDesc scan)
#define ScanDirectionIsBackward(direction)
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
TupleTableSlot * ExecIndexScan(IndexScanState *node)
TupleTableSlot * ps_ResultTupleSlot
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
void pfree(void *pointer)
MemoryContext es_query_cxt
IndexScanState * ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
void ExecAssignScanProjectionInfo(ScanState *node)
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Node * get_leftop(const Expr *clause)
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
StrategyNumber sk_strategy
void ScanKeyEntryInitialize(ScanKey entry, int flags, AttrNumber attributeNumber, StrategyNumber strategy, Oid subtype, Oid collation, RegProcedure procedure, Datum argument)
void ExecIndexMarkPos(IndexScanState *node)
void ExecReScanIndexScan(IndexScanState *node)
bool * iss_OrderByTypByVals
static int reorderqueue_cmp(const pairingheap_node *a, const pairingheap_node *b, void *arg)
bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull)
static ListCell * list_head(const List *l)
bool iss_RuntimeKeysReady
static void EvalOrderByExpressions(IndexScanState *node, ExprContext *econtext)
void index_endscan(IndexScanDesc scan)
Datum datumCopy(Datum value, bool typByVal, int typLen)
void * palloc0(Size size)
void FreeExprContext(ExprContext *econtext, bool isCommit)
NullTestType nulltesttype
static TupleTableSlot * IndexNext(IndexScanState *node)
static TupleTableSlot * IndexNextWithReorder(IndexScanState *node)
#define Assert(condition)
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
#define InstrCountFiltered2(node, delta)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Oid exprType(const Node *expr)
void ExecIndexBuildScanKeys(PlanState *planstate, Relation index, List *quals, bool isorderby, ScanKey *scanKeys, int *numScanKeys, IndexRuntimeKeyInfo **runtimeKeys, int *numRuntimeKeys, IndexArrayKeyInfo **arrayKeys, int *numArrayKeys)
static HeapTuple reorderqueue_pop(IndexScanState *node)
static int list_length(const List *l)
void ExecCloseScanRelation(Relation scanrel)
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
TupleTableSlot * ecxt_scantuple
ExprContext * iss_RuntimeContext
void ExecIndexRestrPos(IndexScanState *node)
void * repalloc(void *pointer, Size size)
void ExecIndexEvalRuntimeKeys(ExprContext *econtext, IndexRuntimeKeyInfo *runtimeKeys, int numRuntimeKeys)
Node * get_rightop(const Expr *clause)
void index_close(Relation relation, LOCKMODE lockmode)
#define DatumGetPointer(X)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
HeapScanDesc ss_currentScanDesc
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
void ExecScanReScan(ScanState *node)
pairingheap_node * pairingheap_remove_first(pairingheap *heap)
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
#define PG_DETOAST_DATUM(datum)
void pairingheap_add(pairingheap *heap, pairingheap_node *node)
Datum * iss_OrderByValues
IndexScanDesc iss_ScanDesc
#define TypeIsToastable(typid)
#define EXEC_FLAG_EXPLAIN_ONLY
Relation index_open(Oid relationId, LOCKMODE lockmode)
bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid)
HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction)
#define ResetExprContext(econtext)
Relation iss_RelationDesc
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
pairingheap * iss_ReorderQueue
static int cmp(const chr *x, const chr *y, size_t len)
#define ExecEvalExpr(expr, econtext, isNull, isDone)
#define DatumGetArrayTypeP(X)