Datum geometry_gist_sel_2d(PG_FUNCTION_ARGS);
Datum geometry_gist_joinsel_2d(PG_FUNCTION_ARGS);
-Datum geometry_gist_read_selectivity(PG_FUNCTION_ARGS);
Datum geometry_analyze_2d(PG_FUNCTION_ARGS);
Datum geometry_estimated_extent(PG_FUNCTION_ARGS);
+Datum _postgis_geometry_sel(PG_FUNCTION_ARGS);
#if ! REALLY_DO_JOINSEL
* Utility function to read the calculated selectivity for a given search
* box and table/column. Used for debugging the selectivity code.
*/
-PG_FUNCTION_INFO_V1(geometry_gist_read_selectivity);
-Datum geometry_gist_read_selectivity(PG_FUNCTION_ARGS)
+PG_FUNCTION_INFO_V1(_postgis_geometry_sel);
+Datum _postgis_geometry_sel(PG_FUNCTION_ARGS)
{
HeapTuple stats_tuple;
float4 *floatptr;
- Oid table_oid = PG_GETARG_INT32(0);
- int16 attr_num = PG_GETARG_INT32(1);
+ Oid table_oid = PG_GETARG_OID(0);
Datum geom_datum = PG_GETARG_DATUM(2);
+ text *att_text = PG_GETARG_TEXT_P(1);
+ const char *att_name = text2cstring(att_text);
int rv;
GBOX gbox;
int32 nvalues = 0;
float8 selectivity = 0;
+ AttrNumber att_num;
/* Calculate the gbox */
if ( ! gserialized_datum_get_gbox_p(geom_datum, &gbox) )
elog(ERROR, "Unable to calculate bounding box from geometry");
+
+ /* Get the attribute number */
+ att_num = get_attnum(table_oid, att_name);
+ if ( ! att_num )
+ elog(ERROR, "Unable to attribute number for attribute '%s'", att_name);
/* First pull the stats tuple */
- stats_tuple = SearchSysCache2(STATRELATT, ObjectIdGetDatum(table_oid), Int16GetDatum(attr_num));
+ stats_tuple = SearchSysCache2(STATRELATT, table_oid, att_num);
if ( ! stats_tuple )
- elog(ERROR, "Unable to retreive stats tuple for oid(%d) attrnum(%d), run ANALYZE?", table_oid, attr_num);
+ elog(ERROR, "Unable to retreive stats tuple for oid(%d) attrnum(%d), run ANALYZE?", table_oid, att_num);
/* Then read the geom status histogram from that */
rv = get_attstatsslot(stats_tuple, 0, 0, STATISTIC_KIND_GEOMETRY, InvalidOid, NULL, NULL, NULL, &floatptr, &nvalues);
LANGUAGE 'c';
-- Availability: 2.1.0
-CREATE OR REPLACE FUNCTION geometry_gist_read_selectivity(relid oid, attnum int2, geom geometry)
+CREATE OR REPLACE FUNCTION _postgis_geometry_sel(tbl regclass, att_name text, geom geometry)
RETURNS float8
- AS 'MODULE_PATHNAME', 'geometry_gist_read_selectivity'
- LANGUAGE 'c';
-
--- Availability: 2.1.0
-CREATE OR REPLACE FUNCTION geometry_gist_selectivity(schemaname varchar, tablename varchar, attrname varchar, geom geometry)
- RETURNS float8
- AS $$
- DECLARE
- selectivity float8;
- BEGIN
- SELECT geometry_gist_read_selectivity(r.oid, a.attnum, 'SRID=4326;LINESTRING(0 0, 1 1)'::geometry)
- INTO selectivity
- FROM pg_class r
- JOIN pg_attribute a ON (r.oid = a.attrelid)
- JOIN pg_namespace n ON (r.relnamespace = n.oid)
- WHERE n.nspname = $1 AND r.relname = $2 and a.attname = $3;
- IF NOT FOUND THEN
- RAISE EXCEPTION 'Couldn''t find table? column?';
- END IF;
- RETURN selectivity;
- END;
- $$
- LANGUAGE 'plpgsql';
+ AS 'MODULE_PATHNAME', '_postgis_geometry_sel'
+ LANGUAGE 'c' STRICT;