Skip to content

Commit

Permalink
Reverted "Refs #20939 -- Moved subquery ordering clearing optimizatio…
Browse files Browse the repository at this point in the history
…n to the __in lookup."

This reverts commit e62ea0b since it
broke multi-column __in lookups and _meta.order_wrt on Oracle.
  • Loading branch information
charettes authored and timgraham committed Apr 28, 2017
1 parent f32ee6d commit eb4724a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 3 additions & 12 deletions django/db/models/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,9 @@ def process_rhs(self, compiler, connection):
placeholder = '(' + ', '.join(sqls) + ')'
return (placeholder, sqls_params)
else:
from django.db.models.sql.query import Query # avoid circular import
if isinstance(self.rhs, Query):
query = self.rhs
# It's safe to drop ordering if the queryset isn't using
# slicing, distinct(*fields), or select_for_update().
if (query.low_mark == 0 and query.high_mark is None and
not query.distinct_fields and
not query.select_for_update):
query.clear_ordering(True)
if not query.has_select_fields:
query.clear_select_clause()
query.add_fields(['pk'])
if not getattr(self.rhs, 'has_select_fields', True):
self.rhs.clear_select_clause()
self.rhs.add_fields(['pk'])
return super().process_rhs(compiler, connection)

def get_rhs_op(self, connection, rhs):
Expand Down
6 changes: 6 additions & 0 deletions django/db/models/sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,12 @@ def resolve_expression(self, query, *args, **kwargs):
# Subqueries need to use a different set of aliases than the outer query.
clone.bump_prefix(query)
clone.subquery = True
# It's safe to drop ordering if the queryset isn't using slicing,
# distinct(*fields) or select_for_update().
if (self.low_mark == 0 and self.high_mark is None and
not self.distinct_fields and
not self.select_for_update):
clone.clear_ordering(True)
return clone

def prepare_lookup_value(self, value, lookups, can_reuse, allow_joins=True):
Expand Down

0 comments on commit eb4724a

Please sign in to comment.