Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Fixed #28933 -- Improved the efficiency of ModelAdmin.date_hierarchy queries. #9469
The predicate generated by date_hierarchy makes it very difficult for databases to optimize the query.
The following date hierarchy:
Will generate the following where clause (PostgreSql):
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.
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".
Instead of the query above the date hierarchy would generate the following predicates for different levels of the heirarchy:
Please let me know if this is acceptable.
charettes left a comment •
Thanks for taking the time to turn hakib/django-admin-lightweight-date-hierarchy into this PR, this is looking great!
One small concern would be that
carltongibson left a comment
This looks really good. Thanks for the effort @hakib!
There is only one existing test which explicitly covers `date_heirarchy:
This is really targeting the DST handling. As such, the new tests are a real bonus.
This is a purely internal change so no new docs needed. (I think) — Is it worth something for the release notes though?
@carltongibson I think so to. I'm not sure where I should do that though (should this PR be assigned to a version before writing the release notes?).
Also, it's been a couple of month (and two Django releases) since this PR was submited - should I reabse on latest master?