PostgreSQL Source Code  git master
nodeIndexscan.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * nodeIndexscan.c
4  * Routines to support indexed scans of relations
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/executor/nodeIndexscan.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 /*
16  * INTERFACE ROUTINES
17  * ExecIndexScan scans a relation using an index
18  * IndexNext retrieve next tuple using index
19  * IndexNextWithReorder same, but recheck ORDER BY expressions
20  * ExecInitIndexScan creates and initializes state info.
21  * ExecReScanIndexScan rescans the indexed relation.
22  * ExecEndIndexScan releases all storage.
23  * ExecIndexMarkPos marks scan position.
24  * ExecIndexRestrPos restores scan position.
25  * ExecIndexScanEstimate estimates DSM space needed for parallel index scan
26  * ExecIndexScanInitializeDSM initialize DSM for parallel indexscan
27  * ExecIndexScanReInitializeDSM reinitialize DSM for fresh scan
28  * ExecIndexScanInitializeWorker attach to DSM info in parallel worker
29  */
30 #include "postgres.h"
31 
32 #include "access/nbtree.h"
33 #include "access/relscan.h"
34 #include "access/tableam.h"
35 #include "catalog/pg_am.h"
36 #include "executor/execdebug.h"
37 #include "executor/nodeIndexscan.h"
38 #include "lib/pairingheap.h"
39 #include "miscadmin.h"
40 #include "nodes/nodeFuncs.h"
41 #include "utils/array.h"
42 #include "utils/datum.h"
43 #include "utils/lsyscache.h"
44 #include "utils/memutils.h"
45 #include "utils/rel.h"
46 
47 /*
48  * When an ordering operator is used, tuples fetched from the index that
49  * need to be reordered are queued in a pairing heap, as ReorderTuples.
50  */
51 typedef struct
52 {
56  bool *orderbynulls;
57 } ReorderTuple;
58 
61 static void EvalOrderByExpressions(IndexScanState *node, ExprContext *econtext);
62 static bool IndexRecheck(IndexScanState *node, TupleTableSlot *slot);
63 static int cmp_orderbyvals(const Datum *adist, const bool *anulls,
64  const Datum *bdist, const bool *bnulls,
65  IndexScanState *node);
66 static int reorderqueue_cmp(const pairingheap_node *a,
67  const pairingheap_node *b, void *arg);
68 static void reorderqueue_push(IndexScanState *node, TupleTableSlot *slot,
69  Datum *orderbyvals, bool *orderbynulls);
71 
72 
73 /* ----------------------------------------------------------------
74  * IndexNext
75  *
76  * Retrieve a tuple from the IndexScan node's currentRelation
77  * using the index specified in the IndexScanState information.
78  * ----------------------------------------------------------------
79  */
80 static TupleTableSlot *
82 {
83  EState *estate;
84  ExprContext *econtext;
85  ScanDirection direction;
86  IndexScanDesc scandesc;
87  TupleTableSlot *slot;
88 
89  /*
90  * extract necessary information from index scan node
91  */
92  estate = node->ss.ps.state;
93  direction = estate->es_direction;
94  /* flip direction if this is an overall backward scan */
95  if (ScanDirectionIsBackward(((IndexScan *) node->ss.ps.plan)->indexorderdir))
96  {
97  if (ScanDirectionIsForward(direction))
98  direction = BackwardScanDirection;
99  else if (ScanDirectionIsBackward(direction))
100  direction = ForwardScanDirection;
101  }
102  scandesc = node->iss_ScanDesc;
103  econtext = node->ss.ps.ps_ExprContext;
104  slot = node->ss.ss_ScanTupleSlot;
105 
106  if (scandesc == NULL)
107  {
108  /*
109  * We reach here if the index scan is not parallel, or if we're
110  * serially executing an index scan that was planned to be parallel.
111  */
112  scandesc = index_beginscan(node->ss.ss_currentRelation,
113  node->iss_RelationDesc,
114  estate->es_snapshot,
115  node->iss_NumScanKeys,
116  node->iss_NumOrderByKeys);
117 
118  node->iss_ScanDesc = scandesc;
119 
120  /*
121  * If no run-time keys to calculate or they are ready, go ahead and
122  * pass the scankeys to the index AM.
123  */
124  if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady)
125  index_rescan(scandesc,
126  node->iss_ScanKeys, node->iss_NumScanKeys,
127  node->iss_OrderByKeys, node->iss_NumOrderByKeys);
128  }
129 
130  /*
131  * ok, now that we have what we need, fetch the next tuple.
132  */
133  while (index_getnext_slot(scandesc, direction, slot))
134  {
136 
137  /*
138  * If the index was lossy, we have to recheck the index quals using
139  * the fetched tuple.
140  */
141  if (scandesc->xs_recheck)
142  {
143  econtext->ecxt_scantuple = slot;
144  if (!ExecQualAndReset(node->indexqualorig, econtext))
145  {
146  /* Fails recheck, so drop it and loop back for another */
147  InstrCountFiltered2(node, 1);
148  continue;
149  }
150  }
151 
152  return slot;
153  }
154 
155  /*
156  * if we get here it means the index scan failed so we are at the end of
157  * the scan..
158  */
159  node->iss_ReachedEnd = true;
160  return ExecClearTuple(slot);
161 }
162 
163 /* ----------------------------------------------------------------
164  * IndexNextWithReorder
165  *
166  * Like IndexNext, but this version can also re-check ORDER BY
167  * expressions, and reorder the tuples as necessary.
168  * ----------------------------------------------------------------
169  */
170 static TupleTableSlot *
172 {
173  EState *estate;
174  ExprContext *econtext;
175  IndexScanDesc scandesc;
176  TupleTableSlot *slot;
177  ReorderTuple *topmost = NULL;
178  bool was_exact;
179  Datum *lastfetched_vals;
180  bool *lastfetched_nulls;
181  int cmp;
182 
183  estate = node->ss.ps.state;
184 
185  /*
186  * Only forward scan is supported with reordering. Note: we can get away
187  * with just Asserting here because the system will not try to run the
188  * plan backwards if ExecSupportsBackwardScan() says it won't work.
189  * Currently, that is guaranteed because no index AMs support both
190  * amcanorderbyop and amcanbackward; if any ever do,
191  * ExecSupportsBackwardScan() will need to consider indexorderbys
192  * explicitly.
193  */
194  Assert(!ScanDirectionIsBackward(((IndexScan *) node->ss.ps.plan)->indexorderdir));
196 
197  scandesc = node->iss_ScanDesc;
198  econtext = node->ss.ps.ps_ExprContext;
199  slot = node->ss.ss_ScanTupleSlot;
200 
201  if (scandesc == NULL)
202  {
203  /*
204  * We reach here if the index scan is not parallel, or if we're
205  * serially executing an index scan that was planned to be parallel.
206  */
207  scandesc = index_beginscan(node->ss.ss_currentRelation,
208  node->iss_RelationDesc,
209  estate->es_snapshot,
210  node->iss_NumScanKeys,
211  node->iss_NumOrderByKeys);
212 
213  node->iss_ScanDesc = scandesc;
214 
215  /*
216  * If no run-time keys to calculate or they are ready, go ahead and
217  * pass the scankeys to the index AM.
218  */
219  if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady)
220  index_rescan(scandesc,
221  node->iss_ScanKeys, node->iss_NumScanKeys,
222  node->iss_OrderByKeys, node->iss_NumOrderByKeys);
223  }
224 
225  for (;;)
226  {
228 
229  /*
230  * Check the reorder queue first. If the topmost tuple in the queue
231  * has an ORDER BY value smaller than (or equal to) the value last
232  * returned by the index, we can return it now.
233  */
235  {
236  topmost = (ReorderTuple *) pairingheap_first(node->iss_ReorderQueue);
237 
238  if (node->iss_ReachedEnd ||
239  cmp_orderbyvals(topmost->orderbyvals,
240  topmost->orderbynulls,
241  scandesc->xs_orderbyvals,
242  scandesc->xs_orderbynulls,
243  node) <= 0)
244  {
245  HeapTuple tuple;
246 
247  tuple = reorderqueue_pop(node);
248 
249  /* Pass 'true', as the tuple in the queue is a palloc'd copy */
250  ExecForceStoreHeapTuple(tuple, slot, true);
251  return slot;
252  }
253  }
254  else if (node->iss_ReachedEnd)
255  {
256  /* Queue is empty, and no more tuples from index. We're done. */
257  return ExecClearTuple(slot);
258  }
259 
260  /*
261  * Fetch next tuple from the index.
262  */
263 next_indextuple:
264  if (!index_getnext_slot(scandesc, ForwardScanDirection, slot))
265  {
266  /*
267  * No more tuples from the index. But we still need to drain any
268  * remaining tuples from the queue before we're done.
269  */
270  node->iss_ReachedEnd = true;
271  continue;
272  }
273 
274  /*
275  * If the index was lossy, we have to recheck the index quals and
276  * ORDER BY expressions using the fetched tuple.
277  */
278  if (scandesc->xs_recheck)
279  {
280  econtext->ecxt_scantuple = slot;
281  if (!ExecQualAndReset(node->indexqualorig, econtext))
282  {
283  /* Fails recheck, so drop it and loop back for another */
284  InstrCountFiltered2(node, 1);
285  /* allow this loop to be cancellable */
287  goto next_indextuple;
288  }
289  }
290 
291  if (scandesc->xs_recheckorderby)
292  {
293  econtext->ecxt_scantuple = slot;
294  ResetExprContext(econtext);
295  EvalOrderByExpressions(node, econtext);
296 
297  /*
298  * Was the ORDER BY value returned by the index accurate? The
299  * recheck flag means that the index can return inaccurate values,
300  * but then again, the value returned for any particular tuple
301  * could also be exactly correct. Compare the value returned by
302  * the index with the recalculated value. (If the value returned
303  * by the index happened to be exact right, we can often avoid
304  * pushing the tuple to the queue, just to pop it back out again.)
305  */
307  node->iss_OrderByNulls,
308  scandesc->xs_orderbyvals,
309  scandesc->xs_orderbynulls,
310  node);
311  if (cmp < 0)
312  elog(ERROR, "index returned tuples in wrong order");
313  else if (cmp == 0)
314  was_exact = true;
315  else
316  was_exact = false;
317  lastfetched_vals = node->iss_OrderByValues;
318  lastfetched_nulls = node->iss_OrderByNulls;
319  }
320  else
321  {
322  was_exact = true;
323  lastfetched_vals = scandesc->xs_orderbyvals;
324  lastfetched_nulls = scandesc->xs_orderbynulls;
325  }
326 
327  /*
328  * Can we return this tuple immediately, or does it need to be pushed
329  * to the reorder queue? If the ORDER BY expression values returned
330  * by the index were inaccurate, we can't return it yet, because the
331  * next tuple from the index might need to come before this one. Also,
332  * we can't return it yet if there are any smaller tuples in the queue
333  * already.
334  */
335  if (!was_exact || (topmost && cmp_orderbyvals(lastfetched_vals,
336  lastfetched_nulls,
337  topmost->orderbyvals,
338  topmost->orderbynulls,
339  node) > 0))
340  {
341  /* Put this tuple to the queue */
342  reorderqueue_push(node, slot, lastfetched_vals, lastfetched_nulls);
343  continue;
344  }
345  else
346  {
347  /* Can return this tuple immediately. */
348  return slot;
349  }
350  }
351 
352  /*
353  * if we get here it means the index scan failed so we are at the end of
354  * the scan..
355  */
356  return ExecClearTuple(slot);
357 }
358 
359 /*
360  * Calculate the expressions in the ORDER BY clause, based on the heap tuple.
361  */
362 static void
364 {
365  int i;
366  ListCell *l;
367  MemoryContext oldContext;
368 
369  oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
370 
371  i = 0;
372  foreach(l, node->indexorderbyorig)
373  {
374  ExprState *orderby = (ExprState *) lfirst(l);
375 
376  node->iss_OrderByValues[i] = ExecEvalExpr(orderby,
377  econtext,
378  &node->iss_OrderByNulls[i]);
379  i++;
380  }
381 
382  MemoryContextSwitchTo(oldContext);
383 }
384 
385 /*
386  * IndexRecheck -- access method routine to recheck a tuple in EvalPlanQual
387  */
388 static bool
390 {
391  ExprContext *econtext;
392 
393  /*
394  * extract necessary information from index scan node
395  */
396  econtext = node->ss.ps.ps_ExprContext;
397 
398  /* Does the tuple meet the indexqual condition? */
399  econtext->ecxt_scantuple = slot;
400  return ExecQualAndReset(node->indexqualorig, econtext);
401 }
402 
403 
404 /*
405  * Compare ORDER BY expression values.
406  */
407 static int
408 cmp_orderbyvals(const Datum *adist, const bool *anulls,
409  const Datum *bdist, const bool *bnulls,
410  IndexScanState *node)
411 {
412  int i;
413  int result;
414 
415  for (i = 0; i < node->iss_NumOrderByKeys; i++)
416  {
417  SortSupport ssup = &node->iss_SortSupport[i];
418 
419  /*
420  * Handle nulls. We only need to support NULLS LAST ordering, because
421  * match_pathkeys_to_index() doesn't consider indexorderby
422  * implementation otherwise.
423  */
424  if (anulls[i] && !bnulls[i])
425  return 1;
426  else if (!anulls[i] && bnulls[i])
427  return -1;
428  else if (anulls[i] && bnulls[i])
429  return 0;
430 
431  result = ssup->comparator(adist[i], bdist[i], ssup);
432  if (result != 0)
433  return result;
434  }
435 
436  return 0;
437 }
438 
439 /*
440  * Pairing heap provides getting topmost (greatest) element while KNN provides
441  * ascending sort. That's why we invert the sort order.
442  */
443 static int
445  void *arg)
446 {
447  ReorderTuple *rta = (ReorderTuple *) a;
448  ReorderTuple *rtb = (ReorderTuple *) b;
449  IndexScanState *node = (IndexScanState *) arg;
450 
451  /* exchange argument order to invert the sort order */
452  return cmp_orderbyvals(rtb->orderbyvals, rtb->orderbynulls,
453  rta->orderbyvals, rta->orderbynulls,
454  node);
455 }
456 
457 /*
458  * Helper function to push a tuple to the reorder queue.
459  */
460 static void
462  Datum *orderbyvals, bool *orderbynulls)
463 {
464  IndexScanDesc scandesc = node->iss_ScanDesc;
465  EState *estate = node->ss.ps.state;
466  MemoryContext oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
467  ReorderTuple *rt;
468  int i;
469 
470  rt = (ReorderTuple *) palloc(sizeof(ReorderTuple));
471  rt->htup = ExecCopySlotHeapTuple(slot);
472  rt->orderbyvals =
473  (Datum *) palloc(sizeof(Datum) * scandesc->numberOfOrderBys);
474  rt->orderbynulls =
475  (bool *) palloc(sizeof(bool) * scandesc->numberOfOrderBys);
476  for (i = 0; i < node->iss_NumOrderByKeys; i++)
477  {
478  if (!orderbynulls[i])
479  rt->orderbyvals[i] = datumCopy(orderbyvals[i],
480  node->iss_OrderByTypByVals[i],
481  node->iss_OrderByTypLens[i]);
482  else
483  rt->orderbyvals[i] = (Datum) 0;
484  rt->orderbynulls[i] = orderbynulls[i];
485  }
487 
488  MemoryContextSwitchTo(oldContext);
489 }
490 
491 /*
492  * Helper function to pop the next tuple from the reorder queue.
493  */
494 static HeapTuple
496 {
497  HeapTuple result;
498  ReorderTuple *topmost;
499  int i;
500 
502 
503  result = topmost->htup;
504  for (i = 0; i < node->iss_NumOrderByKeys; i++)
505  {
506  if (!node->iss_OrderByTypByVals[i] && !topmost->orderbynulls[i])
507  pfree(DatumGetPointer(topmost->orderbyvals[i]));
508  }
509  pfree(topmost->orderbyvals);
510  pfree(topmost->orderbynulls);
511  pfree(topmost);
512 
513  return result;
514 }
515 
516 
517 /* ----------------------------------------------------------------
518  * ExecIndexScan(node)
519  * ----------------------------------------------------------------
520  */
521 static TupleTableSlot *
523 {
524  IndexScanState *node = castNode(IndexScanState, pstate);
525 
526  /*
527  * If we have runtime keys and they've not already been set up, do it now.
528  */
529  if (node->iss_NumRuntimeKeys != 0 && !node->iss_RuntimeKeysReady)
530  ExecReScan((PlanState *) node);
531 
532  if (node->iss_NumOrderByKeys > 0)
533  return ExecScan(&node->ss,
536  else
537  return ExecScan(&node->ss,
540 }
541 
542 /* ----------------------------------------------------------------
543  * ExecReScanIndexScan(node)
544  *
545  * Recalculates the values of any scan keys whose value depends on
546  * information known at runtime, then rescans the indexed relation.
547  *
548  * Updating the scan key was formerly done separately in
549  * ExecUpdateIndexScanKeys. Integrating it into ReScan makes
550  * rescans of indices and relations/general streams more uniform.
551  * ----------------------------------------------------------------
552  */
553 void
555 {
556  /*
557  * If we are doing runtime key calculations (ie, any of the index key
558  * values weren't simple Consts), compute the new key values. But first,
559  * reset the context so we don't leak memory as each outer tuple is
560  * scanned. Note this assumes that we will recalculate *all* runtime keys
561  * on each call.
562  */
563  if (node->iss_NumRuntimeKeys != 0)
564  {
565  ExprContext *econtext = node->iss_RuntimeContext;
566 
567  ResetExprContext(econtext);
568  ExecIndexEvalRuntimeKeys(econtext,
569  node->iss_RuntimeKeys,
570  node->iss_NumRuntimeKeys);
571  }
572  node->iss_RuntimeKeysReady = true;
573 
574  /* flush the reorder queue */
575  if (node->iss_ReorderQueue)
576  {
577  HeapTuple tuple;
578 
579  while (!pairingheap_is_empty(node->iss_ReorderQueue))
580  {
581  tuple = reorderqueue_pop(node);
582  heap_freetuple(tuple);
583  }
584  }
585 
586  /* reset index scan */
587  if (node->iss_ScanDesc)
589  node->iss_ScanKeys, node->iss_NumScanKeys,
590  node->iss_OrderByKeys, node->iss_NumOrderByKeys);
591  node->iss_ReachedEnd = false;
592 
593  ExecScanReScan(&node->ss);
594 }
595 
596 
597 /*
598  * ExecIndexEvalRuntimeKeys
599  * Evaluate any runtime key values, and update the scankeys.
600  */
601 void
603  IndexRuntimeKeyInfo *runtimeKeys, int numRuntimeKeys)
604 {
605  int j;
606  MemoryContext oldContext;
607 
608  /* We want to keep the key values in per-tuple memory */
609  oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
610 
611  for (j = 0; j < numRuntimeKeys; j++)
612  {
613  ScanKey scan_key = runtimeKeys[j].scan_key;
614  ExprState *key_expr = runtimeKeys[j].key_expr;
615  Datum scanvalue;
616  bool isNull;
617 
618  /*
619  * For each run-time key, extract the run-time expression and evaluate
620  * it with respect to the current context. We then stick the result
621  * into the proper scan key.
622  *
623  * Note: the result of the eval could be a pass-by-ref value that's
624  * stored in some outer scan's tuple, not in
625  * econtext->ecxt_per_tuple_memory. We assume that the outer tuple
626  * will stay put throughout our scan. If this is wrong, we could copy
627  * the result into our context explicitly, but I think that's not
628  * necessary.
629  *
630  * It's also entirely possible that the result of the eval is a
631  * toasted value. In this case we should forcibly detoast it, to
632  * avoid repeat detoastings each time the value is examined by an
633  * index support function.
634  */
635  scanvalue = ExecEvalExpr(key_expr,
636  econtext,
637  &isNull);
638  if (isNull)
639  {
640  scan_key->sk_argument = scanvalue;
641  scan_key->sk_flags |= SK_ISNULL;
642  }
643  else
644  {
645  if (runtimeKeys[j].key_toastable)
646  scanvalue = PointerGetDatum(PG_DETOAST_DATUM(scanvalue));
647  scan_key->sk_argument = scanvalue;
648  scan_key->sk_flags &= ~SK_ISNULL;
649  }
650  }
651 
652  MemoryContextSwitchTo(oldContext);
653 }
654 
655 /*
656  * ExecIndexEvalArrayKeys
657  * Evaluate any array key values, and set up to iterate through arrays.
658  *
659  * Returns true if there are array elements to consider; false means there
660  * is at least one null or empty array, so no match is possible. On true
661  * result, the scankeys are initialized with the first elements of the arrays.
662  */
663 bool
665  IndexArrayKeyInfo *arrayKeys, int numArrayKeys)
666 {
667  bool result = true;
668  int j;
669  MemoryContext oldContext;
670 
671  /* We want to keep the arrays in per-tuple memory */
672  oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
673 
674  for (j = 0; j < numArrayKeys; j++)
675  {
676  ScanKey scan_key = arrayKeys[j].scan_key;
677  ExprState *array_expr = arrayKeys[j].array_expr;
678  Datum arraydatum;
679  bool isNull;
680  ArrayType *arrayval;
681  int16 elmlen;
682  bool elmbyval;
683  char elmalign;
684  int num_elems;
685  Datum *elem_values;
686  bool *elem_nulls;
687 
688  /*
689  * Compute and deconstruct the array expression. (Notes in
690  * ExecIndexEvalRuntimeKeys() apply here too.)
691  */
692  arraydatum = ExecEvalExpr(array_expr,
693  econtext,
694  &isNull);
695  if (isNull)
696  {
697  result = false;
698  break; /* no point in evaluating more */
699  }
700  arrayval = DatumGetArrayTypeP(arraydatum);
701  /* We could cache this data, but not clear it's worth it */
703  &elmlen, &elmbyval, &elmalign);
704  deconstruct_array(arrayval,
705  ARR_ELEMTYPE(arrayval),
706  elmlen, elmbyval, elmalign,
707  &elem_values, &elem_nulls, &num_elems);
708  if (num_elems <= 0)
709  {
710  result = false;
711  break; /* no point in evaluating more */
712  }
713 
714  /*
715  * Note: we expect the previous array data, if any, to be
716  * automatically freed by resetting the per-tuple context; hence no
717  * pfree's here.
718  */
719  arrayKeys[j].elem_values = elem_values;
720  arrayKeys[j].elem_nulls = elem_nulls;
721  arrayKeys[j].num_elems = num_elems;
722  scan_key->sk_argument = elem_values[0];
723  if (elem_nulls[0])
724  scan_key->sk_flags |= SK_ISNULL;
725  else
726  scan_key->sk_flags &= ~SK_ISNULL;
727  arrayKeys[j].next_elem = 1;
728  }
729 
730  MemoryContextSwitchTo(oldContext);
731 
732  return result;
733 }
734 
735 /*
736  * ExecIndexAdvanceArrayKeys
737  * Advance to the next set of array key values, if any.
738  *
739  * Returns true if there is another set of values to consider, false if not.
740  * On true result, the scankeys are initialized with the next set of values.
741  */
742 bool
743 ExecIndexAdvanceArrayKeys(IndexArrayKeyInfo *arrayKeys, int numArrayKeys)
744 {
745  bool found = false;
746  int j;
747 
748  /*
749  * Note we advance the rightmost array key most quickly, since it will
750  * correspond to the lowest-order index column among the available
751  * qualifications. This is hypothesized to result in better locality of
752  * access in the index.
753  */
754  for (j = numArrayKeys - 1; j >= 0; j--)
755  {
756  ScanKey scan_key = arrayKeys[j].scan_key;
757  int next_elem = arrayKeys[j].next_elem;
758  int num_elems = arrayKeys[j].num_elems;
759  Datum *elem_values = arrayKeys[j].elem_values;
760  bool *elem_nulls = arrayKeys[j].elem_nulls;
761 
762  if (next_elem >= num_elems)
763  {
764  next_elem = 0;
765  found = false; /* need to advance next array key */
766  }
767  else
768  found = true;
769  scan_key->sk_argument = elem_values[next_elem];
770  if (elem_nulls[next_elem])
771  scan_key->sk_flags |= SK_ISNULL;
772  else
773  scan_key->sk_flags &= ~SK_ISNULL;
774  arrayKeys[j].next_elem = next_elem + 1;
775  if (found)
776  break;
777  }
778 
779  return found;
780 }
781 
782 
783 /* ----------------------------------------------------------------
784  * ExecEndIndexScan
785  * ----------------------------------------------------------------
786  */
787 void
789 {
790  Relation indexRelationDesc;
791  IndexScanDesc indexScanDesc;
792 
793  /*
794  * extract information from the node
795  */
796  indexRelationDesc = node->iss_RelationDesc;
797  indexScanDesc = node->iss_ScanDesc;
798 
799  /*
800  * Free the exprcontext(s) ... now dead code, see ExecFreeExprContext
801  */
802 #ifdef NOT_USED
803  ExecFreeExprContext(&node->ss.ps);
804  if (node->iss_RuntimeContext)
805  FreeExprContext(node->iss_RuntimeContext, true);
806 #endif
807 
808  /*
809  * clear out tuple table slots
810  */
811  if (node->ss.ps.ps_ResultTupleSlot)
814 
815  /*
816  * close the index relation (no-op if we didn't open it)
817  */
818  if (indexScanDesc)
819  index_endscan(indexScanDesc);
820  if (indexRelationDesc)
821  index_close(indexRelationDesc, NoLock);
822 }
823 
824 /* ----------------------------------------------------------------
825  * ExecIndexMarkPos
826  *
827  * Note: we assume that no caller attempts to set a mark before having read
828  * at least one tuple. Otherwise, iss_ScanDesc might still be NULL.
829  * ----------------------------------------------------------------
830  */
831 void
833 {
834  EState *estate = node->ss.ps.state;
835  EPQState *epqstate = estate->es_epq_active;
836 
837  if (epqstate != NULL)
838  {
839  /*
840  * We are inside an EvalPlanQual recheck. If a test tuple exists for
841  * this relation, then we shouldn't access the index at all. We would
842  * instead need to save, and later restore, the state of the
843  * relsubs_done flag, so that re-fetching the test tuple is possible.
844  * However, given the assumption that no caller sets a mark at the
845  * start of the scan, we can only get here with relsubs_done[i]
846  * already set, and so no state need be saved.
847  */
848  Index scanrelid = ((Scan *) node->ss.ps.plan)->scanrelid;
849 
850  Assert(scanrelid > 0);
851  if (epqstate->relsubs_slot[scanrelid - 1] != NULL ||
852  epqstate->relsubs_rowmark[scanrelid - 1] != NULL)
853  {
854  /* Verify the claim above */
855  if (!epqstate->relsubs_done[scanrelid - 1])
856  elog(ERROR, "unexpected ExecIndexMarkPos call in EPQ recheck");
857  return;
858  }
859  }
860 
862 }
863 
864 /* ----------------------------------------------------------------
865  * ExecIndexRestrPos
866  * ----------------------------------------------------------------
867  */
868 void
870 {
871  EState *estate = node->ss.ps.state;
872  EPQState *epqstate = estate->es_epq_active;
873 
874  if (estate->es_epq_active != NULL)
875  {
876  /* See comments in ExecIndexMarkPos */
877  Index scanrelid = ((Scan *) node->ss.ps.plan)->scanrelid;
878 
879  Assert(scanrelid > 0);
880  if (epqstate->relsubs_slot[scanrelid - 1] != NULL ||
881  epqstate->relsubs_rowmark[scanrelid - 1] != NULL)
882  {
883  /* Verify the claim above */
884  if (!epqstate->relsubs_done[scanrelid - 1])
885  elog(ERROR, "unexpected ExecIndexRestrPos call in EPQ recheck");
886  return;
887  }
888  }
889 
891 }
892 
893 /* ----------------------------------------------------------------
894  * ExecInitIndexScan
895  *
896  * Initializes the index scan's state information, creates
897  * scan keys, and opens the base and index relations.
898  *
899  * Note: index scans have 2 sets of state information because
900  * we have to keep track of the base relation and the
901  * index relation.
902  * ----------------------------------------------------------------
903  */
905 ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
906 {
907  IndexScanState *indexstate;
908  Relation currentRelation;
909  LOCKMODE lockmode;
910 
911  /*
912  * create state structure
913  */
914  indexstate = makeNode(IndexScanState);
915  indexstate->ss.ps.plan = (Plan *) node;
916  indexstate->ss.ps.state = estate;
917  indexstate->ss.ps.ExecProcNode = ExecIndexScan;
918 
919  /*
920  * Miscellaneous initialization
921  *
922  * create expression context for node
923  */
924  ExecAssignExprContext(estate, &indexstate->ss.ps);
925 
926  /*
927  * open the scan relation
928  */
929  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
930 
931  indexstate->ss.ss_currentRelation = currentRelation;
932  indexstate->ss.ss_currentScanDesc = NULL; /* no heap scan here */
933 
934  /*
935  * get the scan type from the relation descriptor.
936  */
937  ExecInitScanTupleSlot(estate, &indexstate->ss,
938  RelationGetDescr(currentRelation),
939  table_slot_callbacks(currentRelation));
940 
941  /*
942  * Initialize result type and projection.
943  */
944  ExecInitResultTypeTL(&indexstate->ss.ps);
945  ExecAssignScanProjectionInfo(&indexstate->ss);
946 
947  /*
948  * initialize child expressions
949  *
950  * Note: we don't initialize all of the indexqual expression, only the
951  * sub-parts corresponding to runtime keys (see below). Likewise for
952  * indexorderby, if any. But the indexqualorig expression is always
953  * initialized even though it will only be used in some uncommon cases ---
954  * would be nice to improve that. (Problem is that any SubPlans present
955  * in the expression must be found now...)
956  */
957  indexstate->ss.ps.qual =
958  ExecInitQual(node->scan.plan.qual, (PlanState *) indexstate);
959  indexstate->indexqualorig =
960  ExecInitQual(node->indexqualorig, (PlanState *) indexstate);
961  indexstate->indexorderbyorig =
962  ExecInitExprList(node->indexorderbyorig, (PlanState *) indexstate);
963 
964  /*
965  * If we are just doing EXPLAIN (ie, aren't going to run the plan), stop
966  * here. This allows an index-advisor plugin to EXPLAIN a plan containing
967  * references to nonexistent indexes.
968  */
969  if (eflags & EXEC_FLAG_EXPLAIN_ONLY)
970  return indexstate;
971 
972  /* Open the index relation. */
973  lockmode = exec_rt_fetch(node->scan.scanrelid, estate)->rellockmode;
974  indexstate->iss_RelationDesc = index_open(node->indexid, lockmode);
975 
976  /*
977  * Initialize index-specific scan state
978  */
979  indexstate->iss_RuntimeKeysReady = false;
980  indexstate->iss_RuntimeKeys = NULL;
981  indexstate->iss_NumRuntimeKeys = 0;
982 
983  /*
984  * build the index scan keys from the index qualification
985  */
986  ExecIndexBuildScanKeys((PlanState *) indexstate,
987  indexstate->iss_RelationDesc,
988  node->indexqual,
989  false,
990  &indexstate->iss_ScanKeys,
991  &indexstate->iss_NumScanKeys,
992  &indexstate->iss_RuntimeKeys,
993  &indexstate->iss_NumRuntimeKeys,
994  NULL, /* no ArrayKeys */
995  NULL);
996 
997  /*
998  * any ORDER BY exprs have to be turned into scankeys in the same way
999  */
1000  ExecIndexBuildScanKeys((PlanState *) indexstate,
1001  indexstate->iss_RelationDesc,
1002  node->indexorderby,
1003  true,
1004  &indexstate->iss_OrderByKeys,
1005  &indexstate->iss_NumOrderByKeys,
1006  &indexstate->iss_RuntimeKeys,
1007  &indexstate->iss_NumRuntimeKeys,
1008  NULL, /* no ArrayKeys */
1009  NULL);
1010 
1011  /* Initialize sort support, if we need to re-check ORDER BY exprs */
1012  if (indexstate->iss_NumOrderByKeys > 0)
1013  {
1014  int numOrderByKeys = indexstate->iss_NumOrderByKeys;
1015  int i;
1016  ListCell *lco;
1017  ListCell *lcx;
1018 
1019  /*
1020  * Prepare sort support, and look up the data type for each ORDER BY
1021  * expression.
1022  */
1023  Assert(numOrderByKeys == list_length(node->indexorderbyops));
1024  Assert(numOrderByKeys == list_length(node->indexorderbyorig));
1025  indexstate->iss_SortSupport = (SortSupportData *)
1026  palloc0(numOrderByKeys * sizeof(SortSupportData));
1027  indexstate->iss_OrderByTypByVals = (bool *)
1028  palloc(numOrderByKeys * sizeof(bool));
1029  indexstate->iss_OrderByTypLens = (int16 *)
1030  palloc(numOrderByKeys * sizeof(int16));
1031  i = 0;
1032  forboth(lco, node->indexorderbyops, lcx, node->indexorderbyorig)
1033  {
1034  Oid orderbyop = lfirst_oid(lco);
1035  Node *orderbyexpr = (Node *) lfirst(lcx);
1036  Oid orderbyType = exprType(orderbyexpr);
1037  Oid orderbyColl = exprCollation(orderbyexpr);
1038  SortSupport orderbysort = &indexstate->iss_SortSupport[i];
1039 
1040  /* Initialize sort support */
1041  orderbysort->ssup_cxt = CurrentMemoryContext;
1042  orderbysort->ssup_collation = orderbyColl;
1043  /* See cmp_orderbyvals() comments on NULLS LAST */
1044  orderbysort->ssup_nulls_first = false;
1045  /* ssup_attno is unused here and elsewhere */
1046  orderbysort->ssup_attno = 0;
1047  /* No abbreviation */
1048  orderbysort->abbreviate = false;
1049  PrepareSortSupportFromOrderingOp(orderbyop, orderbysort);
1050 
1051  get_typlenbyval(orderbyType,
1052  &indexstate->iss_OrderByTypLens[i],
1053  &indexstate->iss_OrderByTypByVals[i]);
1054  i++;
1055  }
1056 
1057  /* allocate arrays to hold the re-calculated distances */
1058  indexstate->iss_OrderByValues = (Datum *)
1059  palloc(numOrderByKeys * sizeof(Datum));
1060  indexstate->iss_OrderByNulls = (bool *)
1061  palloc(numOrderByKeys * sizeof(bool));
1062 
1063  /* and initialize the reorder queue */
1065  indexstate);
1066  }
1067 
1068  /*
1069  * If we have runtime keys, we need an ExprContext to evaluate them. The
1070  * node's standard context won't do because we want to reset that context
1071  * for every tuple. So, build another context just like the other one...
1072  * -tgl 7/11/00
1073  */
1074  if (indexstate->iss_NumRuntimeKeys != 0)
1075  {
1076  ExprContext *stdecontext = indexstate->ss.ps.ps_ExprContext;
1077 
1078  ExecAssignExprContext(estate, &indexstate->ss.ps);
1079  indexstate->iss_RuntimeContext = indexstate->ss.ps.ps_ExprContext;
1080  indexstate->ss.ps.ps_ExprContext = stdecontext;
1081  }
1082  else
1083  {
1084  indexstate->iss_RuntimeContext = NULL;
1085  }
1086 
1087  /*
1088  * all done.
1089  */
1090  return indexstate;
1091 }
1092 
1093 
1094 /*
1095  * ExecIndexBuildScanKeys
1096  * Build the index scan keys from the index qualification expressions
1097  *
1098  * The index quals are passed to the index AM in the form of a ScanKey array.
1099  * This routine sets up the ScanKeys, fills in all constant fields of the
1100  * ScanKeys, and prepares information about the keys that have non-constant
1101  * comparison values. We divide index qual expressions into five types:
1102  *
1103  * 1. Simple operator with constant comparison value ("indexkey op constant").
1104  * For these, we just fill in a ScanKey containing the constant value.
1105  *
1106  * 2. Simple operator with non-constant value ("indexkey op expression").
1107  * For these, we create a ScanKey with everything filled in except the
1108  * expression value, and set up an IndexRuntimeKeyInfo struct to drive
1109  * evaluation of the expression at the right times.
1110  *
1111  * 3. RowCompareExpr ("(indexkey, indexkey, ...) op (expr, expr, ...)").
1112  * For these, we create a header ScanKey plus a subsidiary ScanKey array,
1113  * as specified in access/skey.h. The elements of the row comparison
1114  * can have either constant or non-constant comparison values.
1115  *
1116  * 4. ScalarArrayOpExpr ("indexkey op ANY (array-expression)"). If the index
1117  * supports amsearcharray, we handle these the same as simple operators,
1118  * setting the SK_SEARCHARRAY flag to tell the AM to handle them. Otherwise,
1119  * we create a ScanKey with everything filled in except the comparison value,
1120  * and set up an IndexArrayKeyInfo struct to drive processing of the qual.
1121  * (Note that if we use an IndexArrayKeyInfo struct, the array expression is
1122  * always treated as requiring runtime evaluation, even if it's a constant.)
1123  *
1124  * 5. NullTest ("indexkey IS NULL/IS NOT NULL"). We just fill in the
1125  * ScanKey properly.
1126  *
1127  * This code is also used to prepare ORDER BY expressions for amcanorderbyop
1128  * indexes. The behavior is exactly the same, except that we have to look up
1129  * the operator differently. Note that only cases 1 and 2 are currently
1130  * possible for ORDER BY.
1131  *
1132  * Input params are:
1133  *
1134  * planstate: executor state node we are working for
1135  * index: the index we are building scan keys for
1136  * quals: indexquals (or indexorderbys) expressions
1137  * isorderby: true if processing ORDER BY exprs, false if processing quals
1138  * *runtimeKeys: ptr to pre-existing IndexRuntimeKeyInfos, or NULL if none
1139  * *numRuntimeKeys: number of pre-existing runtime keys
1140  *
1141  * Output params are:
1142  *
1143  * *scanKeys: receives ptr to array of ScanKeys
1144  * *numScanKeys: receives number of scankeys
1145  * *runtimeKeys: receives ptr to array of IndexRuntimeKeyInfos, or NULL if none
1146  * *numRuntimeKeys: receives number of runtime keys
1147  * *arrayKeys: receives ptr to array of IndexArrayKeyInfos, or NULL if none
1148  * *numArrayKeys: receives number of array keys
1149  *
1150  * Caller may pass NULL for arrayKeys and numArrayKeys to indicate that
1151  * IndexArrayKeyInfos are not supported.
1152  */
1153 void
1155  List *quals, bool isorderby,
1156  ScanKey *scanKeys, int *numScanKeys,
1157  IndexRuntimeKeyInfo **runtimeKeys, int *numRuntimeKeys,
1158  IndexArrayKeyInfo **arrayKeys, int *numArrayKeys)
1159 {
1160  ListCell *qual_cell;
1161  ScanKey scan_keys;
1162  IndexRuntimeKeyInfo *runtime_keys;
1163  IndexArrayKeyInfo *array_keys;
1164  int n_scan_keys;
1165  int n_runtime_keys;
1166  int max_runtime_keys;
1167  int n_array_keys;
1168  int j;
1169 
1170  /* Allocate array for ScanKey structs: one per qual */
1171  n_scan_keys = list_length(quals);
1172  scan_keys = (ScanKey) palloc(n_scan_keys * sizeof(ScanKeyData));
1173 
1174  /*
1175  * runtime_keys array is dynamically resized as needed. We handle it this
1176  * way so that the same runtime keys array can be shared between
1177  * indexquals and indexorderbys, which will be processed in separate calls
1178  * of this function. Caller must be sure to pass in NULL/0 for first
1179  * call.
1180  */
1181  runtime_keys = *runtimeKeys;
1182  n_runtime_keys = max_runtime_keys = *numRuntimeKeys;
1183 
1184  /* Allocate array_keys as large as it could possibly need to be */
1185  array_keys = (IndexArrayKeyInfo *)
1186  palloc0(n_scan_keys * sizeof(IndexArrayKeyInfo));
1187  n_array_keys = 0;
1188 
1189  /*
1190  * for each opclause in the given qual, convert the opclause into a single
1191  * scan key
1192  */
1193  j = 0;
1194  foreach(qual_cell, quals)
1195  {
1196  Expr *clause = (Expr *) lfirst(qual_cell);
1197  ScanKey this_scan_key = &scan_keys[j++];
1198  Oid opno; /* operator's OID */
1199  RegProcedure opfuncid; /* operator proc id used in scan */
1200  Oid opfamily; /* opfamily of index column */
1201  int op_strategy; /* operator's strategy number */
1202  Oid op_lefttype; /* operator's declared input types */
1203  Oid op_righttype;
1204  Expr *leftop; /* expr on lhs of operator */
1205  Expr *rightop; /* expr on rhs ... */
1206  AttrNumber varattno; /* att number used in scan */
1207  int indnkeyatts;
1208 
1210  if (IsA(clause, OpExpr))
1211  {
1212  /* indexkey op const or indexkey op expression */
1213  int flags = 0;
1214  Datum scanvalue;
1215 
1216  opno = ((OpExpr *) clause)->opno;
1217  opfuncid = ((OpExpr *) clause)->opfuncid;
1218 
1219  /*
1220  * leftop should be the index key Var, possibly relabeled
1221  */
1222  leftop = (Expr *) get_leftop(clause);
1223 
1224  if (leftop && IsA(leftop, RelabelType))
1225  leftop = ((RelabelType *) leftop)->arg;
1226 
1227  Assert(leftop != NULL);
1228 
1229  if (!(IsA(leftop, Var) &&
1230  ((Var *) leftop)->varno == INDEX_VAR))
1231  elog(ERROR, "indexqual doesn't have key on left side");
1232 
1233  varattno = ((Var *) leftop)->varattno;
1234  if (varattno < 1 || varattno > indnkeyatts)
1235  elog(ERROR, "bogus index qualification");
1236 
1237  /*
1238  * We have to look up the operator's strategy number. This
1239  * provides a cross-check that the operator does match the index.
1240  */
1241  opfamily = index->rd_opfamily[varattno - 1];
1242 
1243  get_op_opfamily_properties(opno, opfamily, isorderby,
1244  &op_strategy,
1245  &op_lefttype,
1246  &op_righttype);
1247 
1248  if (isorderby)
1249  flags |= SK_ORDER_BY;
1250 
1251  /*
1252  * rightop is the constant or variable comparison value
1253  */
1254  rightop = (Expr *) get_rightop(clause);
1255 
1256  if (rightop && IsA(rightop, RelabelType))
1257  rightop = ((RelabelType *) rightop)->arg;
1258 
1259  Assert(rightop != NULL);
1260 
1261  if (IsA(rightop, Const))
1262  {
1263  /* OK, simple constant comparison value */
1264  scanvalue = ((Const *) rightop)->constvalue;
1265  if (((Const *) rightop)->constisnull)
1266  flags |= SK_ISNULL;
1267  }
1268  else
1269  {
1270  /* Need to treat this one as a runtime key */
1271  if (n_runtime_keys >= max_runtime_keys)
1272  {
1273  if (max_runtime_keys == 0)
1274  {
1275  max_runtime_keys = 8;
1276  runtime_keys = (IndexRuntimeKeyInfo *)
1277  palloc(max_runtime_keys * sizeof(IndexRuntimeKeyInfo));
1278  }
1279  else
1280  {
1281  max_runtime_keys *= 2;
1282  runtime_keys = (IndexRuntimeKeyInfo *)
1283  repalloc(runtime_keys, max_runtime_keys * sizeof(IndexRuntimeKeyInfo));
1284  }
1285  }
1286  runtime_keys[n_runtime_keys].scan_key = this_scan_key;
1287  runtime_keys[n_runtime_keys].key_expr =
1288  ExecInitExpr(rightop, planstate);
1289  runtime_keys[n_runtime_keys].key_toastable =
1290  TypeIsToastable(op_righttype);
1291  n_runtime_keys++;
1292  scanvalue = (Datum) 0;
1293  }
1294 
1295  /*
1296  * initialize the scan key's fields appropriately
1297  */
1298  ScanKeyEntryInitialize(this_scan_key,
1299  flags,
1300  varattno, /* attribute number to scan */
1301  op_strategy, /* op's strategy */
1302  op_righttype, /* strategy subtype */
1303  ((OpExpr *) clause)->inputcollid, /* collation */
1304  opfuncid, /* reg proc to use */
1305  scanvalue); /* constant */
1306  }
1307  else if (IsA(clause, RowCompareExpr))
1308  {
1309  /* (indexkey, indexkey, ...) op (expression, expression, ...) */
1310  RowCompareExpr *rc = (RowCompareExpr *) clause;
1311  ScanKey first_sub_key;
1312  int n_sub_key;
1313  ListCell *largs_cell;
1314  ListCell *rargs_cell;
1315  ListCell *opnos_cell;
1316  ListCell *collids_cell;
1317 
1318  Assert(!isorderby);
1319 
1320  first_sub_key = (ScanKey)
1321  palloc(list_length(rc->opnos) * sizeof(ScanKeyData));
1322  n_sub_key = 0;
1323 
1324  /* Scan RowCompare columns and generate subsidiary ScanKey items */
1325  forfour(largs_cell, rc->largs, rargs_cell, rc->rargs,
1326  opnos_cell, rc->opnos, collids_cell, rc->inputcollids)
1327  {
1328  ScanKey this_sub_key = &first_sub_key[n_sub_key];
1329  int flags = SK_ROW_MEMBER;
1330  Datum scanvalue;
1331  Oid inputcollation;
1332 
1333  leftop = (Expr *) lfirst(largs_cell);
1334  rightop = (Expr *) lfirst(rargs_cell);
1335  opno = lfirst_oid(opnos_cell);
1336  inputcollation = lfirst_oid(collids_cell);
1337 
1338  /*
1339  * leftop should be the index key Var, possibly relabeled
1340  */
1341  if (leftop && IsA(leftop, RelabelType))
1342  leftop = ((RelabelType *) leftop)->arg;
1343 
1344  Assert(leftop != NULL);
1345 
1346  if (!(IsA(leftop, Var) &&
1347  ((Var *) leftop)->varno == INDEX_VAR))
1348  elog(ERROR, "indexqual doesn't have key on left side");
1349 
1350  varattno = ((Var *) leftop)->varattno;
1351 
1352  /*
1353  * We have to look up the operator's associated btree support
1354  * function
1355  */
1356  if (index->rd_rel->relam != BTREE_AM_OID ||
1357  varattno < 1 || varattno > indnkeyatts)
1358  elog(ERROR, "bogus RowCompare index qualification");
1359  opfamily = index->rd_opfamily[varattno - 1];
1360 
1361  get_op_opfamily_properties(opno, opfamily, isorderby,
1362  &op_strategy,
1363  &op_lefttype,
1364  &op_righttype);
1365 
1366  if (op_strategy != rc->rctype)
1367  elog(ERROR, "RowCompare index qualification contains wrong operator");
1368 
1369  opfuncid = get_opfamily_proc(opfamily,
1370  op_lefttype,
1371  op_righttype,
1372  BTORDER_PROC);
1373  if (!RegProcedureIsValid(opfuncid))
1374  elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
1375  BTORDER_PROC, op_lefttype, op_righttype, opfamily);
1376 
1377  /*
1378  * rightop is the constant or variable comparison value
1379  */
1380  if (rightop && IsA(rightop, RelabelType))
1381  rightop = ((RelabelType *) rightop)->arg;
1382 
1383  Assert(rightop != NULL);
1384 
1385  if (IsA(rightop, Const))
1386  {
1387  /* OK, simple constant comparison value */
1388  scanvalue = ((Const *) rightop)->constvalue;
1389  if (((Const *) rightop)->constisnull)
1390  flags |= SK_ISNULL;
1391  }
1392  else
1393  {
1394  /* Need to treat this one as a runtime key */
1395  if (n_runtime_keys >= max_runtime_keys)
1396  {
1397  if (max_runtime_keys == 0)
1398  {
1399  max_runtime_keys = 8;
1400  runtime_keys = (IndexRuntimeKeyInfo *)
1401  palloc(max_runtime_keys * sizeof(IndexRuntimeKeyInfo));
1402  }
1403  else
1404  {
1405  max_runtime_keys *= 2;
1406  runtime_keys = (IndexRuntimeKeyInfo *)
1407  repalloc(runtime_keys, max_runtime_keys * sizeof(IndexRuntimeKeyInfo));
1408  }
1409  }
1410  runtime_keys[n_runtime_keys].scan_key = this_sub_key;
1411  runtime_keys[n_runtime_keys].key_expr =
1412  ExecInitExpr(rightop, planstate);
1413  runtime_keys[n_runtime_keys].key_toastable =
1414  TypeIsToastable(op_righttype);
1415  n_runtime_keys++;
1416  scanvalue = (Datum) 0;
1417  }
1418 
1419  /*
1420  * initialize the subsidiary scan key's fields appropriately
1421  */
1422  ScanKeyEntryInitialize(this_sub_key,
1423  flags,
1424  varattno, /* attribute number */
1425  op_strategy, /* op's strategy */
1426  op_righttype, /* strategy subtype */
1427  inputcollation, /* collation */
1428  opfuncid, /* reg proc to use */
1429  scanvalue); /* constant */
1430  n_sub_key++;
1431  }
1432 
1433  /* Mark the last subsidiary scankey correctly */
1434  first_sub_key[n_sub_key - 1].sk_flags |= SK_ROW_END;
1435 
1436  /*
1437  * We don't use ScanKeyEntryInitialize for the header because it
1438  * isn't going to contain a valid sk_func pointer.
1439  */
1440  MemSet(this_scan_key, 0, sizeof(ScanKeyData));
1441  this_scan_key->sk_flags = SK_ROW_HEADER;
1442  this_scan_key->sk_attno = first_sub_key->sk_attno;
1443  this_scan_key->sk_strategy = rc->rctype;
1444  /* sk_subtype, sk_collation, sk_func not used in a header */
1445  this_scan_key->sk_argument = PointerGetDatum(first_sub_key);
1446  }
1447  else if (IsA(clause, ScalarArrayOpExpr))
1448  {
1449  /* indexkey op ANY (array-expression) */
1450  ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) clause;
1451  int flags = 0;
1452  Datum scanvalue;
1453 
1454  Assert(!isorderby);
1455 
1456  Assert(saop->useOr);
1457  opno = saop->opno;
1458  opfuncid = saop->opfuncid;
1459 
1460  /*
1461  * leftop should be the index key Var, possibly relabeled
1462  */
1463  leftop = (Expr *) linitial(saop->args);
1464 
1465  if (leftop && IsA(leftop, RelabelType))
1466  leftop = ((RelabelType *) leftop)->arg;
1467 
1468  Assert(leftop != NULL);
1469 
1470  if (!(IsA(leftop, Var) &&
1471  ((Var *) leftop)->varno == INDEX_VAR))
1472  elog(ERROR, "indexqual doesn't have key on left side");
1473 
1474  varattno = ((Var *) leftop)->varattno;
1475  if (varattno < 1 || varattno > indnkeyatts)
1476  elog(ERROR, "bogus index qualification");
1477 
1478  /*
1479  * We have to look up the operator's strategy number. This
1480  * provides a cross-check that the operator does match the index.
1481  */
1482  opfamily = index->rd_opfamily[varattno - 1];
1483 
1484  get_op_opfamily_properties(opno, opfamily, isorderby,
1485  &op_strategy,
1486  &op_lefttype,
1487  &op_righttype);
1488 
1489  /*
1490  * rightop is the constant or variable array value
1491  */
1492  rightop = (Expr *) lsecond(saop->args);
1493 
1494  if (rightop && IsA(rightop, RelabelType))
1495  rightop = ((RelabelType *) rightop)->arg;
1496 
1497  Assert(rightop != NULL);
1498 
1499  if (index->rd_indam->amsearcharray)
1500  {
1501  /* Index AM will handle this like a simple operator */
1502  flags |= SK_SEARCHARRAY;
1503  if (IsA(rightop, Const))
1504  {
1505  /* OK, simple constant comparison value */
1506  scanvalue = ((Const *) rightop)->constvalue;
1507  if (((Const *) rightop)->constisnull)
1508  flags |= SK_ISNULL;
1509  }
1510  else
1511  {
1512  /* Need to treat this one as a runtime key */
1513  if (n_runtime_keys >= max_runtime_keys)
1514  {
1515  if (max_runtime_keys == 0)
1516  {
1517  max_runtime_keys = 8;
1518  runtime_keys = (IndexRuntimeKeyInfo *)
1519  palloc(max_runtime_keys * sizeof(IndexRuntimeKeyInfo));
1520  }
1521  else
1522  {
1523  max_runtime_keys *= 2;
1524  runtime_keys = (IndexRuntimeKeyInfo *)
1525  repalloc(runtime_keys, max_runtime_keys * sizeof(IndexRuntimeKeyInfo));
1526  }
1527  }
1528  runtime_keys[n_runtime_keys].scan_key = this_scan_key;
1529  runtime_keys[n_runtime_keys].key_expr =
1530  ExecInitExpr(rightop, planstate);
1531 
1532  /*
1533  * Careful here: the runtime expression is not of
1534  * op_righttype, but rather is an array of same; so
1535  * TypeIsToastable() isn't helpful. However, we can
1536  * assume that all array types are toastable.
1537  */
1538  runtime_keys[n_runtime_keys].key_toastable = true;
1539  n_runtime_keys++;
1540  scanvalue = (Datum) 0;
1541  }
1542  }
1543  else
1544  {
1545  /* Executor has to expand the array value */
1546  array_keys[n_array_keys].scan_key = this_scan_key;
1547  array_keys[n_array_keys].array_expr =
1548  ExecInitExpr(rightop, planstate);
1549  /* the remaining fields were zeroed by palloc0 */
1550  n_array_keys++;
1551  scanvalue = (Datum) 0;
1552  }
1553 
1554  /*
1555  * initialize the scan key's fields appropriately
1556  */
1557  ScanKeyEntryInitialize(this_scan_key,
1558  flags,
1559  varattno, /* attribute number to scan */
1560  op_strategy, /* op's strategy */
1561  op_righttype, /* strategy subtype */
1562  saop->inputcollid, /* collation */
1563  opfuncid, /* reg proc to use */
1564  scanvalue); /* constant */
1565  }
1566  else if (IsA(clause, NullTest))
1567  {
1568  /* indexkey IS NULL or indexkey IS NOT NULL */
1569  NullTest *ntest = (NullTest *) clause;
1570  int flags;
1571 
1572  Assert(!isorderby);
1573 
1574  /*
1575  * argument should be the index key Var, possibly relabeled
1576  */
1577  leftop = ntest->arg;
1578 
1579  if (leftop && IsA(leftop, RelabelType))
1580  leftop = ((RelabelType *) leftop)->arg;
1581 
1582  Assert(leftop != NULL);
1583 
1584  if (!(IsA(leftop, Var) &&
1585  ((Var *) leftop)->varno == INDEX_VAR))
1586  elog(ERROR, "NullTest indexqual has wrong key");
1587 
1588  varattno = ((Var *) leftop)->varattno;
1589 
1590  /*
1591  * initialize the scan key's fields appropriately
1592  */
1593  switch (ntest->nulltesttype)
1594  {
1595  case IS_NULL:
1596  flags = SK_ISNULL | SK_SEARCHNULL;
1597  break;
1598  case IS_NOT_NULL:
1599  flags = SK_ISNULL | SK_SEARCHNOTNULL;
1600  break;
1601  default:
1602  elog(ERROR, "unrecognized nulltesttype: %d",
1603  (int) ntest->nulltesttype);
1604  flags = 0; /* keep compiler quiet */
1605  break;
1606  }
1607 
1608  ScanKeyEntryInitialize(this_scan_key,
1609  flags,
1610  varattno, /* attribute number to scan */
1611  InvalidStrategy, /* no strategy */
1612  InvalidOid, /* no strategy subtype */
1613  InvalidOid, /* no collation */
1614  InvalidOid, /* no reg proc for this */
1615  (Datum) 0); /* constant */
1616  }
1617  else
1618  elog(ERROR, "unsupported indexqual type: %d",
1619  (int) nodeTag(clause));
1620  }
1621 
1622  Assert(n_runtime_keys <= max_runtime_keys);
1623 
1624  /* Get rid of any unused arrays */
1625  if (n_array_keys == 0)
1626  {
1627  pfree(array_keys);
1628  array_keys = NULL;
1629  }
1630 
1631  /*
1632  * Return info to our caller.
1633  */
1634  *scanKeys = scan_keys;
1635  *numScanKeys = n_scan_keys;
1636  *runtimeKeys = runtime_keys;
1637  *numRuntimeKeys = n_runtime_keys;
1638  if (arrayKeys)
1639  {
1640  *arrayKeys = array_keys;
1641  *numArrayKeys = n_array_keys;
1642  }
1643  else if (n_array_keys != 0)
1644  elog(ERROR, "ScalarArrayOpExpr index qual found where not allowed");
1645 }
1646 
1647 /* ----------------------------------------------------------------
1648  * Parallel Scan Support
1649  * ----------------------------------------------------------------
1650  */
1651 
1652 /* ----------------------------------------------------------------
1653  * ExecIndexScanEstimate
1654  *
1655  * Compute the amount of space we'll need in the parallel
1656  * query DSM, and inform pcxt->estimator about our needs.
1657  * ----------------------------------------------------------------
1658  */
1659 void
1661  ParallelContext *pcxt)
1662 {
1663  EState *estate = node->ss.ps.state;
1664 
1666  estate->es_snapshot);
1668  shm_toc_estimate_keys(&pcxt->estimator, 1);
1669 }
1670 
1671 /* ----------------------------------------------------------------
1672  * ExecIndexScanInitializeDSM
1673  *
1674  * Set up a parallel index scan descriptor.
1675  * ----------------------------------------------------------------
1676  */
1677 void
1679  ParallelContext *pcxt)
1680 {
1681  EState *estate = node->ss.ps.state;
1682  ParallelIndexScanDesc piscan;
1683 
1684  piscan = shm_toc_allocate(pcxt->toc, node->iss_PscanLen);
1686  node->iss_RelationDesc,
1687  estate->es_snapshot,
1688  piscan);
1689  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, piscan);
1690  node->iss_ScanDesc =
1692  node->iss_RelationDesc,
1693  node->iss_NumScanKeys,
1694  node->iss_NumOrderByKeys,
1695  piscan);
1696 
1697  /*
1698  * If no run-time keys to calculate or they are ready, go ahead and pass
1699  * the scankeys to the index AM.
1700  */
1701  if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady)
1702  index_rescan(node->iss_ScanDesc,
1703  node->iss_ScanKeys, node->iss_NumScanKeys,
1704  node->iss_OrderByKeys, node->iss_NumOrderByKeys);
1705 }
1706 
1707 /* ----------------------------------------------------------------
1708  * ExecIndexScanReInitializeDSM
1709  *
1710  * Reset shared state before beginning a fresh scan.
1711  * ----------------------------------------------------------------
1712  */
1713 void
1715  ParallelContext *pcxt)
1716 {
1718 }
1719 
1720 /* ----------------------------------------------------------------
1721  * ExecIndexScanInitializeWorker
1722  *
1723  * Copy relevant information from TOC into planstate.
1724  * ----------------------------------------------------------------
1725  */
1726 void
1728  ParallelWorkerContext *pwcxt)
1729 {
1730  ParallelIndexScanDesc piscan;
1731 
1732  piscan = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
1733  node->iss_ScanDesc =
1735  node->iss_RelationDesc,
1736  node->iss_NumScanKeys,
1737  node->iss_NumOrderByKeys,
1738  piscan);
1739 
1740  /*
1741  * If no run-time keys to calculate or they are ready, go ahead and pass
1742  * the scankeys to the index AM.
1743  */
1744  if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady)
1745  index_rescan(node->iss_ScanDesc,
1746  node->iss_ScanKeys, node->iss_NumScanKeys,
1747  node->iss_OrderByKeys, node->iss_NumOrderByKeys);
1748 }
#define DatumGetArrayTypeP(X)
Definition: array.h:254
#define ARR_ELEMTYPE(a)
Definition: array.h:285
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3576
int16 AttrNumber
Definition: attnum.h:21
#define RegProcedureIsValid(p)
Definition: c.h:713
signed short int16
Definition: c.h:429
regproc RegProcedure
Definition: c.h:586
unsigned int Index
Definition: c.h:550
#define MemSet(start, val, len)
Definition: c.h:953
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
#define ERROR
Definition: elog.h:35
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:319
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:210
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:124
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:158
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:272
void ExecScanReScan(ScanState *node)
Definition: execScan.c:299
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1811
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1755
void ExecForceStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1469
void FreeExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:412
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:481
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:721
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:651
#define InstrCountFiltered2(node, delta)
Definition: execnodes.h:1133
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:573
#define ResetExprContext(econtext)
Definition: executor.h:529
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:458
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:459
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition: executor.h:425
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
Definition: executor.h:318
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:56
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: indexam.c:616
Size index_parallelscan_estimate(Relation indexRelation, Snapshot snapshot)
Definition: indexam.c:402
void index_restrpos(IndexScanDesc scan)
Definition: indexam.c:377
IndexScanDesc index_beginscan_parallel(Relation heaprel, Relation indexrel, int nkeys, int norderbys, ParallelIndexScanDesc pscan)
Definition: indexam.c:484
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
Definition: indexam.c:205
void index_markpos(IndexScanDesc scan)
Definition: indexam.c:353
void index_endscan(IndexScanDesc scan)
Definition: indexam.c:323
void index_parallelscan_initialize(Relation heapRelation, Relation indexRelation, Snapshot snapshot, ParallelIndexScanDesc target)
Definition: indexam.c:435
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132
void index_parallelrescan(IndexScanDesc scan)
Definition: indexam.c:466
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition: indexam.c:297
int b
Definition: isn.c:70
int a
Definition: isn.c:69
int j
Definition: isn.c:74
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
int LOCKMODE
Definition: lockdefs.h:26
#define NoLock
Definition: lockdefs.h:34
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
Definition: lsyscache.c:135
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2229
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition: lsyscache.c:795
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2209
#define TypeIsToastable(typid)
Definition: lsyscache.h:210
void pfree(void *pointer)
Definition: mcxt.c:1306
void * palloc0(Size size)
Definition: mcxt.c:1230
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1321
void * palloc(Size size)
Definition: mcxt.c:1199
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
#define BTORDER_PROC
Definition: nbtree.h:701
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:764
static Node * get_rightop(const void *clause)
Definition: nodeFuncs.h:93
static Node * get_leftop(const void *clause)
Definition: nodeFuncs.h:81
static TupleTableSlot * ExecIndexScan(PlanState *pstate)
static void reorderqueue_push(IndexScanState *node, TupleTableSlot *slot, Datum *orderbyvals, bool *orderbynulls)
void ExecIndexBuildScanKeys(PlanState *planstate, Relation index, List *quals, bool isorderby, ScanKey *scanKeys, int *numScanKeys, IndexRuntimeKeyInfo **runtimeKeys, int *numRuntimeKeys, IndexArrayKeyInfo **arrayKeys, int *numArrayKeys)
void ExecIndexScanEstimate(IndexScanState *node, ParallelContext *pcxt)
static void EvalOrderByExpressions(IndexScanState *node, ExprContext *econtext)
bool ExecIndexEvalArrayKeys(ExprContext *econtext, IndexArrayKeyInfo *arrayKeys, int numArrayKeys)
void ExecIndexEvalRuntimeKeys(ExprContext *econtext, IndexRuntimeKeyInfo *runtimeKeys, int numRuntimeKeys)
void ExecIndexScanReInitializeDSM(IndexScanState *node, ParallelContext *pcxt)
static int cmp_orderbyvals(const Datum *adist, const bool *anulls, const Datum *bdist, const bool *bnulls, IndexScanState *node)
void ExecReScanIndexScan(IndexScanState *node)
void ExecIndexScanInitializeDSM(IndexScanState *node, ParallelContext *pcxt)
IndexScanState * ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
static TupleTableSlot * IndexNextWithReorder(IndexScanState *node)
void ExecIndexScanInitializeWorker(IndexScanState *node, ParallelWorkerContext *pwcxt)
void ExecEndIndexScan(IndexScanState *node)
static bool IndexRecheck(IndexScanState *node, TupleTableSlot *slot)
void ExecIndexRestrPos(IndexScanState *node)
static int reorderqueue_cmp(const pairingheap_node *a, const pairingheap_node *b, void *arg)
void ExecIndexMarkPos(IndexScanState *node)
static HeapTuple reorderqueue_pop(IndexScanState *node)
bool ExecIndexAdvanceArrayKeys(IndexArrayKeyInfo *arrayKeys, int numArrayKeys)
static TupleTableSlot * IndexNext(IndexScanState *node)
Definition: nodeIndexscan.c:81
#define IsA(nodeptr, _type_)
Definition: nodes.h:162
#define nodeTag(nodeptr)
Definition: nodes.h:116
#define makeNode(_type_)
Definition: nodes.h:159
#define castNode(_type_, nodeptr)
Definition: nodes.h:180
void pairingheap_add(pairingheap *heap, pairingheap_node *node)
Definition: pairingheap.c:112
pairingheap_node * pairingheap_first(pairingheap *heap)
Definition: pairingheap.c:130
pairingheap * pairingheap_allocate(pairingheap_comparator compare, void *arg)
Definition: pairingheap.c:42
pairingheap_node * pairingheap_remove_first(pairingheap *heap)
Definition: pairingheap.c:145
#define pairingheap_is_empty(h)
Definition: pairingheap.h:96
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
void * arg
#define lfirst(lc)
Definition: pg_list.h:170
static int list_length(const List *l)
Definition: pg_list.h:150
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:465
#define linitial(l)
Definition: pg_list.h:176
#define lsecond(l)
Definition: pg_list.h:181
#define forfour(cell1, list1, cell2, list2, cell3, list3, cell4, list4)
Definition: pg_list.h:522
#define lfirst_oid(lc)
Definition: pg_list.h:172
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:670
uintptr_t Datum
Definition: postgres.h:412
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:660
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
@ IS_NULL
Definition: primnodes.h:1359
@ IS_NOT_NULL
Definition: primnodes.h:1359
#define INDEX_VAR
Definition: primnodes.h:195
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747
#define RelationGetDescr(relation)
Definition: rel.h:527
#define IndexRelationGetNumberOfKeyAttributes(relation)
Definition: rel.h:520
void ScanKeyEntryInitialize(ScanKey entry, int flags, AttrNumber attributeNumber, StrategyNumber strategy, Oid subtype, Oid collation, RegProcedure procedure, Datum argument)
Definition: scankey.c:32
#define ScanDirectionIsForward(direction)
Definition: sdir.h:55
#define ScanDirectionIsBackward(direction)
Definition: sdir.h:41
ScanDirection
Definition: sdir.h:23
@ BackwardScanDirection
Definition: sdir.h:24
@ ForwardScanDirection
Definition: sdir.h:26
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
struct ScanKeyData ScanKeyData
#define SK_ORDER_BY
Definition: skey.h:123
#define SK_ROW_HEADER
Definition: skey.h:117
#define SK_SEARCHARRAY
Definition: skey.h:120
#define SK_ROW_MEMBER
Definition: skey.h:118
#define SK_SEARCHNOTNULL
Definition: skey.h:122
#define SK_SEARCHNULL
Definition: skey.h:121
#define SK_ROW_END
Definition: skey.h:119
ScanKeyData * ScanKey
Definition: skey.h:75
#define SK_ISNULL
Definition: skey.h:115
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
Definition: sortsupport.c:135
#define InvalidStrategy
Definition: stratnum.h:24
ExecAuxRowMark ** relsubs_rowmark
Definition: execnodes.h:1198
TupleTableSlot ** relsubs_slot
Definition: execnodes.h:1170
bool * relsubs_done
Definition: execnodes.h:1204
MemoryContext es_query_cxt
Definition: execnodes.h:650
ScanDirection es_direction
Definition: execnodes.h:607
struct EPQState * es_epq_active
Definition: execnodes.h:679
Snapshot es_snapshot
Definition: execnodes.h:608
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:255
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:247
Datum * elem_values
Definition: execnodes.h:1504
ExprState * array_expr
Definition: execnodes.h:1501
struct ScanKeyData * scan_key
Definition: execnodes.h:1500
ExprState * key_expr
Definition: execnodes.h:1494
struct ScanKeyData * scan_key
Definition: execnodes.h:1493
bool * xs_orderbynulls
Definition: relscan.h:162
int numberOfOrderBys
Definition: relscan.h:121
bool xs_recheckorderby
Definition: relscan.h:163
Datum * xs_orderbyvals
Definition: relscan.h:161
bool iss_ReachedEnd
Definition: execnodes.h:1552
List * indexorderbyorig
Definition: execnodes.h:1538
bool * iss_OrderByTypByVals
Definition: execnodes.h:1556
int iss_NumRuntimeKeys
Definition: execnodes.h:1544
struct IndexScanDescData * iss_ScanDesc
Definition: execnodes.h:1548
ExprState * indexqualorig
Definition: execnodes.h:1537
Relation iss_RelationDesc
Definition: execnodes.h:1547
pairingheap * iss_ReorderQueue
Definition: execnodes.h:1551
ScanState ss
Definition: execnodes.h:1536
bool * iss_OrderByNulls
Definition: execnodes.h:1554
bool iss_RuntimeKeysReady
Definition: execnodes.h:1545
SortSupport iss_SortSupport
Definition: execnodes.h:1555
struct ScanKeyData * iss_ScanKeys
Definition: execnodes.h:1539
int iss_NumOrderByKeys
Definition: execnodes.h:1542
ExprContext * iss_RuntimeContext
Definition: execnodes.h:1546
struct ScanKeyData * iss_OrderByKeys
Definition: execnodes.h:1541
Datum * iss_OrderByValues
Definition: execnodes.h:1553
int16 * iss_OrderByTypLens
Definition: execnodes.h:1557
IndexRuntimeKeyInfo * iss_RuntimeKeys
Definition: execnodes.h:1543
List * indexorderby
Definition: plannodes.h:450
List * indexorderbyops
Definition: plannodes.h:452
Scan scan
Definition: plannodes.h:446
List * indexqualorig
Definition: plannodes.h:449
Oid indexid
Definition: plannodes.h:447
List * indexqual
Definition: plannodes.h:448
List * indexorderbyorig
Definition: plannodes.h:451
Definition: pg_list.h:52
Definition: nodes.h:112
NullTestType nulltesttype
Definition: primnodes.h:1366
Expr * arg
Definition: primnodes.h:1365
shm_toc_estimator estimator
Definition: parallel.h:42
shm_toc * toc
Definition: parallel.h:45
ExprState * qual
Definition: execnodes.h:1045
Plan * plan
Definition: execnodes.h:1024
EState * state
Definition: execnodes.h:1026
ExprContext * ps_ExprContext
Definition: execnodes.h:1063
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1062
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1030
int plan_node_id
Definition: plannodes.h:149
Datum * orderbyvals
Definition: nodeIndexscan.c:55
bool * orderbynulls
Definition: nodeIndexscan.c:56
pairingheap_node ph_node
Definition: nodeIndexscan.c:53
HeapTuple htup
Definition: nodeIndexscan.c:54
RowCompareType rctype
Definition: primnodes.h:1255
List * inputcollids
Definition: primnodes.h:1258
int sk_flags
Definition: skey.h:66
Datum sk_argument
Definition: skey.h:72
StrategyNumber sk_strategy
Definition: skey.h:68
AttrNumber sk_attno
Definition: skey.h:67
Relation ss_currentRelation
Definition: execnodes.h:1450
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1452
PlanState ps
Definition: execnodes.h:1449
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1451
Index scanrelid
Definition: plannodes.h:384
AttrNumber ssup_attno
Definition: sortsupport.h:81
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
bool ssup_nulls_first
Definition: sortsupport.h:75
MemoryContext ssup_cxt
Definition: sortsupport.h:66
Definition: primnodes.h:205
Definition: type.h:95
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition: tuptable.h:460