summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/operations.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/mysql/operations.py')
-rw-r--r--django/db/backends/mysql/operations.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index ef5d23214e..b801afef4a 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -299,11 +299,16 @@ class DatabaseOperations(BaseDatabaseOperations):
elif not format and 'TREE' in self.connection.features.supported_explain_formats:
# Use TREE by default (if supported) as it's more informative.
format = 'TREE'
+ analyze = options.pop('analyze', False)
prefix = super().explain_query_prefix(format, **options)
- if format:
+ if analyze and self.connection.features.supports_explain_analyze:
+ # MariaDB uses ANALYZE instead of EXPLAIN ANALYZE.
+ prefix = 'ANALYZE' if self.connection.mysql_is_mariadb else prefix + ' ANALYZE'
+ if format and not (analyze and not self.connection.mysql_is_mariadb):
+ # Only MariaDB supports the analyze option with formats.
prefix += ' FORMAT=%s' % format
- if self.connection.features.needs_explain_extended and format is None:
- # EXTENDED and FORMAT are mutually exclusive options.
+ if self.connection.features.needs_explain_extended and not analyze and format is None:
+ # ANALYZE, EXTENDED, and FORMAT are mutually exclusive options.
prefix += ' EXTENDED'
return prefix