How often do you build an index?

75 views
Skip to first unread message

Matt

unread,
Mar 12, 2018, 11:52:36 AM3/12/18
to mongodb-user
Looking for some insight on indexes over time.

I have a collection that will contain millions of documents and several indexes.  The collection will grow over time via inserts (as opposed to drop and rebuild), and so I was just wondering...

  • Do you just create the index once, and the efficiency will maintain itself over the life of the collection?
  • Or do you have to rebuild the index every so often?
  • Also, coming from DB2 background, there is the concept of a table 'reorg' where ordering and pages get rebuilt to maintain structure and efficiency of the tables data.  Is there an equivalent in Mongo?


Ultimately, with this large collection I'll have, I just don't want to see performance slow down over time due to something I'm missing.


Thanks in advance for any help!

Kevin Adistambha

unread,
Mar 13, 2018, 8:11:38 PM3/13/18
to mongodb-user

Hi Matt

Do you just create the index once, and the efficiency will maintain itself over the life of the collection? Or do you have to rebuild the index every so often?

You just need to create the index once. It will be maintained as part of the insert/update process.

Also, coming from DB2 background, there is the concept of a table ‘reorg’ where ordering and pages get rebuilt to maintain structure and efficiency of the tables data. Is there an equivalent in Mongo?

There is no direct equivalent of the reorg command in MongoDB. The closest equivalent is maybe compact, but running compact regularly is not necessary to maintain performance.

Ultimately, with this large collection I’ll have, I just don’t want to see performance slow down over time due to something I’m missing.

If your queries are well-indexed and you have sufficient hardware resources so that MongoDB does not need to fetch from disk very often, performance should not be an issue. Even if the collection keeps growing, as long as the “working set” can comfortably fit in RAM, MongoDB should be able to maintain its performance.

Having said that, please note that unlike tabular databases e.g. DB2 which was designed to run within a single big machine, MongoDB is a distributed database. Hence, in a production environment, it’s strongly recommended to run a replica set to provide high availability and redundancy.

Best regards
Kevin

Matt

unread,
Mar 15, 2018, 1:09:52 PM3/15/18
to mongodb-user
Thanks so much for these responses!  Very helpful and well appreciated!
Reply all
Reply to author
Forward
0 new messages