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 Tim Graham)

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 wim@…, 11 years ago

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 by Anssi Kääriäinen, 11 years ago

Triage Stage: UnreviewedAccepted

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 Daniel Boeve, 11 years ago

Owner: changed from nobody to Daniel Boeve
Status: newassigned

comment:4 by Tim Graham, 11 years ago

Easy pickings: unset

comment:5 by anonymous, 11 years ago

Easy pickings: set
Owner: Daniel Boeve removed
Status: assignednew

comment:6 by Tim Graham, 11 years ago

Easy pickings: unset

comment:7 by Akshesh Doshi, 8 years ago

Cc: aksheshdoshi@… added

comment:8 by Asif Saifuddin Auvi, 8 years ago

Version: 1.5master

comment:9 by Tim Graham, 8 years ago

Description: modified (diff)
Keywords: db-indexes added
Note: See TracTickets for help on using tickets.
Back to Top