summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py3
-rw-r--r--django/db/models/sql/query.py8
2 files changed, 7 insertions, 4 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index fc7a7aafae..b321762303 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1127,9 +1127,6 @@ class SQLCompiler:
Backends (e.g. NoSQL) can override this in order to use optimized
versions of "query has any results."
"""
- # This is always executed on a query clone, so we can modify self.query
- self.query.add_extra({'a': 1}, None, None, None, None, None)
- self.query.set_extra_mask(['a'])
return bool(self.execute_sql(SINGLE))
def execute_sql(self, result_type=MULTI, chunked_fetch=False, chunk_size=GET_ITERATOR_CHUNK_SIZE):
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 659fa87314..4648daf395 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -522,7 +522,7 @@ class Query(BaseExpression):
def has_filters(self):
return self.where
- def has_results(self, using):
+ def exists(self):
q = self.clone()
if not q.distinct:
if q.group_by is True:
@@ -533,6 +533,12 @@ class Query(BaseExpression):
q.clear_select_clause()
q.clear_ordering(True)
q.set_limits(high=1)
+ q.add_extra({'a': 1}, None, None, None, None, None)
+ q.set_extra_mask(['a'])
+ return q
+
+ def has_results(self, using):
+ q = self.exists()
compiler = q.get_compiler(using=using)
return compiler.has_results()