1
0
mirror of https://github.com/django/django.git synced 2025-07-06 02:39:12 +00:00

queryset-refactor: Fixed the optimization that potentially removes the final

join to handle the case where a to_field attribute is given for the join.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6495 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-10-14 02:15:52 +00:00
parent 425e4662a4
commit 240ecf0811
2 changed files with 15 additions and 17 deletions

View File

@ -576,6 +576,7 @@ class Query(object):
if not null_point and nullable:
null_point = len(join_list)
if connection == OR and not split:
# FIXME: Document what's going on and why this is needed.
if self.alias_map[joins[0]][ALIAS_REFCOUNT] == 1:
split = True
self.promote_alias(joins[0])
@ -595,15 +596,16 @@ class Query(object):
col = target_col or target_field.column
if target_field is opts.pk and join_list:
# An optimization: if the final join is against a primary key,
# we can go back one step in the join chain and compare against
# the lhs of the join instead. The result (potentially) involves
# one less table join.
self.unref_alias(alias)
if join_list:
# An optimization: if the final join is against the same column as
# we are comparing against, we can go back one step in the join
# chain and compare against the lhs of the join instead. The result
# (potentially) involves one less table join.
join = self.alias_map[join_list[-1][-1]][ALIAS_JOIN]
alias = join[LHS_ALIAS]
col = join[LHS_JOIN_COL]
if col == join[RHS_JOIN_COL]:
self.unref_alias(alias)
alias = join[LHS_ALIAS]
col = join[LHS_JOIN_COL]
if (lookup_type == 'isnull' and value is True):
# If the comparison is against NULL, we need to use a left outer

View File

@ -128,19 +128,15 @@ Bug #2253
>>> (q1 & q2).order_by('name')
[<Item: one>]
Bugs #4088 & #4306
Bugs #4088, #4306
>>> Report.objects.filter(creator=1001)
[<Report: r1>]
>>> Report.objects.filter(creator__num=1001)
[<Report: r1>]
# FIXME: The "removing final pk comparison" optimization is biting us here.
# Need to only remove it if the join was also on the pk value.
# >>> Report.objects.filter(creator__id=1001)
# []
# >>> Report.objects.filter(creator__id=a1.id)
# [<Report: r1>]
>>> Report.objects.filter(creator__id=1001)
[]
>>> Report.objects.filter(creator__id=a1.id)
[<Report: r1>]
>>> Report.objects.filter(creator__name='a1')
[<Report: r1>]