PostGIS 3.7.0dev-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 2066 of file gserialized_estimate.c.

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

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

Referenced by gserialized_gist_sel(), and postgis_index_supportfn().

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