mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #30897 -- Added support for ANALYZE option to Queryset.explain() on MariaDB and MySQL 8.0.18+.
This commit is contained in:
committed by
Mariusz Felisiak
parent
742961332e
commit
55df1750be
@@ -117,6 +117,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||
# EXTENDED is deprecated (and not required) in MySQL 5.7.
|
||||
return not self.connection.mysql_is_mariadb and self.connection.mysql_version < (5, 7)
|
||||
|
||||
@cached_property
|
||||
def supports_explain_analyze(self):
|
||||
return self.connection.mysql_is_mariadb or self.connection.mysql_version >= (8, 0, 18)
|
||||
|
||||
@cached_property
|
||||
def supported_explain_formats(self):
|
||||
# Alias MySQL's TRADITIONAL to TEXT for consistency with other
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user