From 22ff4f81b1859ed7af7999ef479a10b5d31a2164 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Mon, 9 Oct 2017 18:19:08 +0200 Subject: [PATCH] Fixed #28423 -- Expanded docs for indexing contrib.postgres fields. --- docs/ref/contrib/postgres/fields.txt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt index f151986ff8..4c910527c9 100644 --- a/docs/ref/contrib/postgres/fields.txt +++ b/docs/ref/contrib/postgres/fields.txt @@ -7,6 +7,18 @@ module. .. currentmodule:: django.contrib.postgres.fields +Indexing these fields +===================== + +:class:`~django.db.models.Index` and :attr:`.Field.db_index` both create a +B-tree index, which isn't particularly helpful when querying complex data types. +Indexes such as :class:`~django.contrib.postgres.indexes.GinIndex` and +:class:`~django.contrib.postgres.indexes.GistIndex` are better suited, though +the index choice is dependent on the queries that you're using. Generally, GiST +may be a good choice for the :ref:`range fields ` and +:class:`HStoreField`, and GIN may be helpful for :class:`ArrayField` and +:class:`JSONField`. + ``ArrayField`` ============== @@ -241,14 +253,6 @@ transform do not change. For example:: at the database level and cannot be supported in a logical, consistent fashion by Django. -Indexing ``ArrayField`` ------------------------ - -At present using :attr:`~django.db.models.Field.db_index` will create a -``btree`` index. This does not offer particularly significant help to querying. -A more useful index is a ``GIN`` index, which you should create using a -:class:`~django.db.migrations.operations.RunSQL` operation. - ``CIText`` fields =================