Answer the question
In order to leave comments, you need to log in
Why doesn't sorting on multiple fields use indexes?
Good afternoon. The problem arose very strange and, in my opinion, illogical.
I have some table tbl with fields id, count and something else.
id - primary key, index created on count (btree)
So, I need to sort by count desc, then by id asc. Well, I make this request:
select * from tbl order by count desc, id limit 10;
select * from tbl order by count desc limit 10;
select * from tbl order by id limit 10;
select * from (
select * from tbl order by count desc limit 10;
) as a order by id;
Entry.objects.order_by('-count', 'pk')[:10]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question