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.
2071{
2072 VariableStatData vardata;
2073 Node *other = NULL;
2074 bool varonleft;
2076
2078 float8 selectivity = 0;
2079 Const *otherConst;
2080
2081 POSTGIS_DEBUGF(2, "%s: entered function", __func__);
2082
2083 if (!get_restriction_variable(root, args, varRelid, &vardata, &other, &varonleft))
2084 {
2085 POSTGIS_DEBUGF(2, "%s: could not find vardata", __func__);
2087 }
2088
2089 if (!IsA(other, Const))
2090 {
2091 ReleaseVariableStats(vardata);
2092 POSTGIS_DEBUGF(2,
"%s: no constant argument, returning default selectivity %g", __func__,
DEFAULT_ND_SEL);
2094 }
2095
2096 otherConst = (Const*)other;
2097 if ((!otherConst) || otherConst->constisnull)
2098 {
2099 ReleaseVariableStats(vardata);
2100 POSTGIS_DEBUGF(2, "%s: constant argument is NULL", __func__);
2102 }
2103
2105 {
2106 ReleaseVariableStats(vardata);
2107 POSTGIS_DEBUGF(2, "%s: search box is EMPTY", __func__);
2108 return 0.0;
2109 }
2110
2111 if (!vardata.statsTuple)
2112 {
2113 POSTGIS_DEBUGF(1, "%s: no statistics available on table. Empty? Need to ANALYZE?", __func__);
2115 }
2116
2118 ReleaseVariableStats(vardata);
2120 if (nd_stats)
2121 pfree(nd_stats);
2122
2123 return selectivity;
2124}
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...