Fixed #26167 -- Added support for functional indexes.

Thanks Simon Charette, Mads Jensen, and Mariusz Felisiak for reviews.

Co-authored-by: Markus Holtermann <info@markusholtermann.eu>
This commit is contained in:
Hannes Ljungberg 2019-10-10 20:04:17 +02:00 committed by Mariusz Felisiak
parent e3ece0144a
commit 83fcfc9ec8
28 changed files with 1306 additions and 65 deletions

View file

@ -10,7 +10,7 @@ available from the ``django.contrib.postgres.indexes`` module.
``BloomIndex``
==============
.. class:: BloomIndex(length=None, columns=(), **options)
.. class:: BloomIndex(*expressions, length=None, columns=(), **options)
.. versionadded:: 3.1
@ -30,10 +30,15 @@ available from the ``django.contrib.postgres.indexes`` module.
.. _bloom: https://www.postgresql.org/docs/current/bloom.html
.. versionchanged:: 3.2
Positional argument ``*expressions`` was added in order to support
functional indexes.
``BrinIndex``
=============
.. class:: BrinIndex(autosummarize=None, pages_per_range=None, **options)
.. class:: BrinIndex(*expressions, autosummarize=None, pages_per_range=None, **options)
Creates a `BRIN index
<https://www.postgresql.org/docs/current/brin-intro.html>`_.
@ -43,24 +48,34 @@ available from the ``django.contrib.postgres.indexes`` module.
The ``pages_per_range`` argument takes a positive integer.
.. versionchanged:: 3.2
Positional argument ``*expressions`` was added in order to support
functional indexes.
.. _automatic summarization: https://www.postgresql.org/docs/current/brin-intro.html#BRIN-OPERATION
``BTreeIndex``
==============
.. class:: BTreeIndex(fillfactor=None, **options)
.. class:: BTreeIndex(*expressions, fillfactor=None, **options)
Creates a B-Tree index.
Provide an integer value from 10 to 100 to the fillfactor_ parameter to
tune how packed the index pages will be. PostgreSQL's default is 90.
.. versionchanged:: 3.2
Positional argument ``*expressions`` was added in order to support
functional indexes.
.. _fillfactor: https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS
``GinIndex``
============
.. class:: GinIndex(fastupdate=None, gin_pending_list_limit=None, **options)
.. class:: GinIndex(*expressions, fastupdate=None, gin_pending_list_limit=None, **options)
Creates a `gin index <https://www.postgresql.org/docs/current/gin.html>`_.
@ -79,13 +94,18 @@ available from the ``django.contrib.postgres.indexes`` module.
to tune the maximum size of the GIN pending list which is used when
``fastupdate`` is enabled.
.. versionchanged:: 3.2
Positional argument ``*expressions`` was added in order to support
functional indexes.
.. _GIN Fast Update Technique: https://www.postgresql.org/docs/current/gin-implementation.html#GIN-FAST-UPDATE
.. _gin_pending_list_limit: https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-GIN-PENDING-LIST-LIMIT
``GistIndex``
=============
.. class:: GistIndex(buffering=None, fillfactor=None, **options)
.. class:: GistIndex(*expressions, buffering=None, fillfactor=None, **options)
Creates a `GiST index
<https://www.postgresql.org/docs/current/gist.html>`_. These indexes are
@ -109,13 +129,18 @@ available from the ``django.contrib.postgres.indexes`` module.
Provide an integer value from 10 to 100 to the fillfactor_ parameter to
tune how packed the index pages will be. PostgreSQL's default is 90.
.. versionchanged:: 3.2
Positional argument ``*expressions`` was added in order to support
functional indexes.
.. _buffering build: https://www.postgresql.org/docs/current/gist-implementation.html#GIST-BUFFERING-BUILD
.. _fillfactor: https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS
``HashIndex``
=============
.. class:: HashIndex(fillfactor=None, **options)
.. class:: HashIndex(*expressions, fillfactor=None, **options)
Creates a hash index.
@ -127,12 +152,17 @@ available from the ``django.contrib.postgres.indexes`` module.
Hash indexes have been available in PostgreSQL for a long time, but
they suffer from a number of data integrity issues in older versions.
.. versionchanged:: 3.2
Positional argument ``*expressions`` was added in order to support
functional indexes.
.. _fillfactor: https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS
``SpGistIndex``
===============
.. class:: SpGistIndex(fillfactor=None, **options)
.. class:: SpGistIndex(*expressions, fillfactor=None, **options)
Creates an `SP-GiST index
<https://www.postgresql.org/docs/current/spgist.html>`_.
@ -140,4 +170,30 @@ available from the ``django.contrib.postgres.indexes`` module.
Provide an integer value from 10 to 100 to the fillfactor_ parameter to
tune how packed the index pages will be. PostgreSQL's default is 90.
.. versionchanged:: 3.2
Positional argument ``*expressions`` was added in order to support
functional indexes.
.. _fillfactor: https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS
``OpClass()`` expressions
=========================
.. versionadded:: 3.2
.. class:: OpClass(expression, name)
An ``OpClass()`` expression represents the ``expression`` with a custom
`operator class`_ that can be used to define functional indexes. To use it,
you need to add ``'django.contrib.postgres'`` in your
:setting:`INSTALLED_APPS`. Set the ``name`` parameter to the name of the
`operator class`_.
For example::
Index(OpClass(Lower('username'), name='varchar_pattern_ops'))
creates an index on ``Lower('username')`` using ``varchar_pattern_ops``.
.. _operator class: https://www.postgresql.org/docs/current/indexes-opclass.html