Opened 2 years ago

Last modified 23 months ago

#20888 new New feature

Index ordering in index_together and unique_together

Reported by: anonymous Owned by:
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords: index, order
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



Currently the index_together tuples do not support index ordering using + / -.

If I have the following table:
class Messages:



['user_id', 'rating', 'last_update',] # sorted ASC by default


So for MySQL, the following query cannot make use of the index:


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 (6)

comment:1 Changed 2 years ago by wim@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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.

comment:2 Changed 2 years ago by akaariai

  • Triage Stage changed from Unreviewed to 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 Changed 23 months ago by animan1

  • Owner changed from nobody to animan1
  • Status changed from new to assigned

comment:4 Changed 23 months ago by timo

  • Easy pickings unset

comment:5 Changed 23 months ago by anonymous

  • Easy pickings set
  • Owner animan1 deleted
  • Status changed from assigned to new

comment:6 Changed 23 months ago by timo

  • Easy pickings unset
Note: See TracTickets for help on using tickets.
Back to Top