#29271: Chaining Filters on a Reverse Foreign Key Produces Multiple Joins
-------------------------------------+-------------------------------------
     Reporter:  Michael MacIntosh    |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  2.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  filter chain         |             Triage Stage:
  reverse foreign key                |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 Timothy,

 > That behavior is not only unexpected and undocumented, but never useful.

 I agree with you, so does all all the folks subscribed to #10060.

 But in order to deprecate the current behavior and automatically perform a
 subquery pushdown we need an alternative to point the user at when such
 events are detected.

 There is ungoing work to allow aggregations to be performed using as
 subquery which is on my radar for review (#28296) and is something we
 could direct the user at. Until this lands there's no alternative we can
 point the user at during following theoretical deprecation period where we
 warn about this behavior and how it would change in future versions of
 Django.

 In this particual case I guess we could point users at something like
 `.filter(Exists(Q(multi_valued__foo="bar")))` when
 `.filter(multi_valued__foo="bar")` is used if we added support for
 `Exist(Q)` or `.filter(multi_valued__exists=Q(foo="bar"))` but that's
 tricky because [https://en.wikipedia.org/wiki/Correlated_subquery some
 database engine are really bad with correlated subqueries] (e.g. MySQL
 5.6) so while the results would be more correct it could a ticking bomb
 that reveals itself only in production.

 In the mean time I'd restate that a mention in the documentation couldn't
 hurt. Would you be able to propose an admonition Timothy?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29271#comment:8>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.b6482dc34b7bbf966f9c4112c1d37bfe%40djangoproject.com.

Reply via email to