PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ 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 2239 of file gserialized_estimate.c.

2240 {
2241  VariableStatData vardata;
2242  Node *other = NULL;
2243  bool varonleft;
2244  ND_STATS *nd_stats = NULL;
2245 
2246  GBOX search_box;
2247  float8 selectivity = 0;
2248  Const *otherConst;
2249 
2250  POSTGIS_DEBUGF(2, "%s: entered function", __func__);
2251 
2252  if (!get_restriction_variable(root, args, varRelid, &vardata, &other, &varonleft))
2253  {
2254  POSTGIS_DEBUGF(2, "%s: could not find vardata", __func__);
2255  return DEFAULT_ND_SEL;
2256  }
2257 
2258  if (!IsA(other, Const))
2259  {
2260  ReleaseVariableStats(vardata);
2261  POSTGIS_DEBUGF(2, "%s: no constant argument, returning default selectivity %g", __func__, DEFAULT_ND_SEL);
2262  return DEFAULT_ND_SEL;
2263  }
2264 
2265  otherConst = (Const*)other;
2266  if ((!otherConst) || otherConst->constisnull)
2267  {
2268  ReleaseVariableStats(vardata);
2269  POSTGIS_DEBUGF(2, "%s: constant argument is NULL", __func__);
2270  return DEFAULT_ND_SEL;
2271  }
2272 
2273  if (!gserialized_datum_get_gbox_p(otherConst->constvalue, &search_box))
2274  {
2275  ReleaseVariableStats(vardata);
2276  POSTGIS_DEBUGF(2, "%s: search box is EMPTY", __func__);
2277  return 0.0;
2278  }
2279 
2280  if (!vardata.statsTuple)
2281  {
2282  POSTGIS_DEBUGF(1, "%s: no statistics available on table. Empty? Need to ANALYZE?", __func__);
2283  return DEFAULT_ND_SEL;
2284  }
2285 
2286  nd_stats = pg_nd_stats_from_tuple(vardata.statsTuple, mode);
2287  ReleaseVariableStats(vardata);
2288  selectivity = estimate_selectivity(&search_box, nd_stats, mode);
2289  if (nd_stats) pfree(nd_stats);
2290  return selectivity;
2291 }
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)
int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox)
Given a GSERIALIZED datum, as quickly as possible (peaking into the top of the memory) return the gbo...
args
Definition: ovdump.py:45
N-dimensional statistics structure.

References ovdump::args, DEFAULT_ND_SEL, estimate_selectivity(), gserialized_datum_get_gbox_p(), 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: