Skip to content

Make single-field indexes and unique constraints explicit

Erwan Rouchet requested to merge index-cleanup into master

Closes #1516 (closed)

This uses RawSQL operations that act like the original operations just so the remaining indexes and constraints get renamed instead of re-created. Thankfully, the big cleanup done during the migrations reset means the old automatically generated index names are the same on all instances 😌

All indexes on Classification.state are removed entirely simply because we never ever filter on the classification state anymore. We used to filter back when we had a concept of best classes, but we no longer have that and there is no state filter at all.

All indexes on ElementType.slug are removed entirely, not just the LIKE index, because we always filter on both corpus_id and slug, which already have their own index via the unique constraint on those fields. I checked the query plans, especially on element lists, and found that the query planner always used this unique constraint and completely ignored both indexes.

On every other field, the LIKE index is removed and the regular index is kept because it is defined and used by a unique constraint.

I also updated the best practices to mention that db_index=True and unique=True are Not Great.

Edited by Erwan Rouchet

Merge request reports

Loading