Opened 11 years ago
Last modified 8 years ago
#20888 closed New feature
Index ordering in index_together and unique_together — at Version 9
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | index, order, db-indexes 1.11 |
Cc: | aksheshdoshi@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hi,
Currently the index_together tuples do not support index ordering using + / -.
If I have the following table:
class Messages: user_id, rating, last_update, index_together=[ ['user_id', 'rating', 'last_update',] # sorted ASC by default ]
So for MySQL, the following query cannot make use of the index:
Messages.objects.filter(user_id=xxx).order_by('+rating','-last_update')
Pardon me if it actually can make use of the index.
I know there are workarounds, such as negating values to make a DESC ordering become ASC ordering.
But it is just nice to have such a feature.
Btw, what is the reason for not having this feature?
Change History (9)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
To me this seems acceptable. Of course, supporting this only on MySQL isn't good, I believe most backends support index ordering.
comment:3 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 11 years ago
Easy pickings: | unset |
---|
comment:5 by , 11 years ago
Easy pickings: | set |
---|---|
Owner: | removed |
Status: | assigned → new |
comment:6 by , 11 years ago
Easy pickings: | unset |
---|
comment:7 by , 9 years ago
Cc: | added |
---|
comment:8 by , 9 years ago
Version: | 1.5 → master |
---|
comment:9 by , 9 years ago
Description: | modified (diff) |
---|---|
Keywords: | db-indexes added |
Hi anonymous, thanks for taking the time to fill in a ticket. Just to answer your question: most features are not implemented because people did not have time to write the code for it. :) So if you are willing to write a pull request and contribute such a feature could land in Django.
Unfortunately I do not understand MySQl enough to mark this ticket as accepted.