Ticket #12567: 12567.2.diff

File 12567.2.diff, 1.8 KB (added by coleifer, 15 years ago)

updated patch to respect query optimization on isnull=False & inner joins

  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index dde1494..f50c219 100644
    a b class Query(object):  
    10151015
    10161016        # Process the join list to see if we can remove any inner joins from
    10171017        # the far end (fewer tables in a query is better).
    1018         col, alias, join_list = self.trim_joins(target, join_list, last, trim)
     1018        if (lookup_type == 'isnull' and value is False and not negate and
     1019                len(join_list) > 1):
     1020            col = target.column
     1021            alias = join_list[-1]
     1022        else:
     1023            col, alias, join_list = self.trim_joins(target, join_list, last, trim)
    10191024
    10201025        if connector == OR:
    10211026            # Some joins may need to be promoted when adding a new filter to a
  • tests/regressiontests/model_inheritance_regress/models.py

    diff --git a/tests/regressiontests/model_inheritance_regress/models.py b/tests/regressiontests/model_inheritance_regress/models.py
    index c669b23..c3a8c07 100644
    a b import datetime  
    66
    77from django.db import models
    88
    9 # Python 2.3 doesn't have sorted()
    10 try:
    11     sorted
    12 except NameError:
    13     from django.utils.itercompat import sorted
    149
    1510class Place(models.Model):
    1611    name = models.CharField(max_length=50)
    AttributeError: 'Person' object has no attribute 'messybachelorparty_set'  
    385380>>> p4.bachelorparty_set.all()
    386381[<BachelorParty: Bachelor party for Bob>, <BachelorParty: Bachelor party for Dave>]
    387382
    388 """}
     383# This works
     384>>> Place.objects.exclude(restaurant=None)
     385[<Place:  the place>]
    389386
     387# ... and this doesn't.
     388>>> Place.objects.filter(restaurant__isnull=False)
     389[<Place:  the place>]
     390"""}
Back to Top