MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecIndexEvalArrayKeys

Function ExecIndexEvalArrayKeys

src/backend/executor/nodeIndexscan.c:663–733  ·  view source on GitHub ↗

* ExecIndexEvalArrayKeys * Evaluate any array key values, and set up to iterate through arrays. * * Returns true if there are array elements to consider; false means there * is at least one null or empty array, so no match is possible. On true * result, the scankeys are initialized with the first elements of the arrays. */

Source from the content-addressed store, hash-verified

661 * result, the scankeys are initialized with the first elements of the arrays.
662 */
663bool
664ExecIndexEvalArrayKeys(ExprContext *econtext,
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 */
702 get_typlenbyvalalign(ARR_ELEMTYPE(arrayval),
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;

Callers 1

Calls 4

MemoryContextSwitchToFunction · 0.85
ExecEvalExprFunction · 0.85
get_typlenbyvalalignFunction · 0.85
deconstruct_arrayFunction · 0.85

Tested by

no test coverage detected