| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * geo_selfuncs.c |
| 4 | * Selectivity routines registered in the operator catalog in the |
| 5 | * "oprrest" and "oprjoin" attributes. |
| 6 | * |
| 7 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 8 | * Portions Copyright (c) 1994, Regents of the University of California |
| 9 | * |
| 10 | * |
| 11 | * IDENTIFICATION |
| 12 | * src/backend/utils/adt/geo_selfuncs.c |
| 13 | * |
| 14 | * XXX These are totally bogus. Perhaps someone will make them do |
| 15 | * something reasonable, someday. |
| 16 | * |
| 17 | *------------------------------------------------------------------------- |
| 18 | */ |
| 19 | #include "postgres.h" |
| 20 | |
| 21 | #include "utils/builtins.h" |
| 22 | #include "utils/geo_decls.h" |
| 23 | |
| 24 | |
| 25 | /* |
| 26 | * Selectivity functions for geometric operators. These are bogus -- unless |
| 27 | * we know the actual key distribution in the index, we can't make a good |
| 28 | * prediction of the selectivity of these operators. |
| 29 | * |
| 30 | * Note: the values used here may look unreasonably small. Perhaps they |
| 31 | * are. For now, we want to make sure that the optimizer will make use |
| 32 | * of a geometric index if one is available, so the selectivity had better |
| 33 | * be fairly small. |
| 34 | * |
| 35 | * In general, GiST needs to search multiple subtrees in order to guarantee |
| 36 | * that all occurrences of the same key have been found. Because of this, |
| 37 | * the estimated cost for scanning the index ought to be higher than the |
| 38 | * output selectivity would indicate. gistcostestimate(), over in selfuncs.c, |
| 39 | * ought to be adjusted accordingly --- but until we can generate somewhat |
| 40 | * realistic numbers here, it hardly matters... |
| 41 | */ |
| 42 | |
| 43 | |
| 44 | /* |
| 45 | * Selectivity for operators that depend on area, such as "overlap". |
| 46 | */ |
| 47 | |
| 48 | Datum |
| 49 | areasel(PG_FUNCTION_ARGS) |
| 50 | { |
| 51 | PG_RETURN_FLOAT8(0.005); |
| 52 | } |
| 53 | |
| 54 | Datum |
| 55 | areajoinsel(PG_FUNCTION_ARGS) |
| 56 | { |
| 57 | PG_RETURN_FLOAT8(0.005); |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * positionsel |
| 62 | * |
| 63 | * How likely is a box to be strictly left of (right of, above, below) |
| 64 | * a given box? |
| 65 | */ |
| 66 | |
| 67 | Datum |
| 68 | positionsel(PG_FUNCTION_ARGS) |
| 69 | { |
| 70 | PG_RETURN_FLOAT8(0.1); |
| 71 | } |
| 72 | |
| 73 | Datum |
| 74 | positionjoinsel(PG_FUNCTION_ARGS) |
| 75 | { |
| 76 | PG_RETURN_FLOAT8(0.1); |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * contsel -- How likely is a box to contain (be contained by) a given box? |
| 81 | * |
| 82 | * This is a tighter constraint than "overlap", so produce a smaller |
| 83 | * estimate than areasel does. |
| 84 | */ |
| 85 | |
| 86 | Datum |
| 87 | contsel(PG_FUNCTION_ARGS) |
| 88 | { |
| 89 | PG_RETURN_FLOAT8(0.001); |
| 90 | } |
| 91 | |
| 92 | Datum |
| 93 | contjoinsel(PG_FUNCTION_ARGS) |
| 94 | { |
| 95 | PG_RETURN_FLOAT8(0.001); |
| 96 | } |
| 97 | |