PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum _postgis_gserialized_sel ( PG_FUNCTION_ARGS  )

Definition at line 1957 of file gserialized_estimate.c.

References estimate_selectivity(), gbox_to_string(), pg_get_nd_stats_by_name(), text2cstring(), and text_p_get_mode().

1958 {
1959  Oid table_oid = PG_GETARG_OID(0);
1960  text *att_text = PG_GETARG_TEXT_P(1);
1961  Datum geom_datum = PG_GETARG_DATUM(2);
1962  GBOX gbox; /* search box read from gserialized datum */
1963  float8 selectivity = 0;
1964  ND_STATS *nd_stats;
1965  int mode = 2; /* 2D mode by default */
1966 
1967  /* Check if we've been asked to not use 2d mode */
1968  if ( ! PG_ARGISNULL(3) )
1969  mode = text_p_get_mode(PG_GETARG_TEXT_P(3));
1970 
1971  /* Retrieve the stats object */
1972  nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode);
1973 
1974  if ( ! nd_stats )
1975  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text2cstring(att_text));
1976 
1977  /* Calculate the gbox */
1978  if ( ! gserialized_datum_get_gbox_p(geom_datum, &gbox) )
1979  elog(ERROR, "unable to calculate bounding box from geometry");
1980 
1981  POSTGIS_DEBUGF(3, " %s", gbox_to_string(&gbox));
1982 
1983  /* Do the estimation */
1984  selectivity = estimate_selectivity(&gbox, nd_stats, mode);
1985 
1986  pfree(nd_stats);
1987  PG_RETURN_FLOAT8(selectivity);
1988 }
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:369
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...
char * text2cstring(const text *textptr)
static ND_STATS * pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode)
Pull the stats object from the PgSQL system catalogs.
N-dimensional statistics structure.

Here is the call graph for this function: