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

4👍

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.

Leave a comment