Hey guys, I have a performance issues while trying to find and sort a big amount of data (more than 3m of records, but limit is 10k).
So I have the following request:
I have a single field index of {“timestamp”: -1} and executionTimeMillis is around 11k
I tried to create compound index of {“field1”: 1, “field2”: 1, “field3”: 1}, but as I can see this index is not used cos of sort, so I tried to create another one as {“field1”: 1, “field2”: 1, “field3”: 1, “timestamp”: -1}, but it gives me executionTimeMillis around 8k and it’s a bit better (SORT_MERGE is used), but still it’s 3k without sort.
Any tricks on how to use sortable field in compound index to improve performance here?
Thanks for your answer @Pavel_Duchovny, it answers some of my questions, but I already tried some configurations, and I got the following results:
Documents Returned:9420
Index Keys Examined:1610000
Documents Examined:9420
Actual Query Execution Time (ms):10664
Sorted in Memory:no
Query used the following index:
field2_1_timestamp_-1_field1_1_field3_1
But I managed to improve performance by the following:
Documents Returned:9420
Index Keys Examined:158261
Documents Examined:9420
Actual Query Execution Time (ms):603
Sorted in Memory:no
Query used the following index:
field1_1_field2_1_timestamp_-1_field3_1
Any explanations on why it could be faster? For some reasons I got better results having field1 as the first in my index.