322 Node *rawreq = (Node *) PG_GETARG_POINTER(0);
329 postgis_initialize_cache();
331 if (IsA(rawreq, SupportRequestSelectivity))
333 SupportRequestSelectivity *req = (SupportRequestSelectivity *) rawreq;
343 POSTGIS_DEBUGF(2,
"%s: got selectivity %g", __func__, req->selectivity);
344 PG_RETURN_POINTER(req);
351 if (IsA(rawreq, SupportRequestIndexCondition))
353 SupportRequestIndexCondition *req = (SupportRequestIndexCondition *) rawreq;
355 if (is_funcclause(req->node))
357 FuncExpr *clause = (FuncExpr *) req->node;
358 Oid funcid = clause->funcid;
360 Oid opfamilyoid = req->opfamily;
364 int nargs = list_length(clause->args);
365 Node *leftarg, *rightarg;
366 Oid leftdatatype, rightdatatype, oproid;
367 bool swapped =
false;
376 uint8_t opfamilydims;
378 if (opfamilyam != GIST_AM_OID &&
379 opfamilyam != SPGIST_AM_OID &&
380 opfamilyam != BRIN_AM_OID)
382 PG_RETURN_POINTER((Node *)NULL);
389 if (req->indexarg > 1)
390 PG_RETURN_POINTER((Node *)NULL);
397 if (opfamilydims == 3 && idxfn.dims != 3)
398 PG_RETURN_POINTER((Node *)NULL);
403 if (nargs < 2 || nargs < idxfn.expand_arg)
404 elog(ERROR,
"%s: associated with function with %d arguments", __func__, nargs);
416 if (req->indexarg == 0)
418 leftarg = linitial(clause->args);
419 rightarg = lsecond(clause->args);
423 rightarg = linitial(clause->args);
424 leftarg = lsecond(clause->args);
432 leftdatatype = exprType(leftarg);
433 rightdatatype = exprType(rightarg);
440 oproid = get_opfamily_member(opfamilyoid,
444 if (!OidIsValid(oproid))
446 "no spatial operator found for '%s': opfamily %u type %d",
458 if (idxfn.expand_arg)
461 Node *radiusarg = (Node *) list_nth(clause->args, idxfn.expand_arg-1);
464 FuncExpr *expandexpr = makeFuncExpr(expandfn_oid, rightdatatype,
465 list_make2(rightarg, radiusarg),
466 InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL);
472 #if POSTGIS_PGSQL_VERSION >= 140
473 if (!is_pseudo_constant_for_index(req->root, (Node*)expandexpr, req->index))
475 if (!is_pseudo_constant_for_index((Node*)expandexpr, req->index))
477 PG_RETURN_POINTER((Node*)NULL);
480 expr = make_opclause(oproid, BOOLOID,
false,
481 (Expr *) leftarg, (Expr *) expandexpr,
482 InvalidOid, InvalidOid);
484 ret = (Node *)(list_make1(expr));
499 #if POSTGIS_PGSQL_VERSION >= 140
500 if (!is_pseudo_constant_for_index(req->root, rightarg, req->index))
502 if (!is_pseudo_constant_for_index(rightarg, req->index))
504 PG_RETURN_POINTER((Node*)NULL);
513 oproid = get_commutator(oproid);
514 if (!OidIsValid(oproid))
515 PG_RETURN_POINTER((Node *)NULL);
518 expr = make_opclause(oproid, BOOLOID,
false,
519 (Expr *) leftarg, (Expr *) rightarg,
520 InvalidOid, InvalidOid);
522 ret = (Node *)(list_make1(expr));
532 PG_RETURN_POINTER(ret);
536 elog(WARNING,
"support function '%s' called from unsupported spatial function", __func__);
541 PG_RETURN_POINTER(ret);
static bool needsSpatialIndex(Oid funcid, IndexableFunction *idxfn)
static Oid expandFunctionOid(Oid geotype, Oid callingfunc)
static Oid opFamilyAmOid(Oid opfamilyoid, uint8_t *dims)
float8 gserialized_sel_internal(PlannerInfo *root, List *args, int varRelid, int mode)
This function should return an estimation of the number of rows returned by a query involving an over...
float8 gserialized_joinsel_internal(PlannerInfo *root, List *args, JoinType jointype, int mode)
static int16 get_strategy_by_type(Oid first_type, uint16_t index)