#30256: autocomplete_fields cause one or two extra queries for each field wth
foreign key or many to many relation
-------------------------------------+-------------------------------------
     Reporter:  George Tantiras      |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  contrib.admin        |                  Version:  2.1
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by George Tantiras):

 Hallo, thank you for the response.

 It took me some hours to understand why I could not reproduce the above in
 the project I uploaded, [https://github.com/raratiru/autobug  autobug app
 ] :

 The answer is that the queries are reduced in PostgreSQL and not in
 SQLite.

 I incorporated the debug toolbar in that project and arranged it to use a
 Postgresql database with
 [https://github.com/raratiru/autobug/blob/master/autobug/settings.py#L81
 those credentials].

 I uploaded the `queries*.txt` files which report all the queries from
 debug toolbar either with their full traceback or only the queries.

 I also uploaded a db.json file with all the database contents in json
 format.

 Here, I paste the queries for the url
 http://127.0.0.1:8000/admin/inl/child3/1/change/.

 The url http://127.0.0.1:8000/admin/inl/master/1/change/  has many more
 queries because it includes all other models as inlines.

 [https://github.com/raratiru/autobug/blob/master/queries_only_django-
 autocomplete.txt The queries]:
 Those first 4 queries are common for all three occasions (django-
 autocomplete, autocomplete-light, no autocomplete at all):


 {{{
 SELECT "django_session"."session_key", "django_session"."session_data",
 "django_session"."expire_date" FROM "django_session" WHERE
 ("django_session"."expire_date" >
 '2019-03-21T15:07:04.528846+00:00'::timestamptz AND
 "django_session"."session_key" = 'ku98yfv1ublrcwkqfqtguhw5a886241r')

 SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login",
 "auth_user"."is_superuser", "auth_user"."username",
 "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email",
 "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined"
 FROM "auth_user" WHERE "auth_user"."id" = 1

 SELECT "inl_child3"."id", "inl_child3"."key_id", "inl_child3"."boolean"
 FROM "inl_child3" WHERE "inl_child3"."id" = 1

 SELECT "inl_child2"."id", "inl_child2"."key_id", "inl_child2"."boolean",
 "inl_child2"."child_key_id" FROM "inl_child2" INNER JOIN
 "inl_child3_child_keys" ON ("inl_child2"."id" =
 "inl_child3_child_keys"."child2_id") WHERE
 "inl_child3_child_keys"."child3_id" = 1
 }}}

 The following 2 queries are added from django-autocomplete only:

 {{{
 SELECT "inl_master"."id" FROM "inl_master" WHERE "inl_master"."id" IN (1)

 SELECT "inl_child2"."id", "inl_child2"."key_id", "inl_child2"."boolean",
 "inl_child2"."child_key_id" FROM "inl_child2" WHERE "inl_child2"."id" IN
 (2, 5, 3, 1, 4)
 }}}

 The complete traceback cam be found in
 [https://github.com/raratiru/autobug/blob/master/queries_django-
 autocomplete.txt this file].

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30256#comment:5>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.5151eafb30886a5a906af3d7f6cdb186%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to