PostgreSQL特定的模型索引

以下是PostgreSQL特有的 indexes 可从 django.contrib.postgres.indexes 模块。

BloomIndex

class BloomIndex(*expressions, length=None, columns=(), **options)[源代码]

创建一个 bloom 索引。

要使用此索引访问,您需要激活 bloom PostgreSQL上的扩展。您可以使用 BloomExtension 迁移操作。

提供从1到4096的整数位数 length 参数指定每个索引项的长度。PostgreSQL的默认值是80。

这个 columns 参数接受最多32个值的元组或列表,这些值是从1到4095的整数位数。

BrinIndex

class BrinIndex(*expressions, autosummarize=None, pages_per_range=None, **options)[源代码]

创建一个 BRIN index .

设置 autosummarize 参数到 True 使能 automatic summarization 由自动真空进行。

这个 pages_per_range 参数采用正整数。

BTreeIndex

class BTreeIndex(*expressions, fillfactor=None, **options)[源代码]

创建B树索引。

提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。

GinIndex

class GinIndex(*expressions, fastupdate=None, gin_pending_list_limit=None, **options)[源代码]

创建一个 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

class GistIndex(*expressions, buffering=None, fillfactor=None, **options)[源代码]

创建一个 GiST index . 这些索引是在具有 spatial_index=True . 它们在其他类型上也很有用,例如 HStoreFieldrange fields .

对不在内置数据类型中的数据类型使用此索引 gist operator classes ,您需要激活 btree_gist extension 在PostgreSQL上。您可以使用 BtreeGistExtension 迁移操作。

设置 buffering 参数到 TrueFalse 手动启用或禁用 buffering build 索引的

提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。

HashIndex

class HashIndex(*expressions, fillfactor=None, **options)[源代码]

创建哈希索引。

提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。

SpGistIndex

class SpGistIndex(*expressions, fillfactor=None, **options)[源代码]

创建一个 SP-GiST index .

提供从10到100的整数值 fillfactor 用于调整索引页的压缩程度的参数。PostgreSQL的默认值是90。

OpClass() 表达式

class OpClass(expression, name)[源代码]

一个 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