#23440: select_related with multiple ForeignKey to same table generates 
sub-optimal
SQL
-------------------------------------+-------------------------------------
     Reporter:  djbug                |                    Owner:  nobody
         Type:                       |                   Status:  closed
  Cleanup/optimization               |                  Version:  1.6
    Component:  Uncategorized        |               Resolution:  invalid
     Severity:  Normal               |             Triage Stage:
     Keywords:  select_related       |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by akaariai):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 I don't think that actually works. Assume the following on node table:
 ||id || name
 ||1  || node 1
 ||2  || node 2

 And relation has one model with left_id = 1 and right_id = 2. Now, the
 second query produces results
 ||id || left_id|| right_id|| node.id || name
 ||1 || 1 || 2 || 1 ||node 1
 ||1 || 1 || 2 || 2 ||node 2

 Which is not the wanted result. Instead we want all the related objects in
 a single row. Trying to collapse the two rows into a single object while
 iterating leads to all sorts of really complex issues which we are not
 going to tackle.

--
Ticket URL: <https://code.djangoproject.com/ticket/23440#comment:2>
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/063.5b94b99cdc60ec191581dd99770a5f85%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to