title: django query aggregate function is slow?
body: <p>I am working with Django to see how to handle large databases. I use a database with fields name, age, date of birth(dob) and height. The database has about 500000 entries. I have to find the average height of persons of (1) same age and (2) born in same year. The aggregate function in querying table takes about 10s. Is it usual or am I missing something?</p>
  
  <p>For age:</p>
  
  <pre><code>age = [i[0] for i in Data.objects.values_list('age').distinct()]
  ht = []
  for each in age:
      aggr = Data.objects.filter(age=each).aggregate(ag_ht=Avg('height')
      ht.append(aggr)
  </code></pre>
  
  <p>From dob, </p>
  
  <pre><code>age = [i[0].year for i in Data.objects.values_list('dob').distinct()]
  for each in age:
      aggr = Data.objects.filter(dob__contains=each).aggregate(ag_ht=Avg(‌​'height')
      ht.append(aggr)
  </code></pre>
  
  <p>The year has to be extracted from dob. It is SQLite and I cannot use __year (join).</p>