Fixed #28574 -- Added QuerySet.explain().

This commit is contained in:
Tom 2017-09-10 15:34:18 +01:00 committed by Tim Graham
parent df90e462d9
commit c1c163b427
15 changed files with 253 additions and 0 deletions

View file

@ -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