#20888: Index ordering in index_together and unique_together
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner:
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: index, order, db- | Triage Stage: Accepted
indexes |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):
* keywords: index, order => index, order, db-indexes
Old description:
> 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?
New description:
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?
--
--
Ticket URL: <https://code.djangoproject.com/ticket/20888#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.019c478da6cb04fa14770b508f08d8e9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.