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

Function ExecInitScalarArrayOpFastPath

src/backend/executor/execExpr.c:3365–3556  ·  view source on GitHub ↗

* GPDB: For a few built-in equality operators, we have a specialized fast-path * version to evaluate a ScalarArrayOpExpr. In the fast path, the array * argument must be a constant. It is decomposed into a C array here for faster * evaluation at runtime. */

Source from the content-addressed store, hash-verified

3363 * evaluation at runtime.
3364 */
3365static bool
3366ExecInitScalarArrayOpFastPath(ExprEvalStep *scratch,
3367 ScalarArrayOpExpr *opexpr,
3368 ExprState *state, Datum *resv, bool *resnull)
3369{
3370 Oid opfuncid = opexpr->opfuncid;
3371 Oid collid = opexpr->inputcollid;
3372 Expr *scalararg;
3373 Expr *arrayarg;
3374 Const *arrayconst;
3375 ArrayType *arr;
3376 int16 typlen;
3377 bool typbyval;
3378 char typalign;
3379 char *s;
3380 bits8 *bitmap;
3381 int bitmask;
3382 int nelems;
3383 int *fp_len;
3384 Datum *fp_datum;
3385
3386 Assert(list_length(opexpr->args) == 2);
3387 scalararg = (Expr *) linitial(opexpr->args);
3388 arrayarg = (Expr *) lsecond(opexpr->args);
3389
3390 /* IN will be evaluated as OR */
3391 if (!opexpr->useOr)
3392 return false;
3393
3394 /* only if the array arg is const */
3395 if (!IsA(arrayarg, Const))
3396 return false;
3397 arrayconst = (Const *) arrayarg;
3398
3399 /* We do not handle null */
3400 if (arrayconst->constisnull)
3401 return false;
3402
3403 arr = DatumGetArrayTypeP(arrayconst->constvalue);
3404 nelems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3405
3406 /* We do not handle this case */
3407 if (nelems <= 0)
3408 return false;
3409
3410 if (opfuncid == F_INT2EQ || opfuncid == F_INT4EQ || opexpr->opfuncid == F_INT8EQ ||
3411 opfuncid == F_DATE_EQ)
3412 {
3413 /* ok */
3414 }
3415 else if (opfuncid == F_TEXTEQ || opfuncid == F_BPCHAREQ)
3416 {
3417 /*
3418 * Since we're not calling texteq(), sanity check here that collation was
3419 * reosolved. This is the same as check_collation_set(collid).
3420 */
3421 if (!OidIsValid(collid))
3422 {

Callers 1

ExecInitExprRecFunction · 0.85

Calls 15

list_lengthFunction · 0.85
ArrayGetNItemsFunction · 0.85
lc_collate_is_cFunction · 0.85
get_typlenbyvalalignFunction · 0.85
Int16GetDatumFunction · 0.85
DatumGetInt16Function · 0.85
Int32GetDatumFunction · 0.85
DatumGetInt32Function · 0.85
ExecInitExprRecFunction · 0.85
ExprEvalPushStepFunction · 0.85

Tested by

no test coverage detected