321{
322 Node *rawreq = (Node *) PG_GETARG_POINTER(0);
323 Node *ret = NULL;
324
325
326
327
328
329 postgis_initialize_cache();
330
331 if (IsA(rawreq, SupportRequestSelectivity))
332 {
333 SupportRequestSelectivity *req = (SupportRequestSelectivity *) rawreq;
334
335 if (req->is_join)
336 {
338 }
339 else
340 {
342 }
343 POSTGIS_DEBUGF(2, "%s: got selectivity %g", __func__, req->selectivity);
344 PG_RETURN_POINTER(req);
345 }
346
347
348
349
350
351 if (IsA(rawreq, SupportRequestIndexCondition))
352 {
353 SupportRequestIndexCondition *req = (SupportRequestIndexCondition *) rawreq;
354
355 if (is_funcclause(req->node))
356 {
357 FuncExpr *clause = (FuncExpr *) req->node;
358 Oid funcid = clause->funcid;
360 Oid opfamilyoid = req->opfamily;
361
363 {
364 int nargs = list_length(clause->args);
365 Node *leftarg, *rightarg;
366 Oid leftdatatype, rightdatatype, oproid;
367 bool swapped = false;
368
369
370
371
372
373
374
375
376 uint8_t opfamilydims;
378 if (opfamilyam != GIST_AM_OID &&
379 opfamilyam != SPGIST_AM_OID &&
380 opfamilyam != BRIN_AM_OID)
381 {
382 PG_RETURN_POINTER((Node *)NULL);
383 }
384
385
386
387
388
389 if (req->indexarg > 1)
390 PG_RETURN_POINTER((Node *)NULL);
391
392
393
394
395
396
397 if (opfamilydims == 3 && idxfn.
dims != 3)
398 PG_RETURN_POINTER((Node *)NULL);
399
400
401
402
404 elog(ERROR, "%s: associated with function with %d arguments", __func__, nargs);
405
406
407
408
409
410
411
412
413
414
415
416 if (req->indexarg == 0)
417 {
418 leftarg = linitial(clause->args);
419 rightarg = lsecond(clause->args);
420 }
421 else
422 {
423 rightarg = linitial(clause->args);
424 leftarg = lsecond(clause->args);
425 swapped = true;
426 }
427
428
429
430
431
432 leftdatatype = exprType(leftarg);
433 rightdatatype = exprType(rightarg);
434
435
436
437
438
439
440 oproid = get_opfamily_member(opfamilyoid,
441 leftdatatype,
442 rightdatatype,
444 if (!OidIsValid(oproid))
445 elog(ERROR,
446 "no spatial operator found for '%s': opfamily %u type %d",
448 opfamilyoid,
449 leftdatatype);
450
451
452
453
454
455
456
457
459 {
460 Expr *expr;
461 Node *radiusarg = (Node *) list_nth(clause->args, idxfn.
expand_arg-1);
463
464 FuncExpr *expandexpr = makeFuncExpr(expandfn_oid, rightdatatype,
465 list_make2(rightarg, radiusarg),
466 InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL);
467
468
469
470
471
472#if POSTGIS_PGSQL_VERSION >= 140
473 if (!is_pseudo_constant_for_index(req->root, (Node*)expandexpr, req->index))
474#else
475 if (!is_pseudo_constant_for_index((Node*)expandexpr, req->index))
476#endif
477 PG_RETURN_POINTER((Node*)NULL);
478
479
480 expr = make_opclause(oproid, BOOLOID, false,
481 (Expr *) leftarg, (Expr *) expandexpr,
482 InvalidOid, InvalidOid);
483
484 ret = (Node *)(list_make1(expr));
485 }
486
487
488
489
490
491
492 else
493 {
494 Expr *expr;
495
496
497
498
499#if POSTGIS_PGSQL_VERSION >= 140
500 if (!is_pseudo_constant_for_index(req->root, rightarg, req->index))
501#else
502 if (!is_pseudo_constant_for_index(rightarg, req->index))
503#endif
504 PG_RETURN_POINTER((Node*)NULL);
505
506
507
508
509
510
511 if (swapped)
512 {
513 oproid = get_commutator(oproid);
514 if (!OidIsValid(oproid))
515 PG_RETURN_POINTER((Node *)NULL);
516 }
517
518 expr = make_opclause(oproid, BOOLOID, false,
519 (Expr *) leftarg, (Expr *) rightarg,
520 InvalidOid, InvalidOid);
521
522 ret = (Node *)(list_make1(expr));
523 }
524
525
526
527
528
529
530 req->lossy = true;
531
532 PG_RETURN_POINTER(ret);
533 }
534 else
535 {
536 elog(WARNING, "support function '%s' called from unsupported spatial function", __func__);
537 }
538 }
539 }
540
541 PG_RETURN_POINTER(ret);
542}
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)