Q:

What is the a performance cost of Django's unique_together feature

To me it seems like there would be a lot of processing or searching when using more complex unique_together tuples. It seems like the better option would be to strictly handle uniqueness when creating records in a database. Does anyone happen to know what the costs are to using unique_together especially if they involve more complex tuples?
I currently have a model that I will likely need to switch from
index_together = unique_together = (('a', 'b'), ('a', 'c', 'd'))

to
index_together = unique_together = (('a', 'b', 'e'), ('a', 'c', 'd', 'e'))

A:

unique_together is implemented as UNIQUE CONSTRAINT at the database level. Read how SQL indexes work, about read / write ratio (indexes are built when data is written, so it slows down write operations but when there is much more of reads than writes that is not the problem), read about index selectivity / cardinality. Use EXPLAIN queries to check whether the index are used (not ignored) when retrieving data.
Having multiple large unique indexes is one of the sign that the table should be split into two or few with lower number of columns, related through one to many relations.

