Opened 16 years ago
Closed 11 years ago
#11320 closed Cleanup/optimization (fixed)
Over aggressive join promotion with exclude()
Reported by: | Alex Gaynor | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently filter() optimizes it so that when you create a query such that a relation must exist it uses an INNER JOIN, since that's faster than an OUTER JOIN. However with exclude() a query such as:
class MyModel(models.Model): venue = models.ForeignKey("Venue", null=True) MyModel.objects.exclude(venue=None).exclude(venue__name='a')
For this query it should be using an INNER JOIN but instead uses a LEFT OUTER JOIN.
Attachments (1)
Change History (9)
by , 16 years ago
Attachment: | exclude-none-join.diff added |
---|
comment:1 by , 16 years ago
Actually, upon further review my patch is even worse than the comment indicates. The issue is that anything n an exlcude() gets unconditionally promoted to an OUTER JOIN, so my current patch would fail for something like Event.objects.filter(venue__isnull=False).exlcude(venue__name='a')
, because the exclude join promotion doesn't respect anything.
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:7 by , 11 years ago
Has patch: | set |
---|
Patch available from https://github.com/django/django/pull/1883
comment:8 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
First stab at a patch, I think it fails in nested disjunctives and probably other edge cases though.