如何在 Django 中指定索引类型? (btree 与哈希等)
How do I specify type of index in django? (btree vs hash, etc)
如标题所说,如何在 django 模型的字段上指定我想要的索引类型。
class Person:
...
age = models.IntegerField(db_index=True)
但是现在呢?我如何确定它是 btree
索引而不是 hash
。或者这一切都是自动为我们完成的,并且 django 使用一些大的 table 来选择 "optimal index type"
每当您指定 index=True
:
时,Django 默认创建 btree
索引
https://docs.djangoproject.com/en/1.11/ref/models/indexes/
我注意到您正在使用 MySQL;但如果您使用的是 PostgreSQL,则可以在某些类型的字段上指定某些其他索引类型:
https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/indexes/
此答案提供了有关如何覆盖 MySQL 中的 btree
默认值的信息,如果您需要:
如标题所说,如何在 django 模型的字段上指定我想要的索引类型。
class Person:
...
age = models.IntegerField(db_index=True)
但是现在呢?我如何确定它是 btree
索引而不是 hash
。或者这一切都是自动为我们完成的,并且 django 使用一些大的 table 来选择 "optimal index type"
每当您指定 index=True
:
btree
索引
https://docs.djangoproject.com/en/1.11/ref/models/indexes/
我注意到您正在使用 MySQL;但如果您使用的是 PostgreSQL,则可以在某些类型的字段上指定某些其他索引类型:
https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/indexes/
此答案提供了有关如何覆盖 MySQL 中的 btree
默认值的信息,如果您需要: