Fixed #28046 -- Added the db_tablespace parameter to class-based indexes.

Thanks Markus Holtermann and Tim Graham for reviews.
This commit is contained in:
Mariusz Felisiak 2017-06-27 21:15:15 +02:00 committed by GitHub
parent 617505ca89
commit 3297dede7f
7 changed files with 93 additions and 23 deletions

View file

@ -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
================