We'll need your model definitions in order to help much. On Wed, Feb 17, 2010 at 2:54 PM, Steve <[email protected]> wrote: > Hello all, > > I believe select_related is creating some extraneous joins in situations > where one is joining child models from a base model (model inheritance). > > Take the following SQL generated (dpaste here, probably more readable > http://dpaste.com/160677/) > > ==== > > SELECT (fields) FROM `base_contact` > > > LEFT OUTER JOIN `consumer_consumer` ON (`base_contact`.`consumer_id` = > `consumer_consumer`.`id`) # ok > > > INNER JOIN `agency_program` ON (`base_contact`.`program_id` = > `agency_program`.`id`) # ok > > > LEFT OUTER JOIN `consumer_contact` ON (`base_contact`.`id` = > `consumer_contact`.`base_id`) # ok > > > INNER JOIN `base_contact` T5 ON (`consumer_contact`.`base_id` = T5.`id`) # > ?!? > > > # These next two are questionable, since they are joined on a LEFT OUTER (so > they may potentially not be there) > > > INNER JOIN `consumer_service` ON (`consumer_contact`.`service_id` = > `consumer_service`.`id`) > > > INNER JOIN `consumer_servicetype` ON (`consumer_service`.`type_id` = > `consumer_servicetype`.`id`) > > > LEFT OUTER JOIN `IR_contact` ON (`base_contact`.`id` = > `IR_contact`.`base_id`) # ok > > > INNER JOIN `base_contact` T9 ON (`IR_contact`.`base_id` = T9.`id`) # ?!? > > > WHERE `consumer_consumer`.`file` = 06-1757 ORDER BY `base_contact`.`date` > DESC > > > ==== > > There are two joins I simply can't explain (marked "?!?"). Removing them > gives me my expected results. select_related in on case seems to correctly > create a LEFT OUTER, but then follows up by creating an unwanted INNER. > > Keep in mind I made a note about the 'questionable' join above, but even > removing that entirely creates the same problem. > > I'll be glad to file a ticket, if the issue is something other than my > ignorance. > > -Steve > > -- > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/django-developers?hl=en. >
-- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
