Changes between Version 5 and Version 6 of Ticket #25470


Ignore:
Timestamp:
Sep 26, 2015, 9:33:45 AM (9 years ago)
Author:
Qian Xu
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #25470 – Description

    v5 v6  
    1 I posted a question at http://stackoverflow.com/questions/32795047/have-a-perforamance-issue-of-query-date-object-using-django-queryset
    2 
    31I'm using django 1.8.4 writing a webapp. The backend uses MySQL 5.6 (MyISAM). Recently the number of table records reaches 1 million, it will take 1-1.5 seconds to query all distinct record dates. But using MySQL client, it takes less than 0.001 second.
    42
     
    1917}}}
    2018
    21 I noticed that the second query did a type cast. The cast is not a necessary step. It slows down when the amount of records is huge. I pretty sure this is the root cause of the slow.
    22 
    23 The table is created by django. The field is exactly `DATE` field. I'd like to know, why django cast DATE to DATETIME. Is it a bug?
     19As you can see, the query did possibly an unnecessary type cast. The performance impact is scaled to the amount of records. The table field is exactly `DATE` type. I don't know, if there is some reason for the type casting.
    2420
    2521Currently, I use a workaround:
    2622{{{
    27 db_dates = [dt['date'] for dt in Model1.objects.order_by('date').values('date').distinct()]
     23db_dates = Model1.objects.values_list('date', flat=True).distinct()
    2824}}}
     25
     26I posted a question at [http://stackoverflow.com/questions/32795047/have-a-perforamance-issue-of-query-date-object-using-django-queryset StackOverflow].
Back to Top