#10790: Too many joins in a comparison for NULL. -----------------------------+---------------------------------------------- Reporter: mtredinnick | Owner: mtredinnick Status: new | Milestone: Component: ORM aggregation | Version: SVN Keywords: | Stage: Unreviewed Has_patch: 0 | -----------------------------+---------------------------------------------- Using these models: {{{ #!python class Student(models.Model): name = models.CharField(max_length=50)
class Message(models.Model): title = models.CharField(max_length=50) student = models.ForeignKey(Student, null=True) }}} this query generates slightly inefficient SQL: {{{ #!python Message.objects.filter(student=None) }}} We get this {{{ #!sql SELECT `outer_message`.`id`, `outer_message`.`title`, `outer_message`.`student_id` FROM `outer_message` LEFT OUTER JOIN `outer_student` ON (`outer_message`.`student_id` = `outer_student`.`id`) WHERE `outer_student`.`id` IS NULL }}} when we should ideally be using this: {{{ #!sql SELECT `outer_message`.`id`, `outer_message`.`title`, `outer_message`.`student_id` FROM `outer_message` WHERE `outer_message`.`student_id` IS NULL }}} Not worth worrying about for 1.1, since the result isn't incorrect; just less efficient than it could be. Note to self for when fixing this: This is essentially the only situation where we can trim a left outer join from the end of a list of joins. We're comparing to NULL and can factor that back across the outer join. Needs special casing in `Query.add_filter()`. -- Ticket URL: <http://code.djangoproject.com/ticket/10790> Django <http://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 this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---