diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-06-27 21:15:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-27 21:15:15 +0200 |
| commit | 3297dede7fce4b190f7b3bf0b0fc29a734151b61 (patch) | |
| tree | 1f1c91a72990ccaa7908766a20a64186b2971bc0 /docs | |
| parent | 617505ca892fc84c7be1c224ebca2c27f93e8f50 (diff) | |
Fixed #28046 -- Added the db_tablespace parameter to class-based indexes.
Thanks Markus Holtermann and Tim Graham for reviews.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/indexes.txt | 19 | ||||
| -rw-r--r-- | docs/releases/2.0.txt | 3 | ||||
| -rw-r--r-- | docs/topics/db/tablespaces.txt | 15 |
3 files changed, 31 insertions, 6 deletions
diff --git a/docs/ref/models/indexes.txt b/docs/ref/models/indexes.txt index 1b2af670d7..6e8ab210ee 100644 --- a/docs/ref/models/indexes.txt +++ b/docs/ref/models/indexes.txt @@ -23,7 +23,7 @@ options`_. ``Index`` options ================= -.. class:: Index(fields=[], name=None) +.. class:: Index(fields=[], name=None, db_tablespace=None) Creates an index (B-Tree) in the database. @@ -57,6 +57,23 @@ The name of the index. If ``name`` isn't provided Django will auto-generate a name. For compatibility with different databases, index names cannot be longer than 30 characters and shouldn't start with a number (0-9) or underscore (_). +``db_tablespace`` +----------------- + +.. attribute:: Index.db_tablespace + +.. versionadded:: 2.0 + +The name of the :doc:`database tablespace </topics/db/tablespaces>` to use for +this index. For single field indexes, if ``db_tablespace`` isn't provided, the +index is created in the ``db_tablespace`` of the field. + +If :attr:`.Field.db_tablespace` isn't specified (or if the index uses multiple +fields), the index is created in tablespace specified in the +:attr:`~django.db.models.Options.db_tablespace` option inside the model's +``class Meta``. If neither of those tablespaces are set, the index is created +in the same tablespace as the table. + .. seealso:: For a list of PostgreSQL-specific indexes, see diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 0b51736768..a68bd48877 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -245,6 +245,9 @@ Models function to truncate :class:`~django.db.models.DateField` and :class:`~django.db.models.DateTimeField` to the first day of a quarter. +* Added the :attr:`~django.db.models.Index.db_tablespace` parameter to + class-based indexes. + Requests and Responses ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/topics/db/tablespaces.txt b/docs/topics/db/tablespaces.txt index 6cda629254..4d7151fc55 100644 --- a/docs/topics/db/tablespaces.txt +++ b/docs/topics/db/tablespaces.txt @@ -29,10 +29,12 @@ cannot control. Declaring tablespaces for indexes ================================= -You can pass the :attr:`~django.db.models.Field.db_tablespace` option to a -``Field`` constructor to specify an alternate tablespace for the ``Field``’s -column index. If no index would be created for the column, the option is -ignored. +You can pass the :attr:`~django.db.models.Index.db_tablespace` option to an +``Index`` constructor to specify the name of a tablespace to use for the index. +For single field indexes, you can pass the +:attr:`~django.db.models.Field.db_tablespace` option to a ``Field`` constructor +to specify an alternate tablespace for the field's column index. If the column +doesn't have an index, the option is ignored. You can use the :setting:`DEFAULT_INDEX_TABLESPACE` setting to specify a default value for :attr:`~django.db.models.Field.db_tablespace`. @@ -49,17 +51,20 @@ An example class TablespaceExample(models.Model): name = models.CharField(max_length=30, db_index=True, db_tablespace="indexes") data = models.CharField(max_length=255, db_index=True) + shortcut = models.CharField(max_length=7) edges = models.ManyToManyField(to="self", db_tablespace="indexes") class Meta: db_tablespace = "tables" + indexes = [models.Index(fields=['shortcut'], db_tablespace='other_indexes')] In this example, the tables generated by the ``TablespaceExample`` model (i.e. the model table and the many-to-many table) would be stored in the ``tables`` tablespace. The index for the name field and the indexes on the many-to-many table would be stored in the ``indexes`` tablespace. The ``data`` field would also generate an index, but no tablespace for it is specified, so it would be -stored in the model tablespace ``tables`` by default. +stored in the model tablespace ``tables`` by default. The index for the +``shortcut`` field would be stored in the ``other_indexes`` tablespace. Database support ================ |
