From 2470756de0b21c1ff15758a88e167d08da23e5f7 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Sat, 2 Sep 2017 22:39:51 +0200 Subject: [PATCH] Moved select_sql in SQLCompiler.get_extra_select() to improve performance. --- django/db/models/sql/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 2afc3635fa..743803338b 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -357,8 +357,8 @@ class SQLCompiler: def get_extra_select(self, order_by, select): extra_select = [] - select_sql = [t[1] for t in select] if self.query.distinct and not self.query.distinct_fields: + select_sql = [t[1] for t in select] for expr, (sql, params, is_ref) in order_by: without_ordering = self.ordering_parts.search(sql).group(1) if not is_ref and (without_ordering, params) not in select_sql: