From e9aa20e4e17aee7adcf52fcd3f445cd296fa9b7b Mon Sep 17 00:00:00 2001 From: Matjaz Gregoric Date: Thu, 12 Aug 2021 09:52:24 +0200 Subject: [PATCH] Optimized DatabaseSchemaEditor._field_should_be_indexed() on MySQL. --- django/db/backends/mysql/schema.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py index 39450dd50d..6402bc7145 100644 --- a/django/db/backends/mysql/schema.py +++ b/django/db/backends/mysql/schema.py @@ -107,7 +107,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): }, [effective_default]) def _field_should_be_indexed(self, model, field): - create_index = super()._field_should_be_indexed(model, field) + if not super()._field_should_be_indexed(model, field): + return False + storage = self.connection.introspection.get_storage_engine( self.connection.cursor(), model._meta.db_table ) @@ -115,11 +117,10 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): # db_constraint=False because the index from that constraint won't be # created. if (storage == "InnoDB" and - create_index and field.get_internal_type() == 'ForeignKey' and field.db_constraint): return False - return not self._is_limited_data_type(field) and create_index + return not self._is_limited_data_type(field) def _delete_composed_index(self, model, fields, *args): """