I have a project running on PostgreSQL v9.4 and Django 1.6 (planning to upgrade to v1.8 soon...)
Let's say I have the following model:
class Product(models.Model):
x = models.ForeignKey(Shop)
y = models.PositiveIntegerField()
class Meta:
unique_together = (("x", "y"), )
As far as I understand:
- Field x is a foreign key, so unless requested otherwise, Django automatically adds a db index for (x)
- Due to the unique_together statement, PostgreSQL implicitly generates a combined index for (x, y)
- Generally, an index for (x, y) also serves as an index for (x)
- Duplicates indexes consume extra time in SQL INSERT operations
My conclusion is that in such a scenario, it is better to explicitly declare db_index=false for field x, to avoid the duplicate indexes.
Is this a valid conclusion?