diff options
| author | Akshesh <aksheshdoshi@gmail.com> | 2016-08-25 12:42:17 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-09-02 21:14:12 -0400 |
| commit | dbccf163b6e45bf2a673c249d4667360676acddc (patch) | |
| tree | 55f45364d66e03cee18d76ab84669988c7a2b34d /django | |
| parent | 082f5bfdbcc9b18d064dd6c72a910188c459d617 (diff) | |
Fixed #27097 -- Added index type introspection to built-in db backends.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/base/features.py | 3 | ||||
| -rw-r--r-- | django/db/backends/base/introspection.py | 2 | ||||
| -rw-r--r-- | django/db/backends/mysql/introspection.py | 4 | ||||
| -rw-r--r-- | django/db/backends/oracle/introspection.py | 13 | ||||
| -rw-r--r-- | django/db/backends/postgresql/features.py | 1 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/introspection.py | 4 |
6 files changed, 14 insertions, 13 deletions
diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py index 67c34f028f..e3677dd35a 100644 --- a/django/db/backends/base/features.py +++ b/django/db/backends/base/features.py @@ -163,9 +163,6 @@ class BaseDatabaseFeatures(object): # Can the backend introspect the column order (ASC/DESC) for indexes? supports_index_column_ordering = True - # Can the backend introspect the type of index created? - can_introspect_index_type = False - # Support for the DISTINCT ON clause can_distinct_on_fields = False diff --git a/django/db/backends/base/introspection.py b/django/db/backends/base/introspection.py index b3eec72469..7da14985c3 100644 --- a/django/db/backends/base/introspection.py +++ b/django/db/backends/base/introspection.py @@ -172,6 +172,8 @@ class BaseDatabaseIntrospection(object): * foreign_key: (table, column) of target, or None * check: True if check constraint, False otherwise * index: True if index, False otherwise. + * orders: The order (ASC/DESC) defined for the columns of indexes + * type: The type of the index (btree, hash, etc.) Some backends may return special constraint names that don't exist if they don't name constraints of a certain type (e.g. SQLite) diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py index 4ac8864ba6..3a8b7f6933 100644 --- a/django/db/backends/mysql/introspection.py +++ b/django/db/backends/mysql/introspection.py @@ -201,17 +201,17 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): constraints[constraint]['unique'] = True # 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 in [x[:5] for x in cursor.fetchall()]: + for table, non_unique, index, colseq, column, type_ in [x[:5] + (x[10],) for x in cursor.fetchall()]: if index not in constraints: constraints[index] = { 'columns': OrderedSet(), 'primary_key': False, 'unique': False, - 'index': True, 'check': False, 'foreign_key': None, } constraints[index]['index'] = True + constraints[index]['type'] = type_.lower() constraints[index]['columns'].add(column) # Convert the sorted sets to lists for constraint in constraints.values(): diff --git a/django/db/backends/oracle/introspection.py b/django/db/backends/oracle/introspection.py index f8eec17256..5c0c5c5861 100644 --- a/django/db/backends/oracle/introspection.py +++ b/django/db/backends/oracle/introspection.py @@ -258,20 +258,20 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): # Now get indexes cursor.execute(""" SELECT - index_name, - LOWER(column_name), descend + cols.index_name, LOWER(cols.column_name), cols.descend, + LOWER(ind.index_type) FROM - user_ind_columns cols + user_ind_columns cols, user_indexes ind WHERE - table_name = UPPER(%s) AND + cols.table_name = UPPER(%s) AND NOT EXISTS ( SELECT 1 FROM user_constraints cons WHERE cols.index_name = cons.index_name - ) + ) AND cols.index_name = ind.index_name ORDER BY cols.column_position """, [table_name]) - for constraint, column, order in cursor.fetchall(): + for constraint, column, order, type_ in cursor.fetchall(): # If we're the first column, make the record if constraint not in constraints: constraints[constraint] = { @@ -282,6 +282,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): "foreign_key": None, "check": False, "index": True, + "type": 'btree' if type_ == 'normal' else type_, } # Record the details constraints[constraint]['columns'].append(column) diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py index 918dfe7978..a9e1c77480 100644 --- a/django/db/backends/postgresql/features.py +++ b/django/db/backends/postgresql/features.py @@ -22,7 +22,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): can_introspect_autofield = True can_introspect_ip_address_field = True can_introspect_small_integer_field = True - can_introspect_index_type = True can_distinct_on_fields = True can_rollback_ddl = True supports_combined_alters = True diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py index 32efd7ff6f..db475505d8 100644 --- a/django/db/backends/sqlite3/introspection.py +++ b/django/db/backends/sqlite3/introspection.py @@ -255,8 +255,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): "index": True, } constraints[index]['columns'].append(column) - # Add column orders for indexes + # Add type and column orders for indexes if constraints[index]['index'] and not constraints[index]['unique']: + # SQLite doesn't support any index type other than b-tree + constraints[index]['type'] = 'btree' cursor.execute( "SELECT sql FROM sqlite_master " "WHERE type='index' AND name=%s" % self.connection.ops.quote_name(index) |
