Why IXSCAN not enough?

Hi @Anteaus first of all, welcome to the community!

Actually a FETCH stage is not all bad. It just simply means that the server need to either: 1) Fetch the actual result documents to give to you, or 2) Fetch the document to further check the query parameters match to actual documents.

Not all queries need to be a covered query. Anecdotally, if all your queries are covered queries, then you need many, many indexes to cover all the queries you have. You definitely can have too many indexes in a collection (you can have at most 64 indexes in a collection) and with each additional index, writing to the collection involves updating all those indexes as well. This is on top fo what @Rafael_Green mentioned as well: a multikey index (index involving arrays) cannot be used for a covered query, due to how a multikey index works.

Thus, if your queries are adhering to the principles outlined in the Query Optimization page and are fast enough for your needs, it doesn’t really matter that the query has FETCH stage.

However if you’re very concerned about the query’s performance, please post

  • Your MongoDB version
  • The output of db.collection.explain('executionStats').find(....) of the query in question

Best regards
Kevin

3 Likes