#33773: DEFAULT_INDEX_TABLESPACE setting is ignored for Indexes defined with
multiple fields.
-------------------------------------+-------------------------------------
               Reporter:  sumebrius  |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Tested with Postgresql backend, Django versions 3.2 & 4.0

 Defining an Index in the Meta of a model ignores the
 DEFAULT_INDEX_TABLESPACE setting if multiple fields are used for the
 index.
 The setting is honoured if only a single field defines the index.

 Example case, with a postgresql DB defined in settings, as well as:
 {{{
 DEFAULT_TABLESPACE = 'data_ts'
 DEFAULT_INDEX_TABLESPACE = 'index_ts'
 }}}

 The below model definition:
 {{{
 class MyModel(models.Model):
     foo = models.CharField(max_length=10)
     bar = models.CharField(max_length=10)

     class Meta:
         indexes = [
             models.Index(fields=['foo']),
             models.Index(fields=['foo', 'bar']),
         ]
 }}}
 generates this output from management command {{{sqlmigrate}}} run on the
 produced migration:
 {{{
 BEGIN;
 --
 -- Create model MyModel
 --
 CREATE TABLE "cbcap_mymodel" ("id" bigserial NOT NULL PRIMARY KEY USING
 INDEX TABLESPACE "index_ts", "foo" varchar(10) NOT NULL, "bar" varchar(10)
 NOT NULL) TABLESPACE "data_ts";
 --
 -- Create index cbcap_mymod_foo_f01529_idx on field(s) foo of model
 mymodel
 --
 CREATE INDEX "cbcap_mymod_foo_f01529_idx" ON "cbcap_mymodel" ("foo")
 TABLESPACE "index_ts";
 --
 -- Create index cbcap_mymod_foo_44bcd6_idx on field(s) foo, bar of model
 mymodel
 --
 CREATE INDEX "cbcap_mymod_foo_44bcd6_idx" ON "cbcap_mymodel" ("foo",
 "bar") TABLESPACE "data_ts";
 COMMIT;
 }}}
 Note the 'data_ts' tablespace is used for the second index

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33773>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070181480434b2-625eb398-39fa-42a5-8676-24d86ff8eb33-000000%40eu-central-1.amazonses.com.

Reply via email to