Changes between Initial Version and Version 3 of Ticket #28933
- Timestamp:
- Feb 13, 2018, 1:22:58 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #28933
- Property Has patch set
- Property Triage Stage Unreviewed → Accepted
- Property Patch needs improvement set
- Property Summary Implement a range-based filter for Django Admin date_hierarchy → Optimize the queries for ModelAdmin.date_hierarchy
- Property Type New feature → Cleanup/optimization
-
Ticket #28933 – Description
initial v3 1 The predicate generated by date_hierarchymakes it very difficult for databases to optimize the query.1 The predicate generated by `ModelAdmin.date_hierarchy` makes it very difficult for databases to optimize the query. 2 2 3 3 The following date hierarchy: 4 4 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` 8 6 9 Will generate the following where clause (PostgreSql):7 generates the following WHERE clause (PostgreSQL): 10 8 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` 15 10 16 11 The 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. 17 12 18 The current implementation of date hierarchy is relying on the "default" filtering mech inizem 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".**13 The 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. 19 14 20 Instead of the query above the date hierarchy would generate the following predicates for different levels of the heirarchy: 21 15 Instead of the query above the date hierarchy would generate the following predicates for different levels of the hierarchy: 22 16 23 17 {{{ … … 26 20 }}} 27 21 28 29 22 {{{ 30 23 /admin/app/model?created__year=2017&created__month=12 31 24 WHERE created >= '2017-12-01' and created < '2018-01-01' 32 25 }}} 33 34 26 35 27 {{{ … … 38 30 }}} 39 31 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. 32 I 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`. 42 33 43 34 I already have a PR ready - I'm following proper protocol here so please let me know if this is acceptable. 44 45