﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27448	GIS distance queries use deprecated ST_distance_sphere	Christian von Roques	Mjumbe Poe	"When using `django.contrib.gis` with PostGIS 2.3.0, distance queries will create SQL using the `ST_distance_sphere` function, which is deprecated since PostGIS 2.2.0 (see http://trac.osgeo.org/postgis/ticket/2748 ). The old function still works, but now issues a deprecation-warning. The problem is that `ST_distance_sphere` has become more than 40× slower than its replacement `ST_DistanceSphere` due to the added deprecation warning.

My `city_cities` table has 143260 rows. The following query executes in about 7.5 seconds:
{{{#!sql
SELECT min(ST_distance_sphere(ST_Point(0,0), location)) FROM cities_city;
}}}
Whereas the same query with `ST_DistanceSphere` instead of `ST_distance_sphere` completes in less than 170ms.

I've prepared a patch to stop Django from using the deprecated functions. https://github.com/roques/django/tree/postgis22_deprecated The problem with this patch is that the non-deprecated functions only became available with PostGIS 2.2.0 and thus the patch would raise the minimum required PostGIS version from 2.1.0.

As I can see the situation, we have a choice between the following three scenarios:

1. Raise the required version of PostGIS from 2.1.0 to 2.2.0 and use the non-deprecated functions.
2. Keep using the deprecated functions and live with all distance queries being often unusably slow.
3. Complicate the code to detect the PostGIS version and use `ST_DistanceSphere` when available or `ST_distance_sphere` otherwise.

I would prefer option 1, but people stuck with PostGIS <2.2.0 would then be unable to make distance queries with newer releases of Django."	Cleanup/optimization	closed	GIS	dev	Normal	fixed	GIS distance deprecated ST_distance_sphere	Christian von Roques	Ready for checkin	1	0	0	0	0	0
