I have a model with the fields word and user, which I use together in a lot of queries. I made this manager function to test how fast the get() function is for these two fields:
def speedtest(self):
start = timeit.default_timer()
for obj in self.all().iterator():
self.get(user=obj.user, word=obj.word)
print(timeit.default_timer() - start)
Without indexing it takes around 13 seconds to get ~18,000 items. I then add indexes to the model like so:
class Meta:
indexes = [models.Index(fields = ["user", "word"])]
Now, it takes about 11 seconds. A 15% increase isn't bad, but to be honest, I was expecting something more significant This is my first time using SQL indexing, so I wanted to ensure that I'm doing the right thing.