Changes between Initial Version and Version 3 of Ticket #28933


Ignore:
Timestamp:
Feb 13, 2018, 1:22:58 PM (6 years ago)
Author:
Tim Graham
Comment:

I left some comments for improvement.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28933

    • Property Has patch set
    • Property Triage Stage UnreviewedAccepted
    • Property Patch needs improvement set
    • Property Summary Implement a range-based filter for Django Admin date_hierarchyOptimize the queries for ModelAdmin.date_hierarchy
    • Property Type New featureCleanup/optimization
  • Ticket #28933 – Description

    initial v3  
    1 The predicate generated by date_hierarchy makes it very difficult for databases to optimize the query.
     1The predicate generated by `ModelAdmin.date_hierarchy` makes it very difficult for databases to optimize the query.
    22
    33The following date hierarchy:
    44
    5 {{{
    6 /admin/app/model?created__year=2017&created__month=12&created__day=16
    7 }}}
     5`/admin/app/model?created__year=2017&created__month=12&created__day=16`
    86 
    9 Will generate the following where clause (PostgreSql):
     7generates the following WHERE clause (PostgreSQL):
    108
    11 {{{
    12 WHERE created between '2017-01-01' and '2017-31-12' and EXTRACT('month', created) = 12 and EXTRACT('day', created) = 16
    13 }}}
    14 
     9`WHERE created between '2017-01-01' and '2017-31-12' and EXTRACT('month', created) = 12 and EXTRACT('day', created) = 16`
    1510
    1611The query above will not be able to utilize range based indexes on the date hierarchy column - on big tables this has a significant performance impact.
    1712
    18 The current implementation of date hierarchy is relying on the "default" filtering mechinizem used by Django Admin. **I propose implementing custom filtering for Django Admin that will better utilize it's hierarchical nature and make it more database "friendly".**
     13The current implementation of date hierarchy is relying on the "default" filtering mechanism used by the admin. I propose implementing custom filtering for  that will better utilize it's hierarchical nature and make it more database friendly.
    1914
    20 Instead of the query above the date hierarchy would generate the following predicates for different levels of the heirarchy:
    21 
     15Instead of the query above the date hierarchy would generate the following predicates for different levels of the hierarchy:
    2216
    2317{{{
     
    2620}}}
    2721
    28 
    2922{{{
    3023/admin/app/model?created__year=2017&created__month=12
    3124WHERE created >= '2017-12-01' and created < '2018-01-01'
    3225}}}
    33 
    3426
    3527{{{
     
    3830}}}
    3931
    40 
    41 I already [wrote about this issue](https://codeburst.io/django-admin-range-based-date-hierarchy-37955b12ea4e) and [published a package](https://github.com/hakib/django-admin-lightweight-date-hierarchy/blob/master/django_admin_lightweight_date_hierarchy/admin.py) that implement the above as a custom SimpleListFilter.
     32I already [https://codeburst.io/django-admin-range-based-date-hierarchy-37955b12ea4e wrote about this issue] and [https://github.com/hakib/django-admin-lightweight-date-hierarchy/blob/master/django_admin_lightweight_date_hierarchy/admin.py published a package] that implements the above as a custom `SimpleListFilter`.
    4233
    4334I already have a PR ready - I'm following proper protocol here so please let me know if this is acceptable.
    44 
    45 
Back to Top