#17276: Slow anti-join query against Postgres -------------------------------------+------------------------------------- Reporter: dmitry@… | Owner: nobody Type: | Status: new Cleanup/optimization | Version: 1.3 Component: Database layer | Resolution: (models, ORM) | Triage Stage: Accepted Severity: Normal | Needs documentation: 0 Keywords: orm, postgres, | Patch needs improvement: 0 join, anti-join | UI/UX: 0 Has patch: 0 | Needs tests: 0 | Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by dberansky): I realized over the weekend that the same issue exists for one-to-many relationships. For example, consider these models: {{{ class Parent(models.Model): name = models.CharField(max_length=100) class Child(models.Model): name = models.CharField(max_length=200) parents = models.ForeignKey(to=Parent, db_column="parent_id") }}} and the following Django query: {{{ Parent.objects.filter(child__isnull=True) }}} for which Django will generate this SQL: {{{ SELECT "demo_parent"."id", "demo_parent"."name" FROM "demo_parent" LEFT OUTER JOIN "demo_child" ON ("demo_parent"."id" = "demo_child"."parent_id") WHERE "demo_child"."id" IS NULL }}} So the same issue as with many-to-many where this query is orders of magnitude slower than a slightly modified one: {{{ SELECT "demo_parent"."id", "demo_parent"."name" FROM "demo_parent" LEFT OUTER JOIN "demo_child" ON ("demo_parent"."id" = "demo_child"."parent_id") WHERE "demo_child"."parent_id" IS NULL }}} ('WHERE "demo_child"."__parent_id__" IS NULL' vs. 'WHERE "demo_child"."__id__" IS NULL') -- Ticket URL: <https://code.djangoproject.com/ticket/17276#comment:4> 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 this group at http://groups.google.com/group/django-updates?hl=en.