Django: specifying HASH instead of BTREE for an indexed column

Is there a good way in Django models to specify a specific type of index store?

For example, the default storage type for MySQL is BTREE, when it can be more efficient for my particular column to have a HASH (hash table) as the storage type.

I cannot find a good way without creating a custom field or modifying the django kernel that will do this for me. I can also do this by changing the index after creating the table.

This situation probably doesn’t matter for most things, but there are situations when the hash table is a more efficient search mechanism, and, of course, if sorting by column is not needed or it does not make sense. For example, a column with randomly generated data usually does not make a reasonable ordering of information (unless you are looking for a repeatable random type, but this does not apply to the point).

+3
source share
1 answer

After looking at the code for django.db.backends.mysql.creation.sql_indexes_for_field(), there seems to be no way to specify the type of index in Django itself (there is no way to get the parameter USINGin the request unless you want to subclass the backend).

- , . Django SQL- . "sql" SQL <your_modelname>.mysql.sql. SQL , Django "syncdb" "reset", .

+5

Source: https://habr.com/ru/post/1755411/


All Articles