Optimized DatabaseSchemaEditor._field_should_be_indexed() on MySQL.

This commit is contained in:
Matjaz Gregoric 2021-08-12 09:52:24 +02:00 committed by Mariusz Felisiak
parent bf5abf1bdc
commit e9aa20e4e1
1 changed files with 4 additions and 3 deletions

View File

@ -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):
"""