#28561: .order_by('foo__id') doesn't create a join
------------------------------------------------+------------------------
               Reporter:  Marten Kenbeek        |          Owner:  nobody
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  Documentation         |        Version:  1.11
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  1
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 The documentation on `order_by()` states:

 > It is also possible to order a queryset by a related field, without
 incurring the cost of a JOIN, by referring to the _id of the related
 field:
 > {{{
 > # No Join
 > Entry.objects.order_by('blog_id')
 >
 > # Join
 > Entry.objects.order_by('blog__id')
 > }}}

 However, in recent versions the latter query is optimised and won't create
 a join:

 {{{
 >>> print(Bar.objects.order_by('foo__id').query)
 SELECT "foo_bar"."id", "foo_bar"."foo_id" FROM "foo_bar" ORDER BY
 "foo_bar"."foo_id" ASC
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28561>
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/047.6cfb141958782c00fd3e6d78b26eb394%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to