mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +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
@@ -80,6 +80,25 @@ class ExplainTests(TestCase):
|
||||
self.assertEqual(len(captured_queries), 1)
|
||||
self.assertIn('FORMAT=TRADITIONAL', captured_queries[0]['sql'])
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'mysql', 'MariaDB and MySQL >= 8.0.18 specific.')
|
||||
def test_mysql_analyze(self):
|
||||
# Inner skip to avoid module level query for MySQL version.
|
||||
if not connection.features.supports_explain_analyze:
|
||||
raise unittest.SkipTest('MariaDB and MySQL >= 8.0.18 specific.')
|
||||
qs = Tag.objects.filter(name='test')
|
||||
with CaptureQueriesContext(connection) as captured_queries:
|
||||
qs.explain(analyze=True)
|
||||
self.assertEqual(len(captured_queries), 1)
|
||||
prefix = 'ANALYZE ' if connection.mysql_is_mariadb else 'EXPLAIN ANALYZE '
|
||||
self.assertTrue(captured_queries[0]['sql'].startswith(prefix))
|
||||
with CaptureQueriesContext(connection) as captured_queries:
|
||||
qs.explain(analyze=True, format='JSON')
|
||||
self.assertEqual(len(captured_queries), 1)
|
||||
if connection.mysql_is_mariadb:
|
||||
self.assertIn('FORMAT=JSON', captured_queries[0]['sql'])
|
||||
else:
|
||||
self.assertNotIn('FORMAT=JSON', captured_queries[0]['sql'])
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'mysql', 'MySQL < 5.7 specific')
|
||||
def test_mysql_extended(self):
|
||||
# Inner skip to avoid module level query for MySQL version.
|
||||
|
||||
Reference in New Issue
Block a user