---
title: "PostgreSQL 固有のモデルインデックス"
version: 6.1
locale: ja
source: https://docs.djangoproject.com/ja/6.1/ref/contrib/postgres/indexes/
canonical: https://djangodocs.dev/ja/6.1/ref/contrib/postgres/indexes/
---
# PostgreSQL 固有のモデルインデックス

以下はPostgreSQL固有の `django.contrib.postgres.indexes` モジュールから利用可能な [インデックス](/ja/6.1/ref/models/indexes/) です。

## `BloomIndex`

#### `class BloomIndex(*expressions, length=None, columns=(), **options)`

[bloom](https://www.postgresql.org/docs/current/bloom.html) インデックスを作成します。

このインデックスアクセスを使用するには、PostgreSQLで [bloom](https://www.postgresql.org/docs/current/bloom.html) 拡張機能を有効にする必要があります。これは、 [`BloomExtension`](/ja/6.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.BloomExtension) マイグレーションオペレーションを使用してインストールできます。

`length` パラメータには、1 から 4096 の整数のビット数を指定して、各インデックスエントリの長さを指定してください。PostgreSQL のデフォルト値は 80 です。

`columns` 引数は、1から4095までの整数ビットで、最大32個の値を持つタプルまたはリストを取ります。

## `BrinIndex`

#### `class BrinIndex(*expressions, autosummarize=None, pages_per_range=None, **options)`

[BRIN index](https://www.postgresql.org/docs/current/brin.html) を作成します。

`autosummarize` パラメータを `True` に設定すると、autovacuum による [automatic summarization](https://www.postgresql.org/docs/current/brin.html#BRIN-OPERATION) を有効にできます。

`pages_per_range` 引数は正の整数を取ります。

## `BTreeIndex`

#### `class BTreeIndex(*expressions, fillfactor=None, deduplicate_items=None, **options)`

B-Tree インデックスを作成します。

[fillfactor](https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS) パラメータには、インデックスページがどれだけ詰め込まれるかを調整するために、10 から 100 の整数値を指定してください。PostgreSQL のデフォルト値は 90 です。

[deduplicate\_items](https://www.postgresql.org/docs/current/btree.html#BTREE-DEDUPLICATION) パラメータに真偽値を指定して、重複排除が有効かどうかを制御します。PostgreSQLでは、重複排除はデフォルトで有効になっています。

## `GinIndex`

#### `class GinIndex(*expressions, fastupdate=None, gin_pending_list_limit=None, **options)`

[gin インデックス](https://www.postgresql.org/docs/current/gin.html) を作成します。

[組み込みの演算子クラス](https://www.postgresql.org/docs/current/gin.html#GIN-BUILTIN-OPCLASSES) 以外のデータ型でこのインデックスを使用するには、 PostgreSQL で [btree\_gin 拡張](https://www.postgresql.org/docs/current/btree-gin.html) を有効にする必要があります。これをインストールするには [`BtreeGinExtension`](/ja/6.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.BtreeGinExtension) というマイグレーションオペレーションを使用します。

`fastupdate` パラメータを `False` に設定すると、PostgreSQL でデフォルトで有効になっている [GIN Fast Update Technique](https://www.postgresql.org/docs/current/gin.html#GIN-FAST-UPDATE) を無効にできます。

`fastupdate` が有効な場合に使用される GIN 保留リストの最大サイズを調整するには、 [gin\_pending\_list\_limit](https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-GIN-PENDING-LIST-LIMIT) パラメータに整数キロバイト数を指定します。

## `GistIndex`

#### `class GistIndex(*expressions, buffering=None, fillfactor=None, **options)`

[GiSTインデックス](https://www.postgresql.org/docs/current/gist.html) を作成します。これらのインデックスは、 [`spatial_index=True`](/ja/6.1/ref/contrib/gis/model-api/#django.contrib.gis.db.models.BaseSpatialField.spatial_index) で指定された空間フィールドに自動的に作成されます。これらは、 [`HStoreField`](/ja/6.1/ref/contrib/postgres/fields/#django.contrib.postgres.fields.HStoreField) や [範囲フィールド](/ja/6.1/ref/contrib/postgres/fields/#range-fields) など他のタイプでも有用です。

組み込みの [gist 演算子クラス](https://www.postgresql.org/docs/current/gist.html#GIST-BUILTIN-OPCLASSES) 以外のデータ型でこのインデックスを使用するには、 PostgreSQL で [btree\_gist 拡張](https://www.postgresql.org/docs/current/btree-gist.html) を有効にする必要があります。これをインストールするには [`BtreeGistExtension`](/ja/6.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.BtreeGistExtension) というマイグレーションオペレーションを使用します。

インデックスの [buffering build](https://www.postgresql.org/docs/current/gist.html#GIST-BUFFERING-BUILD) を手動で有効または無効にするには、 `buffering` パラメータを `True` または `False` に設定してください。

[fillfactor](https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS) パラメータには、インデックスページがどれだけ詰め込まれるかを調整するために、10 から 100 の整数値を指定してください。PostgreSQL のデフォルト値は 90 です。

## `HashIndex`

#### `class HashIndex(*expressions, fillfactor=None, **options)`

ハッシュインデックスを作成します。

[fillfactor](https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS) パラメータには、インデックスページがどれだけ詰め込まれるかを調整するために、10 から 100 の整数値を指定してください。PostgreSQL のデフォルト値は 90 です。

## `SpGistIndex`

#### `class SpGistIndex(*expressions, fillfactor=None, **options)`

[SP-GiST インデックス](https://www.postgresql.org/docs/current/spgist.html) を作成します。

[fillfactor](https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS) パラメータには、インデックスページがどれだけ詰め込まれるかを調整するために、10 から 100 の整数値を指定してください。PostgreSQL のデフォルト値は 90 です。

## `OpClass()` 式

#### `class OpClass(expression, name)`

`OpClass()` 式は、機能インデックス、機能ユニーク制約、または除外制約を定義するために使用できるカスタム [operator class](https://www.postgresql.org/docs/current/indexes-opclass.html) と一緒に表す `expression` を表します。これを使用するには、 [`INSTALLED_APPS`](/ja/6.1/ref/settings/#std-setting-INSTALLED_APPS) に `'django.contrib.postgres'` を追加する必要があります。`name` パラメータを [operator class](https://www.postgresql.org/docs/current/indexes-opclass.html) の名前に設定します。

例:

```
Index(
    OpClass(Lower("username"), name="varchar_pattern_ops"),
    name="lower_username_idx",
)
```

`varchar_pattern_ops` を使用して `Lower('username')` にインデックスを作成します:

```
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_ops` を使用して `circle` 上に排他制約を作成します。
