以下是PostgreSQL特有的 indexes 可从 django.contrib.postgres.indexes 模块。
BloomIndex¶创建一个 bloom 指数。
要使用此索引访问,您需要激活 bloom PostgreSQL上的扩展。您可以使用 BloomExtension 迁移操作。
向 length 参数指定每个索引项的长度。PostgreSQL的默认值是80。
这个 columns 参数采用最多32个值的数组或列表,这些值是从1到4095的个位数。
BrinIndex¶创建一个 BRIN index .
设置 autosummarize 参数到 True 使能 automatic summarization 由自动真空进行。
这个 pages_per_range 参数采用正整数。
BTreeIndex¶创建B树索引。
提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。
将布尔值提供给 deduplicate_items 用于控制是否启用重复数据消除的参数。默认情况下,PostgreSQL启用重复数据消除。
GinIndex¶创建一个 gin index .
要对不在 built-in operator classes ,您需要激活 btree_gin extension 在PostgreSQL上。您可以使用 BtreeGinExtension 迁移操作。
设置 fastupdate 参数到 False 禁用 GIN Fast Update Technique 这在PostgreSQL中是默认启用的。
将以千字节为单位的整数提供给 gin_pending_list_limit 参数来调整GIN挂起列表的最大大小,该列表在 fastupdate 已启用。
GistIndex¶创建一个 GiST index . 这些索引是在具有 spatial_index=True . 它们在其他类型上也很有用,例如 HStoreField 或 range fields .
要对未在内置中的数据类型使用此索引 gist operator classes ,您需要激活 btree_gist extension 在PostgreSQL上。您可以使用 BtreeGistExtension 迁移操作。
设置 buffering 参数到 True 或 False 手动启用或禁用 buffering build 索引的
提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。
HashIndex¶创建哈希索引。
提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。
SpGistIndex¶创建一个 SP-GiST index .
提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。
OpClass() 表达式¶一个 OpClass() 表达式表示 expression 有一个风俗习惯 operator class 可用于定义函数索引、函数唯一约束或排除约束的。要使用它,您需要添加 'django.contrib.postgres' 在你的 INSTALLED_APPS 。设置 name 参数设置为 operator class 。
例如::
Index(
OpClass(Lower("username"), name="varchar_pattern_ops"),
name="lower_username_idx",
)
在上创建索引 Lower('username') 使用 varchar_pattern_ops 。**
UniqueConstraint(
OpClass(Upper("description"), name="text_pattern_ops"),
name="upper_description_unique",
)
在上创建唯一约束 Upper('description') 使用 text_pattern_ops 。**
ExclusionConstraint(
name="exclude_overlapping_ops",
expressions=[
(OpClass("circle", name="circle_ops"), RangeOperators.OVERLAPS),
],
)
在上创建排除约束 circle 使用 circle_ops 。
5月 28, 2025