PostgreSQL 特有模型索引
PostgreSQL 特有模型索引
以下是 PostgreSQL 特有的 索引 可以从 django.contrib.postgres.indexes 模块中获得。
BloomIndex
class BloomIndex(expressions_ , length=None , columns=() , _*options)
创建一个 bloom 索引。
要使用这个索引访问,你需要激活 PostgreSQL 上的 bloom 扩展。你可以使用 BloomExtension 迁移操作来安装它。
为 length 参数提供一个从 1 到 4096 的整数位,用于指定每个索引条目的长度。PostgreSQL 的默认值是 80。
columns 参数取一个元组或最多 32 个值的列表,这些值是 1 到 4095 的整数位。
BrinIndex
class BrinIndex(expressions_ , autosummarize=None , pages_per_range=None , _*options)
创建一个 BRIN 索引 。
将 autosummarize 参数设置为 True,启用 autovacuum 进行 自动汇总 。
pages_per_range 参数取一个正整数。
BTreeIndex
class BTreeIndex(expressions_ , fillfactor=None , _*options)
创建一个 B 树索引。
为 fillfactor 参数提供一个从 10 到 100 的整数值,以调整索引页的打包程度。PostgreSQL 的默认值是 90。
GinIndex
class GinIndex(expressions_ , fastupdate=None , gin_pending_list_limit=None , _*options)
创建一个 gin 索引 。
要想在不在 内置运算符类 的数据类型上使用这个索引,需要在 PostgreSQL 上激活 btree_gin 扩展 。你可以使用 BtreeGinExtension 迁移操作来安装它。
将 fastupdate 参数设置为 False,以禁用 PostgreSQL 中默认启用的 GIN 快速更新技术 。
Provide an integer number of kilobytes to the gin_pending_list_limit parameter to tune the maximum size of the GIN pending list which is used when fastupdate is enabled.
GistIndex
class GistIndex(expressions_ , buffering=None , fillfactor=None , _*options)
创建一个 GiST 索引 。这些索引在空间字段上会自动创建 spatial_index=True。它们在其他类型上也很有用,比如 HStoreField 或者 range fields。
要在不在内置的 gist 操作类 的数据类型上使用这个索引,需要在 PostgreSQL 上激活 btree_gist 扩展 。你可以使用 BtreeGistExtension 迁移操作来安装它。
将 buffering 参数设置为 True 或 False,手动启用或禁用索引的 buffering build 。
为 fillfactor 参数提供一个从 10 到 100 的整数值,以调整索引页的打包程度。PostgreSQL 的默认值是 90。
HashIndex
class HashIndex(expressions_ , fillfactor=None , _*options)
创建一个哈希索引。
为 fillfactor 参数提供一个从 10 到 100 的整数值,以调整索引页的打包程度。PostgreSQL 的默认值是 90。
SpGistIndex
class SpGistIndex(expressions_ , fillfactor=None , _*options)
创建 SP-GIST 索引 。
为 fillfactor 参数提供一个从 10 到 100 的整数值,以调整索引页的打包程度。PostgreSQL 的默认值是 90。
OpClass() 表达式
class OpClass(expression , name)
An OpClass() expression represents the expression with a custom operator class that can be used to define functional indexes, functional unique constraints, or exclusion constraints. To use it, you need to add 'django.contrib.postgres' in your INSTALLED_APPS. Set the name parameter to the name of the operator class.
例子:
Index(
OpClass(Lower("username"), name="varchar_pattern_ops"),
name="lower_username_idx",
)
creates an index on Lower('username') using varchar_pattern_ops.
UniqueConstraint(
OpClass(Upper("description"), name="text_pattern_ops"),
name="upper_description_unique",
)
creates a unique constraint on Upper('description') using text_pattern_ops.
ExclusionConstraint(
name="exclude_overlapping_ops",
expressions=[
(OpClass("circle", name="circle_ops"), RangeOperators.OVERLAPS),
],
)
使用 circle_ops 在 circle 上创建一个排除约束。
