#10790: Too many joins in a comparison for NULL.
-------------------------------------+-------------------------------------
     Reporter:  mtredinnick          |                    Owner:
         Type:  Bug                  |  mtredinnick
    Component:  Database layer       |                   Status:  new
  (models, ORM)                      |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by akaariai):

 I have now a working version of join trimming beforehand. The approach
 taken in setup_joins is this:
   1. Walk the lookup path, and turn it into "JoinPath" structures. The
 structures basically tell from which model we are coming from, and to
 which model we are going to, and using which fields. All different join
 types are converted to these simple join structures (m2m, generic relation
 joins etc).
   2. Trim non-necessary joins from the path. This is easy to do at this
 stage.
   3. Generate the actual joins. This again is pretty trivial, just call
 self.join() for the generated joins.

 I think it would be possible to get totally rid of trim_joins(), but it
 seems to do some special trimming which the trim in setup_joins() can't do
 currently. The trimming logic of setup_joins() could be improved easily.

 There were some complications related to generic relations. When fixing
 this I ended up removing the whole process_extra hack. Now the generic
 relations extra join restriction is appended directly into the join
 clause:
 {{{
 JOIN a on (a.id = b.object_id and b.content_type_id = xxx)
 }}}
 This should result in correctly working joins in .exclude() and LEFT OUTER
 JOIN cases, though I haven't added any tests.

 In addition I had to make the m2m through models pickleable. I don't know
 if the approach used was correct, but at least it works.

 Apart of the above there is one test failure. It is related to combining
 ORed queries. In short the combined query now uses LEFT JOIN for one join
 where INNER JOIN would be correct, and the reason for this is that pre-
 patch one join was added, then trimmed (so it was with refcount of 0 in
 the query), but now it is never even added to the query. I think I know
 how to fix this one, but haven't done so yet.

 In total I think the patch is a major cleanup to the join logic, and it
 should allow further improvements if the names_to_path call would be done
 already in add_filter (or even add_q) stage.

 However, there is very little chance this one can ever end up in 1.4. This
 is just too big of a patch. For 1.4 the correct approach will be to teach
 the trim_joins to just trim the extra joins.

 The new patch can be found from:
 https://github.com/akaariai/django/tree/new_10790

-- 
Ticket URL: <https://code.djangoproject.com/ticket/10790#comment:34>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to