PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ _postgis_gserialized_sel()

Datum _postgis_gserialized_sel ( PG_FUNCTION_ARGS  )

Definition at line 1943 of file gserialized_estimate.c.

1944{
1945 Oid table_oid = PG_GETARG_OID(0);
1946 text *att_text = PG_GETARG_TEXT_P(1);
1947 Datum geom_datum = PG_GETARG_DATUM(2);
1948 GBOX gbox; /* search box read from gserialized datum */
1949 float8 selectivity = 0;
1950 ND_STATS *nd_stats;
1951 int mode = 2; /* 2D mode by default */
1952
1953 /* Check if we've been asked to not use 2d mode */
1954 if ( ! PG_ARGISNULL(3) )
1955 mode = text_p_get_mode(PG_GETARG_TEXT_P(3));
1956
1957 /* Retrieve the stats object */
1958 nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode, false);
1959
1960 if ( ! nd_stats )
1961 elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text_to_cstring(att_text));
1962
1963 /* Calculate the gbox */
1964 if ( ! gserialized_datum_get_gbox_p(geom_datum, &gbox) )
1965 elog(ERROR, "unable to calculate bounding box from geometry");
1966
1967 POSTGIS_DEBUGF(3, " %s", gbox_to_string(&gbox));
1968
1969 /* Do the estimation */
1970 selectivity = estimate_selectivity(&gbox, nd_stats, mode);
1971
1972 pfree(nd_stats);
1973 PG_RETURN_FLOAT8(selectivity);
1974}
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition gbox.c:404
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...
static int text_p_get_mode(const text *txt)
Utility function to see if the first letter of the mode argument is 'N'.
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.
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 estimate_selectivity(), gbox_to_string(), gserialized_datum_get_gbox_p(), pg_get_nd_stats_by_name(), and text_p_get_mode().

Here is the call graph for this function: