Changes between Initial Version and Version 1 of Ticket #24431


Ignore:
Timestamp:
Feb 28, 2015, 1:04:41 PM (9 years ago)
Author:
briankrznarich
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24431 – Description

    initial v1  
    1212
    1313Another Example with some toy models:
     14{{{#!python
    1415class Address(models.Model):
    1516    city = models.CharField(max_length=40)
     
    2021    data = models.CharField(max_length=40)
    2122    author = models.ForeignKey(Author)
    22 
     23}}}
    2324For each author, select a count of their total blog entries, as well as a custom boolean value based on their address:
     25{{{#!python
    2426Author.objects.all().annotate(blogpost_count=Count('blogpost')).select_related('address').extra(select={'in_maryland':"address.state='MD'"}).count()
    25 
     27}}}
    2628This is fine until you append the count()
    2729
     
    3032A potential fix is in django/db/models/sql/query.py line 396 in get_aggregation().
    3133Change
     34{{{#!python
    3235inner_query.select_related = False
     36}}}
    3337To
     38{{{#!python
    3439if not self._extra: #Skip optimization, extra() fields might need these joins
    3540    inner_query.select_related = False
    36 
     41}}}
    3742The cause appears to be a performance optimization (don't do joins if the results don't appear the affect the aggregate).
    3843
Back to Top