Indexes prefix vs equality,sort,range

I have on question that to get best performance we should use index prefix( It means to query in linear order ) .
but if we use ( equality , sort , range ) i think it breaks the rule for query performance like to use index prefix. then which of this both is better to use to increase performance of query

Hi @Vasu_Rangpariya- welcome to the forums!

Have you reviewed Chapter 4: CRUD Optimization Lesson 1 - Chapter 4: CRUD Optimization as this covers the same topics and might be useful if you have not already seen this lesson?

In terms of using compound or index single-field indexes, it really can depend on what you are querying as to what the performance of the query will be. Ideally, you want a selective query (in terms of criteria) and one where it can be covered completely by the index (so it does not need to read any documents only index entries to service the query).

In the course, we mainly focus on the advantage of using an index to help perform a sort so that you can avoid a costly in-memory sort if the index can’t assist you with the sorting.

Does this help answer your question?

Kindest regards,
Eoin

1 Like