mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #30897 -- Added support for TREE format to Queryset.explain() on MySQL 8.0.16+.
This commit is contained in:
committed by
Mariusz Felisiak
parent
37f02c47f8
commit
742961332e
@@ -48,8 +48,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||
END;
|
||||
"""
|
||||
db_functions_convert_bytes_to_str = True
|
||||
# Alias MySQL's TRADITIONAL to TEXT for consistency with other backends.
|
||||
supported_explain_formats = {'JSON', 'TEXT', 'TRADITIONAL'}
|
||||
# Neither MySQL nor MariaDB support partial indexes.
|
||||
supports_partial_indexes = False
|
||||
|
||||
@@ -119,6 +117,15 @@ 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 supported_explain_formats(self):
|
||||
# Alias MySQL's TRADITIONAL to TEXT for consistency with other
|
||||
# backends.
|
||||
formats = {'JSON', 'TEXT', 'TRADITIONAL'}
|
||||
if not self.connection.mysql_is_mariadb and self.connection.mysql_version >= (8, 0, 16):
|
||||
formats.add('TREE')
|
||||
return formats
|
||||
|
||||
@cached_property
|
||||
def supports_transactions(self):
|
||||
"""
|
||||
|
||||
@@ -296,6 +296,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||
# Alias MySQL's TRADITIONAL to TEXT for consistency with other backends.
|
||||
if format and format.upper() == 'TEXT':
|
||||
format = 'TRADITIONAL'
|
||||
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'
|
||||
prefix = super().explain_query_prefix(format, **options)
|
||||
if format:
|
||||
prefix += ' FORMAT=%s' % format
|
||||
|
||||
Reference in New Issue
Block a user