mirror of
https://github.com/django/django.git
synced 2025-07-06 18:59:13 +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:
parent
425e4662a4
commit
240ecf0811
@ -576,6 +576,7 @@ class Query(object):
|
|||||||
if not null_point and nullable:
|
if not null_point and nullable:
|
||||||
null_point = len(join_list)
|
null_point = len(join_list)
|
||||||
if connection == OR and not split:
|
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:
|
if self.alias_map[joins[0]][ALIAS_REFCOUNT] == 1:
|
||||||
split = True
|
split = True
|
||||||
self.promote_alias(joins[0])
|
self.promote_alias(joins[0])
|
||||||
@ -595,13 +596,14 @@ class Query(object):
|
|||||||
|
|
||||||
col = target_col or target_field.column
|
col = target_col or target_field.column
|
||||||
|
|
||||||
if target_field is opts.pk and join_list:
|
if join_list:
|
||||||
# An optimization: if the final join is against a primary key,
|
# An optimization: if the final join is against the same column as
|
||||||
# we can go back one step in the join chain and compare against
|
# we are comparing against, we can go back one step in the join
|
||||||
# the lhs of the join instead. The result (potentially) involves
|
# chain and compare against the lhs of the join instead. The result
|
||||||
# one less table join.
|
# (potentially) involves one less table join.
|
||||||
self.unref_alias(alias)
|
|
||||||
join = self.alias_map[join_list[-1][-1]][ALIAS_JOIN]
|
join = self.alias_map[join_list[-1][-1]][ALIAS_JOIN]
|
||||||
|
if col == join[RHS_JOIN_COL]:
|
||||||
|
self.unref_alias(alias)
|
||||||
alias = join[LHS_ALIAS]
|
alias = join[LHS_ALIAS]
|
||||||
col = join[LHS_JOIN_COL]
|
col = join[LHS_JOIN_COL]
|
||||||
|
|
||||||
|
@ -128,19 +128,15 @@ Bug #2253
|
|||||||
>>> (q1 & q2).order_by('name')
|
>>> (q1 & q2).order_by('name')
|
||||||
[<Item: one>]
|
[<Item: one>]
|
||||||
|
|
||||||
Bugs #4088 & #4306
|
Bugs #4088, #4306
|
||||||
>>> Report.objects.filter(creator=1001)
|
>>> Report.objects.filter(creator=1001)
|
||||||
[<Report: r1>]
|
[<Report: r1>]
|
||||||
>>> Report.objects.filter(creator__num=1001)
|
>>> Report.objects.filter(creator__num=1001)
|
||||||
[<Report: r1>]
|
[<Report: r1>]
|
||||||
|
>>> Report.objects.filter(creator__id=1001)
|
||||||
# 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=a1.id)
|
||||||
# >>> Report.objects.filter(creator__id=1001)
|
[<Report: r1>]
|
||||||
# []
|
|
||||||
# >>> Report.objects.filter(creator__id=a1.id)
|
|
||||||
# [<Report: r1>]
|
|
||||||
|
|
||||||
>>> Report.objects.filter(creator__name='a1')
|
>>> Report.objects.filter(creator__name='a1')
|
||||||
[<Report: r1>]
|
[<Report: r1>]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user