-
-
Notifications
You must be signed in to change notification settings - Fork 405
Allow wfs_use_default_extent_for_getfeature for MSSQL Driver #5994
Description
I've been looking to optimise WFS 2.0 MapServer queries using the MSSQL driver and one change would greatly improve query speeds would be to disable the default spatial query. This probably applies to other database drivers such as Postgres and Oracle.
The "wfs_use_default_extent_for_getfeature" was implemented with 45037eb for OGR data sources as documented at https://mapserver.org/el/ogc/wfs_server.html#layer-object
If no spatial filter is passed to a WFS GetFeature the bbox of the map is added to the WHERE clause in SQL Server:
GEOM.STIntersects(geometry::STGeomFromText('POLYGON((-826053.00001 7143520.99999,-719272.99999 7143520.99999,-719272.99999 7257149.00001,-826053.00001 7257149.00001,-826053.00001 7143520.99999))',3857)) = 1 )
This can greatly slow down the query, and as the bbox is set to the extent of all data in the MAP serves no purpose (in this case).
In addition, if "wfs_compute_number_matched" is set to "true" to get the feature count the default spatial bbox is added to get the count, which has a further impact on performance. Queries such as the following are created:
SELECT count(*) FROM (select * from cities) as foo WHERE ogr_geometry.MakeValid().STIntersects(geometry::STGeomFromText('POLYGON((-826053.00001 7143520.99999,-719272.99999 7143520.99999,-719272.99999 7257149.00001,-826053.00001 7257149.00001,-826053.00001 7143520.99999))',3857)) = 1 )
This SQL is generated in mapmssql2008.c in the msMSSQL2008LayerGetShapeCount function.
Again the spatial filter will not filter out any records, but greatly increases the running time of a query.