mirror of https://github.com/django/django.git
Fixed #32342 -- Added index order introspection on MySQL 8.0.1+.
This commit is contained in:
parent
cd3019bc10
commit
407d3cf39c
|
@ -14,7 +14,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||
supports_forward_references = False
|
||||
supports_regex_backreferencing = False
|
||||
supports_date_lookup_using_string = False
|
||||
supports_index_column_ordering = False
|
||||
supports_timezones = False
|
||||
requires_explicit_null_ordering_when_grouping = True
|
||||
can_release_savepoints = True
|
||||
|
@ -219,3 +218,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||
if self.connection.mysql_is_mariadb:
|
||||
return self.supports_json_field and self.can_introspect_check_constraints
|
||||
return self.supports_json_field
|
||||
|
||||
@cached_property
|
||||
def supports_index_column_ordering(self):
|
||||
return (
|
||||
not self.connection.mysql_is_mariadb and
|
||||
self.connection.mysql_version >= (8, 0, 1)
|
||||
)
|
||||
|
|
|
@ -229,6 +229,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
'check': False,
|
||||
'foreign_key': (ref_table, ref_column) if ref_column else None,
|
||||
}
|
||||
if self.connection.features.supports_index_column_ordering:
|
||||
constraints[constraint]['orders'] = []
|
||||
constraints[constraint]['columns'].add(column)
|
||||
# Now get the constraint types
|
||||
type_query = """
|
||||
|
@ -289,7 +291,9 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
}
|
||||
# Now add in the indexes
|
||||
cursor.execute("SHOW INDEX FROM %s" % self.connection.ops.quote_name(table_name))
|
||||
for table, non_unique, index, colseq, column, type_ in [x[:5] + (x[10],) for x in cursor.fetchall()]:
|
||||
for table, non_unique, index, colseq, column, order, type_ in [
|
||||
x[:6] + (x[10],) for x in cursor.fetchall()
|
||||
]:
|
||||
if index not in constraints:
|
||||
constraints[index] = {
|
||||
'columns': OrderedSet(),
|
||||
|
@ -298,9 +302,13 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
'check': False,
|
||||
'foreign_key': None,
|
||||
}
|
||||
if self.connection.features.supports_index_column_ordering:
|
||||
constraints[index]['orders'] = []
|
||||
constraints[index]['index'] = True
|
||||
constraints[index]['type'] = Index.suffix if type_ == 'BTREE' else type_.lower()
|
||||
constraints[index]['columns'].add(column)
|
||||
if self.connection.features.supports_index_column_ordering:
|
||||
constraints[index]['orders'].append('DESC' if order == 'D' else 'ASC')
|
||||
# Convert the sorted sets to lists
|
||||
for constraint in constraints.values():
|
||||
constraint['columns'] = list(constraint['columns'])
|
||||
|
|
Loading…
Reference in New Issue