#28146: PostGIS: Django 1.11 adds two extra queries: SELECT
postgis_lib_version()
and SELECT version()
-------------------------------------------+------------------------
Reporter: George Tantiras | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
* Python 3.4.2
* PostgreSQL(9.4.10)
* Database Extensions:
{{{
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.1.4 | public | PostGIS geometry, geography, and raster
spatial types and functions
(2 rows)
}}}
models.py
{{{
from django.contrib.gis.db import models
class TheModel(models.Model):
polygon_area = models.PolygonField()
centroid = models.PointField(srid=4326)
}}}
The code needed to fetch the results:
{{{
>>> from my.models import TheModel
>>> from django.contrib.gis.geos import Point
>>> from django.contrib.gis.measure import D
>>> from django.contrib.gis.db.models.functions import Distance
>>> db.reset_queries()
>>> TheModel.objects.filter(centroid__distance_lte=(Point(23.12, 37.9),
D(m=3000))).annotate(distance=Distance('centroid', Point(23.12,
37.9))).order_by('polygon_area'))
... <QuerySet []>
>>> print(db.connection.queries)
}}}
Django-1.11 result(4 Queries, total time 0.025):
{{{
{'time': '0.003', 'sql': 'SELECT "spatial_ref_sys"."srid",
"spatial_ref_sys"."auth_name", "spatial_ref_sys"."auth_srid",
"spatial_ref_sys"."srtext", "spatial_ref_sys"."proj4text" FROM
"spatial_ref_sys" WHERE "spatial_ref_sys"."srid" = 4326'}
{'time': '0.001', 'sql': 'SELECT version()'}
{'time': '0.014', 'sql': 'SELECT postgis_lib_version()'}
{'time': '0.007', 'sql': 'SELECT "my_themodel"."id",
"my_themodel"."polygon_area", "my_themodel"."centroid",
ST_distance_sphere("my_themodel"."centroid",
ST_GeomFromEWKB(\'\\x0101000020e61000001f85eb51b81e37403333333333f34240\'::bytea))
AS "distance" FROM "my_themodel" WHERE
ST_distance_sphere("my_themodel"."centroid",
ST_GeomFromEWKB(\'\\x0101000020e61000001f85eb51b81e37403333333333f34240\'::bytea))
<= 3000.0 ORDER BY "my_themodel"."polygon_area" ASC LIMIT 21'}
}}}
Django-1.10.7 result (2 queries, total time 0.01):
{{{
{'time': '0.003', 'sql': 'SELECT "spatial_ref_sys"."srid",
"spatial_ref_sys"."auth_name", "spatial_ref_sys"."auth_srid",
"spatial_ref_sys"."srtext", "spatial_ref_sys"."proj4text" FROM
"spatial_ref_sys" WHERE "spatial_ref_sys"."srid" = 4326'}
{'time': '0.007', 'sql': 'SELECT "my_themodel"."id",
"my_themodel"."polygon_area", "my_themodel"."centroid",
ST_distance_sphere("my_themodel"."centroid",
ST_GeomFromEWKB(\'\\x0101000020e61000001f85eb51b81e37403333333333f34240\'::bytea))
AS "distance" FROM "my_themodel" WHERE
ST_distance_sphere("my_themodel"."centroid",
ST_GeomFromEWKB(\'\\x0101000020e61000001f85eb51b81e37403333333333f34240\'::bytea))
<= 3000.0 ORDER BY "my_themodel"."polygon_area" ASC LIMIT 21'}
}}}
After upgrading to Django 1.11, Google spends around 600ms to download the
page which was downloaded in 350ms using Django 1.10.7, as illustrated in
the image below:
[[Image(https://yadi.sk/i/wWAup3MU3HRx9N)]]
--
Ticket URL: <https://code.djangoproject.com/ticket/28146>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.646658075b401c064783ca9f60a7dafe%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.