2217 PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
2219 List *
args = (List *) PG_GETARG_POINTER(2);
2221 int mode = PG_GETARG_INT32(4);
2223 VariableStatData vardata;
2229 float8 selectivity = 0;
2231 POSTGIS_DEBUG(2,
"gserialized_gist_sel called");
2243 if (list_length(
args) != 2)
2245 POSTGIS_DEBUG(3,
"gserialized_gist_sel: not a binary opclause");
2250 other = (Node *) linitial(
args);
2251 if ( ! IsA(other, Const) )
2253 self = (Var *)other;
2254 other = (Node *) lsecond(
args);
2258 self = (Var *) lsecond(
args);
2261 if ( ! IsA(other, Const) )
2263 POSTGIS_DEBUG(3,
" no constant arguments - returning a default selectivity");
2268 if( ! gserialized_datum_get_gbox_p(((Const*)other)->constvalue, &search_box) )
2270 POSTGIS_DEBUG(3,
"search box is EMPTY");
2271 PG_RETURN_FLOAT8(0.0);
2273 POSTGIS_DEBUGF(4,
" requested search box is: %s",
gbox_to_string(&search_box));
2276 examine_variable(root, (Node*)
self, 0, &vardata);
2277 if ( vardata.statsTuple ) {
2280 ReleaseVariableStats(vardata);
2284 POSTGIS_DEBUG(3,
" unable to load stats from syscache, not analyzed yet?");
2292 POSTGIS_DEBUGF(3,
" returning computed value: %f", selectivity);
2295 PG_RETURN_FLOAT8(selectivity);
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
static char * nd_stats_to_json(const ND_STATS *nd_stats)
Convert an ND_STATS to a JSON representation for external use.
static float8 estimate_selectivity(const GBOX *box, const ND_STATS *nd_stats, int mode)
This function returns an estimate of the selectivity of a search GBOX by looking at data in the ND_ST...
#define FALLBACK_ND_SEL
More modest fallback selectivity factor.
#define DEFAULT_ND_SEL
Default geometry selectivity factor.
static ND_STATS * pg_nd_stats_from_tuple(HeapTuple stats_tuple, int mode)
N-dimensional statistics structure.