PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ _postgis_gserialized_sel()

Datum _postgis_gserialized_sel ( PG_FUNCTION_ARGS  )

Definition at line 2090 of file gserialized_estimate.c.

References _postgis_gserialized_joinsel(), estimate_selectivity(), gbox_to_string(), PG_FUNCTION_INFO_V1(), pg_get_nd_stats_by_name(), text_p_get_mode(), and text_to_cstring().

Referenced by _postgis_gserialized_stats().

2091 {
2092  Oid table_oid = PG_GETARG_OID(0);
2093  text *att_text = PG_GETARG_TEXT_P(1);
2094  Datum geom_datum = PG_GETARG_DATUM(2);
2095  GBOX gbox; /* search box read from gserialized datum */
2096  float8 selectivity = 0;
2097  ND_STATS *nd_stats;
2098  int mode = 2; /* 2D mode by default */
2099 
2100  /* Check if we've been asked to not use 2d mode */
2101  if ( ! PG_ARGISNULL(3) )
2102  mode = text_p_get_mode(PG_GETARG_TEXT_P(3));
2103 
2104  /* Retrieve the stats object */
2105  nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode, false);
2106 
2107  if ( ! nd_stats )
2108  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text_to_cstring(att_text));
2109 
2110  /* Calculate the gbox */
2111  if ( ! gserialized_datum_get_gbox_p(geom_datum, &gbox) )
2112  elog(ERROR, "unable to calculate bounding box from geometry");
2113 
2114  POSTGIS_DEBUGF(3, " %s", gbox_to_string(&gbox));
2115 
2116  /* Do the estimation */
2117  selectivity = estimate_selectivity(&gbox, nd_stats, mode);
2118 
2119  pfree(nd_stats);
2120  PG_RETURN_FLOAT8(selectivity);
2121 }
char * text_to_cstring(const text *textptr)
static ND_STATS * pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode, bool only_parent)
Pull the stats object from the PgSQL system catalogs.
static int text_p_get_mode(const text *txt)
Utility function to see if the first letter of the mode argument is 'N'.
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:399
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...
N-dimensional statistics structure.
Here is the call graph for this function:
Here is the caller graph for this function: