Mongo used to have 2 index build type, one is foreground which is fast and block read-write on the whole db, and the other is background which is slow and non-blocking. Since 4.2, it just has one build type which has medium speed and it does block the collection being indexed. Am I right here?
The doc has this part https://www.mongodb.com/docs/manual/core/index-creation/#index-build-impact-on-database-performance
“Building indexes during time periods where the target collection is under heavy write load can result in reduced write performance and longer index builds.”
What does it mean by “reduced write performance”? Isn’t it block the read-write entirely? Does it reduce the write performance for the whole db?
I used to run createIndexes in the middle of the day on a 4.4 mongo with background option. At that time, I did not know that background build had been removed. But after I know that the option has been removed, I still run it in the middle of the day, because I think that the new index build == ( foreground + background) == ( medium speed + non blocking).
I test it on mongo 4.4, and the result is that:
While an index is creating on a collection, that collection can still be read and written. I index on a 49M docs collection, and the indexing time takes 20 minutes so I have plenty of time to observe the read/write activities.
Also this doc states that “Building indexes during time periods where the target collection is under heavy write load can result in reduced write performance and longer index builds.”. So I guess that it will not block the collection during the whole indexing process.
As per the documentation you linked, index builds have been optimised since MongoDB 4.2 so there no longer foreground versus background build types:
Starting in MongoDB 4.2, index builds use an optimized build process that holds an exclusive lock on the collection at the beginning and end of the index build. The rest of the build process yields to interleaving read and write operations.
… and this is as good or better than previous background index build performance:
The optimized index build performance is at least on par with background index builds. For workloads with few or no updates received during the build process, optimized index builds can be as fast as a foreground index build on that same data.
Collection read/write operations can be interleaved while indexes are being built, but additional I/O from concurrent index builds may impact performance.
This should be similar or better speed without blocking read/write operations during index builds.