2176 PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
2178 List *
args = (List *) PG_GETARG_POINTER(2);
2180 int mode = PG_GETARG_INT32(4);
2182 VariableStatData vardata;
2188 float8 selectivity = 0;
2190 POSTGIS_DEBUG(2,
"gserialized_gist_sel called");
2202 if (list_length(args) != 2)
2204 POSTGIS_DEBUG(3,
"gserialized_gist_sel: not a binary opclause");
2209 other = (Node *) linitial(args);
2210 if ( ! IsA(other, Const) )
2212 self = (Var *)other;
2213 other = (Node *) lsecond(args);
2217 self = (Var *) lsecond(args);
2220 if ( ! IsA(other, Const) )
2222 POSTGIS_DEBUG(3,
" no constant arguments - returning a default selectivity");
2227 if( ! gserialized_datum_get_gbox_p(((Const*)other)->constvalue, &search_box) )
2229 POSTGIS_DEBUG(3,
"search box is EMPTY");
2230 PG_RETURN_FLOAT8(0.0);
2232 POSTGIS_DEBUGF(4,
" requested search box is: %s",
gbox_to_string(&search_box));
2235 examine_variable(root, (Node*)
self, 0, &vardata);
2236 if ( vardata.statsTuple ) {
2239 ReleaseVariableStats(vardata);
2243 POSTGIS_DEBUG(3,
" unable to load stats from syscache, not analyzed yet?");
2251 POSTGIS_DEBUGF(3,
" returning computed value: %f", selectivity);
2254 PG_RETURN_FLOAT8(selectivity);
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
#define FALLBACK_ND_SEL
More modest fallback selectivity factor.
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...
static ND_STATS * pg_nd_stats_from_tuple(HeapTuple stats_tuple, int mode)
static char * nd_stats_to_json(const ND_STATS *nd_stats)
Convert an ND_STATS to a JSON representation for external use.
N-dimensional statistics structure.
#define DEFAULT_ND_SEL
Default geometry selectivity factor.