diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2019-10-21 17:34:19 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-24 15:13:26 +0200 |
| commit | 55df1750be3c88db89444335f77dca10681dcbe3 (patch) | |
| tree | 71c8547cd87b78ba47659ad34aff957352172251 /tests | |
| parent | 742961332e1e2221e6fb9506c7254164e0c2cb5a (diff) | |
Refs #30897 -- Added support for ANALYZE option to Queryset.explain() on MariaDB and MySQL 8.0.18+.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/queries/test_explain.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/queries/test_explain.py b/tests/queries/test_explain.py index e3872213a0..481924a2e4 100644 --- a/tests/queries/test_explain.py +++ b/tests/queries/test_explain.py @@ -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. |
