0
  1. Do indexes always persist on RAM?
  2. Hence, does scanning indexes require first retrieving the index from disk?

EDITED:

My questions is more about whether or not MongoDB will keep the index on RAM always, assuming that there is enough space. Because actual data is pushed off of RAM if they are not recent to make room for more recently accessed data. Is this the case with indexes as well? WIll indexes be pushed off of RAM based upon recency? Or does MongoDB treat indexes with priority and always keep it in RAM if there is enough room?

  • You should really try to have a look into documentation before you ask question here. See https://www.mongodb.com/docs/manual/tutorial/ensure-indexes-fit-ram/ and this one: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Wernfried Domscheit Jan 27 '23 at 19:55
  • thx, I did read that page. But my questions is more about whether or not MongoDB will keep the index on RAM always, assuming that there is enough space. Because actual data is push off of RAM if they are not recent to make room for more recently access data. Is this the case with indexes? WIll indexes be pushed off of RAM based upon recency? Or does MongoDB treat indexes with priority and alway keep it in RAM if there is enough room? – Bear Bile Farming is Torture Jan 27 '23 at 20:08

1 Answers1

1

That is not guaranteed.

MongoDB does store indexes in the same cache as documents, which does evict LRU.

It does not load the entire structure into memory, it load pages as they are needed, so the amount of the index in memory will depend on how it is accessed.

Indexes do get a bit of priority, but that is not absolute, so index pages can be evicted.

An insert into a collection will likely need to update all of the indexes, so it would be a reasonable assumption that any collection that is not totally idle will have at least the root page of each index in the cache.

Joe
  • 25,000
  • 3
  • 22
  • 44