I have a database table in psql which contains of 10,000,000 rows and 60 columns (features). I define a Django Queryset as follows:
MyQ=MyDataBase.objects.filter(Name='Mike', date=date(2018, 2, 11),
Class='03')
There are only 5 rows that satisfy the above filter. But when I try something like
MyQ.count() #which equals 5
or
MyQ.aggregate(Sum('Score'))['Score__sum'] #which equals 61
each take about 3 minutes to give me the result. Isn't that weird? Aren't query sets supposed to make life easier by focusing only on the rows that we have told them to focus on? counting 5 rows or summing one of the fields of them must not take that long. What am I doing wrong?
I should also say this. The first time that I tried this code on this table, everything was fine and it took maybe 1 second to catch the result but now the 3 minutes is really annoying. And since then I have not changed anything in the database or the code.