summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorTom <tom@tomforb.es>2017-09-10 15:34:18 +0100
committerTim Graham <timograham@gmail.com>2018-04-19 10:52:19 -0400
commitc1c163b42717ed5e051098ebf0e2f5c77810f20e (patch)
treeb3c42bcf178fe8f33394f41252a92238cb8baff3 /django/db/models/sql/query.py
parentdf90e462d91d3a77aa89b69d791bf17c2bf7ff9b (diff)
Fixed #28574 -- Added QuerySet.explain().
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 3756ecbb5d..995e89564d 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -223,6 +223,10 @@ class Query:
self._filtered_relations = {}
+ self.explain_query = False
+ self.explain_format = None
+ self.explain_options = {}
+
@property
def extra(self):
if self._extra is None:
@@ -511,6 +515,14 @@ class Query:
compiler = q.get_compiler(using=using)
return compiler.has_results()
+ def explain(self, using, format=None, **options):
+ q = self.clone()
+ q.explain_query = True
+ q.explain_format = format
+ q.explain_options = options
+ compiler = q.get_compiler(using=using)
+ return '\n'.join(compiler.explain_query())
+
def combine(self, rhs, connector):
"""
Merge the 'rhs' query into the current one (with any 'rhs' effects