I want to index a very common query in a project that involves a CharField and ForeignKey. I have a bottleneck with this query and I am trying to optimize it. I have this:
class Bill(models.Model):
company = models.ForeignKey(Company, on_delete=models.CASCADE)
category = models.CharField(max_length=200, null=True, blank=True)
...
I added this to try to improve the performance:
class Meta:
indexes = [
models.Index(fields=['category', 'company']),
]
But the result is the same, the query is:
models.Bill.objects.filter(company=company, category='recibida')
Is there something else that I could improve? Is this indexing well done?