PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ gserialized_sel_internal()

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 overlap check ( it's the restrict function for the && operator )

It can make use (if available) of the statistics collected by the geometry analyzer function.

Note that the good work is done by estimate_selectivity() above. This function just tries to find the search_box, loads the statistics and invoke the work-horse.

Definition at line 2229 of file gserialized_estimate.c.

2230{
2231 VariableStatData vardata;
2232 Node *other = NULL;
2233 bool varonleft;
2234 ND_STATS *nd_stats = NULL;
2235
2236 GBOX search_box;
2237 float8 selectivity = 0;
2238 Const *otherConst;
2239
2240 POSTGIS_DEBUGF(2, "%s: entered function", __func__);
2241
2242 if (!get_restriction_variable(root, args, varRelid, &vardata, &other, &varonleft))
2243 {
2244 POSTGIS_DEBUGF(2, "%s: could not find vardata", __func__);
2245 return DEFAULT_ND_SEL;
2246 }
2247
2248 if (!IsA(other, Const))
2249 {
2250 ReleaseVariableStats(vardata);
2251 POSTGIS_DEBUGF(2, "%s: no constant argument, returning default selectivity %g", __func__, DEFAULT_ND_SEL);
2252 return DEFAULT_ND_SEL;
2253 }
2254
2255 otherConst = (Const*)other;
2256 if ((!otherConst) || otherConst->constisnull)
2257 {
2258 ReleaseVariableStats(vardata);
2259 POSTGIS_DEBUGF(2, "%s: constant argument is NULL", __func__);
2260 return DEFAULT_ND_SEL;
2261 }
2262
2263 if (!gserialized_datum_get_gbox_p(otherConst->constvalue, &search_box))
2264 {
2265 ReleaseVariableStats(vardata);
2266 POSTGIS_DEBUGF(2, "%s: search box is EMPTY", __func__);
2267 return 0.0;
2268 }
2269
2270 if (!vardata.statsTuple)
2271 {
2272 POSTGIS_DEBUGF(1, "%s: no statistics available on table. Empty? Need to ANALYZE?", __func__);
2273 return DEFAULT_ND_SEL;
2274 }
2275
2276 nd_stats = pg_nd_stats_from_tuple(vardata.statsTuple, mode);
2277 ReleaseVariableStats(vardata);
2278 selectivity = estimate_selectivity(&search_box, nd_stats, mode);
2279 pfree(nd_stats);
2280 return selectivity;
2281}
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 DEFAULT_ND_SEL
Default geometry selectivity factor.
static ND_STATS * pg_nd_stats_from_tuple(HeapTuple stats_tuple, int mode)
N-dimensional statistics structure.

References DEFAULT_ND_SEL, estimate_selectivity(), and pg_nd_stats_from_tuple().

Referenced by gserialized_gist_sel().

Here is the call graph for this function:
Here is the caller graph for this function: