Hi MongoDB teachers !
I’m kind thoughtful concerning the subject of differing index, which is explained in Chapter 5 “Replica Sets with Differing Indexes Part 3”.
At 3m05 : https://youtu.be/5151d9wyAl0?t=182 after having created the differing index, the teacher runs the same query from the replica set. However, the query optimizer doesn’t select the secondary “passive” node to do an IXSCAN as the winning plan, but prefer a COLLSCAN on the primary.
When I read the documentation : “The MongoDB query optimizer processes queries and chooses the most efficient query plan for a query given the available indexes… This mechanism makes a pass/fail
decision based on the plan performance and either keeps or evicts the cache entry”.
The teacher next explains how the IXSCAN can be performed (by reading from secondary), but however I’m wondering why the query optimizer, from replica set, doesn’t prefer an IXSCAN from secondary over a COLLSCAN from the primary ? Would that means that query optimizer always prefer reading from primary to avoid potential outdated results ?
Thanks a lot !
Joris